Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,7 @@ OP_SAME_OPERANDS_AND_RESULT(Selu_)
OP_SAME_OPERANDS_AND_RESULT(ShadowFeed)
OP_SAME_OPERANDS_AND_RESULT(ShareData_)
OP_SAME_OPERANDS_AND_RESULT(Sign)
OP_SAME_OPERANDS_AND_RESULT(Sign_)
OP_SAME_OPERANDS_AND_RESULT(Sin)
OP_SAME_OPERANDS_AND_RESULT(Sin_)
OP_SAME_OPERANDS_AND_RESULT(Sinh)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,7 @@ OP_DECLARE_INFER_SYMBOLIC_SHAPE(Select)
OP_DECLARE_INFER_SYMBOLIC_SHAPE(ShadowFeed)
OP_DECLARE_INFER_SYMBOLIC_SHAPE(ShareData_)
OP_DECLARE_INFER_SYMBOLIC_SHAPE(Sign)
OP_DECLARE_INFER_SYMBOLIC_SHAPE(Sign_)
OP_DECLARE_INFER_SYMBOLIC_SHAPE(Silu)
OP_DECLARE_INFER_SYMBOLIC_SHAPE(Silu_)
OP_DECLARE_INFER_SYMBOLIC_SHAPE(Sin)
Expand Down
1 change: 1 addition & 0 deletions paddle/phi/ops/yaml/ops.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5136,6 +5136,7 @@
spmd_rule : ElementwiseUnaryInferSpmd
kernel :
func : sign
inplace: (x -> out)
backward : sign_grad
interfaces : paddle::dialect::InferSymbolicShapeInterface
traits: pir::UnaryElementWiseTrait
Expand Down
18 changes: 14 additions & 4 deletions paddle/phi/ops/yaml/python_api_info.yaml
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
- op : abs
name : [paddle.abs, paddle.Tensor.abs]
name : [paddle.abs, paddle.Tensor.abs, paddle.absolute, paddle.Tensor.absolute]

This comment was marked as outdated.

args_alias :
use_default_mapping : True

- op : abs_
name : [paddle.abs_, paddle.Tensor.abs_]
name : [paddle.abs_, paddle.Tensor.abs_, paddle.absolute_, paddle.Tensor.absolute_]
args_alias :
use_default_mapping : True

Expand Down Expand Up @@ -470,7 +470,7 @@
- op : inverse
name : [paddle.inverse, paddle.Tensor.inverse, paddle.linalg.inv]
args_alias:
use_default_mapping : True
x : [input, A]

- op : lgamma
name : [paddle.lgamma, paddle.Tensor.lgamma]
Expand Down Expand Up @@ -580,6 +580,11 @@
args_alias :
use_default_mapping : True

- op : imag
name : [paddle.imag, paddle.Tensor.imag]

This comment was marked as outdated.

args_alias :
use_default_mapping : True

- op : pixel_shuffle
name : [paddle.nn.functional.pixel_shuffle]
args_alias :
Expand All @@ -598,7 +603,7 @@
use_default_mapping : True

- op : remainder_
name : [paddle.remainder_, paddle.Tensor.remainder_, paddle.mod_, paddle.Tensor.mod_, paddle.floor_mod_, paddle.Tensor.floor_mod_]
name : [paddle.remainder_, paddle.Tensor.remainder_, paddle.mod_, paddle.Tensor.mod_, paddle.floor_mod_, paddle.Tensor.floor_mod_, paddle.fmod_, paddle.Tensor.fmod_]
args_alias :
use_default_mapping : True
pre_process :
Expand Down Expand Up @@ -647,6 +652,11 @@
args_alias :
use_default_mapping : True

- op : sign_
name : [paddle.sign_, paddle.Tensor.sign_]
args_alias :
use_default_mapping : True

- op : sin
name : [paddle.sin, paddle.Tensor.sin]
args_alias :
Expand Down
21 changes: 21 additions & 0 deletions python/paddle/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -343,6 +343,7 @@ def new_init(self, *args, **kwargs):
load,
save,
set_default_dtype,
set_default_tensor_type,
)
from .framework.random import (
Generator,
Expand Down Expand Up @@ -435,6 +436,7 @@ def new_init(self, *args, **kwargs):
cdist,
cholesky,
cross,
det,
diagonal,
dist,
dot,
Expand All @@ -447,6 +449,7 @@ def new_init(self, *args, **kwargs):
mv,
norm,
permute,
pinv,

This comment was marked as outdated.

t,
t_,
transpose,
Expand Down Expand Up @@ -532,10 +535,12 @@ def new_init(self, *args, **kwargs):
moveaxis,
narrow,
put_along_axis,
put_along_axis_,
ravel,
repeat_interleave,
reshape,
reshape_,
resize_as_,
roll,
rot90,
row_stack,
Expand All @@ -546,6 +551,7 @@ def new_init(self, *args, **kwargs):
scatter_nd,
scatter_nd_add,
scatter_reduce,
scatter_reduce_,
select_scatter,
shard_index,
slice,
Expand Down Expand Up @@ -584,6 +590,8 @@ def new_init(self, *args, **kwargs):
acosh_,
add,
add_n,
addcdiv,
addcdiv_,
addmm,
addmm_,
addmv,
Expand Down Expand Up @@ -737,6 +745,7 @@ def new_init(self, *args, **kwargs):
scale,
sgn,
sign,
sign_,
signbit,
sin,
sin_,
Expand Down Expand Up @@ -1063,11 +1072,13 @@ def __dir__(self):
movedim = moveaxis
mod = remainder
floor_mod = remainder
fmod = remainder

This comment was marked as outdated.

fix = trunc
fix_ = trunc_
mvlgamma = multigammaln
mvlgamma_ = multigammaln_
negative_ = neg_
pinverse = pinv

__all__ = [
'block_diag',
Expand Down Expand Up @@ -1100,6 +1111,8 @@ def __dir__(self):
'complex128',
'pstring',
'raw',
'addcdiv',
'addcdiv_',
'addmm',
'addmm_',
'addmv',
Expand All @@ -1115,6 +1128,7 @@ def __dir__(self):
'add',
'subtract',
'subtract_',
'det',
'diag',
'diagflat',
'diag_embed',
Expand Down Expand Up @@ -1300,6 +1314,8 @@ def __dir__(self):
'inference_mode',
'mod',
'mod_',
'fmod',
'fmod_',
'abs',
'abs_',
'tril',
Expand All @@ -1312,6 +1328,7 @@ def __dir__(self):
'index_select',
'CPUPlace',
'matmul',
'pinverse',
'seed',
'acos',
'acos_',
Expand Down Expand Up @@ -1437,6 +1454,7 @@ def __dir__(self):
'enable_static',
'scatter_nd',
'set_default_dtype',
'set_default_tensor_type',
'disable_signal_handler',
'expand_as',
'stack',
Expand All @@ -1451,6 +1469,7 @@ def __dir__(self):
'logspace',
'reshape',
'reshape_',
'resize_as_',
'atleast_1d',
'atleast_2d',
'atleast_3d',
Expand Down Expand Up @@ -1512,7 +1531,9 @@ def __dir__(self):
'take_along_axis',
'take_along_dim',
'scatter_reduce',
'scatter_reduce_',
'put_along_axis',
'put_along_axis_',
'scatter_add',
'select_scatter',
'multigammaln',
Expand Down
54 changes: 54 additions & 0 deletions python/paddle/_paddle_docs.py
Original file line number Diff line number Diff line change
Expand Up @@ -3966,6 +3966,60 @@ def angle(
""",
)

add_doc_and_signature(
"imag",
r"""
Returns a new tensor containing imaginary values of input tensor.

Args:
x (Tensor): the input tensor, its data type could be complex64 or complex128.
name (str|None, optional): The default value is None. Normally there is no need for
user to set this property. For more information, please refer to :ref:`api_guide_Name` .

Keyword args:
out(Tensor, optional): The output tensor.

Returns:
Tensor: a tensor containing imaginary values of the input tensor.

Examples:
.. code-block:: pycon

>>> import paddle

>>> x = paddle.to_tensor(
... [
... [1 + 6j, 2 + 5j, 3 + 4j],
... [4 + 3j, 5 + 2j, 6 + 1j],
... ]
... )
>>> print(x)
Tensor(shape=[2, 3], dtype=complex64, place=Place(cpu), stop_gradient=True,
[[(1.00000000+6.00000000j), (2.00000000+5.00000000j), (3.00000000+4.00000000j)],
[(4.00000000+3.00000000j), (5.00000000+2.00000000j), (6.00000000+1.00000000j)]])

>>> imag_res = paddle.imag(x)
>>> print(imag_res)
Tensor(shape=[2, 3], dtype=float32, place=Place(cpu), stop_gradient=True,
[[6., 5., 4.],
[3., 2., 1.]])

>>> imag_t = x.imag()
>>> print(imag_t)
Tensor(shape=[2, 3], dtype=float32, place=Place(cpu), stop_gradient=True,
[[6., 5., 4.],
[3., 2., 1.]])
""",
"""
def imag(
x: Tensor,
name: str | None = None,
*,
out: Tensor | None = None,
) -> Tensor
""",
)

add_doc_and_signature(
"real",
r"""
Expand Down
2 changes: 1 addition & 1 deletion python/paddle/compat/nn/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -744,7 +744,7 @@ def forward(self, input: Tensor) -> Tensor:
return functional.softmax(input, self._dim)

def extra_repr(self) -> str:
return f"dim={self.dim}"
return f"dim={self._dim}"


class SmoothL1Loss(nn.Layer):
Expand Down
6 changes: 5 additions & 1 deletion python/paddle/framework/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,11 @@
# isort: on
from ..base.param_attr import ParamAttr # noqa: F401
from . import random # noqa: F401
from .framework import get_default_dtype, set_default_dtype # noqa: F401
from .framework import ( # noqa: F401
get_default_dtype,
set_default_dtype,
set_default_tensor_type,
)
from .io import load, save # noqa: F401
from .io_utils import ( # noqa: F401
_clone_var_in_block_,
Expand Down
47 changes: 47 additions & 0 deletions python/paddle/framework/framework.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,53 @@ def set_default_dtype(d: DTypeLike) -> None:
LayerHelperBase.set_default_dtype(d)


def set_default_tensor_type(t: DTypeLike | str, /) -> None:
"""
Set the default tensor type.

.. warning::
This API is deprecated. Please use ``paddle.set_default_dtype`` instead.

Args:
t (dtype or str): The default tensor type. It can be a dtype like
``paddle.float32`` or a string like ``"paddle.float32"`` or
``"paddle.FloatTensor"``. Only float dtypes are supported.

Returns:
None.

Examples:
.. code-block:: pycon

>>> import paddle
>>> paddle.set_default_tensor_type("paddle.FloatTensor")
>>> paddle.set_default_tensor_type(paddle.FloatTensor)
"""
if isinstance(t, type):
t = t.__name__

if isinstance(t, str):
t = t.replace('torch.', '').replace('paddle.', '').replace('cuda.', '')
dtype_map = {
"FloatTensor": "float32",
"DoubleTensor": "float64",
"HalfTensor": "float16",
"BFloat16Tensor": "bfloat16",
}
if t in dtype_map:
t = dtype_map[t]
else:
raise TypeError(
f"set_default_tensor_type only supports DtypeTensor, but received {t}"
)
else:
raise TypeError(
f"set_default_tensor_type only supports DtypeTensor or str, but received {t}"
)

set_default_dtype(t)


def get_default_dtype() -> _DTypeLiteral:
"""
Get the current default dtype. The default dtype is initially float32.
Expand Down
2 changes: 2 additions & 0 deletions python/paddle/nn/functional/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,7 @@
conv_transpose1d = conv1d_transpose
conv_transpose2d = conv2d_transpose
conv_transpose3d = conv3d_transpose
huber_loss = smooth_l1_loss

This comment was marked as outdated.

multilabel_margin_loss = multi_label_margin_loss
multilabel_soft_margin_loss = multi_label_soft_margin_loss
__all__ = [
Expand Down Expand Up @@ -324,4 +325,5 @@
"flash_attention_v3_varlen",
'flash_attn_varlen_qkvpacked',
'group_norm',
'huber_loss',
]
11 changes: 10 additions & 1 deletion python/paddle/nn/functional/loss.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,10 @@
from paddle import _C_ops, base, in_dynamic_mode
from paddle.static.nn.control_flow import Assert
from paddle.utils import deprecated
from paddle.utils.decorator_utils import legacy_reduction_decorator
from paddle.utils.decorator_utils import (
ParamAliasDecorator,
legacy_reduction_decorator,
)

from ...base.data_feeder import check_type, check_variable_and_dtype
from ...base.framework import (
Expand Down Expand Up @@ -2063,6 +2066,12 @@ def mse_loss(
)


@ParamAliasDecorator(

This comment was marked as outdated.

alias_mapping={
'labels': ['targets'],
'label_lengths': ['target_lengths'],
}
)
def ctc_loss(
log_probs: Tensor,
labels: Tensor,
Expand Down
Loading
Loading