Skip to content
Merged
Show file tree
Hide file tree
Changes from 17 commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
d32d979
[API Compatibility] nn.Module.to_empty/linalg.det/nn.functional.gumbe…
zhwesky2010 Jul 2, 2026
13328d3
[API Compatibility] nn.Module.to_empty/linalg.det/nn.functional.gumbe…
zhwesky2010 Jul 3, 2026
5aafa15
[API Compatibility] nn.Module.to_empty/linalg.det/nn.functional.gumbe…
zhwesky2010 Jul 3, 2026
69a736f
Merge branch 'develop' of https://github.com/PaddlePaddle/Paddle into…
zhwesky2010 Jul 3, 2026
0e0271e
fix CI
zhwesky2010 Jul 5, 2026
99525a9
Revert third_party/sleef submodule pointer to original commit
zhwesky2010 Jul 5, 2026
d7fac5c
[API Compatibility] add QrRetType named tuple for qr return type
zhwesky2010 Jul 6, 2026
529f31b
[API Compatibility] qr: mode=r returns single Tensor; add QrRetType n…
zhwesky2010 Jul 6, 2026
64633da
[API Compatibility] update batch_norm/instance_norm tests to use comp…
zhwesky2010 Jul 6, 2026
9b0e602
update batch_norm/instance_norm tests to use compat functions with re…
zhwesky2010 Jul 6, 2026
edc5ca4
[API Compatibility] fix eigh/cholesky static graph shape check; updat…
zhwesky2010 Jul 6, 2026
e3eaea1
[API Compatibility] add clamp_min API
zhwesky2010 Jul 6, 2026
0f878b1
[API Compatibility] add clamp_min API and enhance test coverage for 6…
zhwesky2010 Jul 6, 2026
ab8651f
[API Compatibility] fix expand_copy signature, instance_norm alias, e…
zhwesky2010 Jul 6, 2026
251a608
[API Compatibility] add instance_norm momentum conversion test
zhwesky2010 Jul 6, 2026
32341de
[API Compatibility] fix enable_static misuse, to_empty _set_impl, nor…
zhwesky2010 Jul 6, 2026
69fc6e1
[API Compatibility] PADDLE_ENFORCE→PADDLE_ENFORCE_EQ, rms_norm skipfi…
zhwesky2010 Jul 6, 2026
d1cc20e
[API Compatibility] Tensor.H/Tensor.mH support 0-D input; rms_norm sk…
zhwesky2010 Jul 7, 2026
87951f0
[API Compatibility] fix static test for Tensor.H/mH to actually test …
zhwesky2010 Jul 7, 2026
699f2d1
[API Compatibility] add qr mode='r' out parameter test coverage
zhwesky2010 Jul 7, 2026
97b81d8
[API Compatibility] expand to_empty test with nested layers and buffers
zhwesky2010 Jul 7, 2026
fd11da6
[API Compatibility] add Windows skip for rms_norm test methods
zhwesky2010 Jul 7, 2026
91796ff
fix some bug and add type hints
zhwesky2010 Jul 7, 2026
d5b02da
fix ci
zhwesky2010 Jul 7, 2026
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
85 changes: 85 additions & 0 deletions paddle/fluid/pybind/arg_pre_process.cc
Original file line number Diff line number Diff line change
Expand Up @@ -563,6 +563,91 @@ void PixelShufflePreProcess(std::string* data_format) {
}
}

// Eigh input validation for dygraph
void EighPreProcess(Tensor* x, std::string* UPLO) {
auto x_shape = x->dims();
int64_t rank = x_shape.size();
PADDLE_ENFORCE_GE(rank,
2,
phi::errors::InvalidArgument(
"Input(input) only support >=2 tensor, but received "
"length of Input(input) is %ld.",
rank));
PADDLE_ENFORCE_EQ(x_shape[rank - 1],
x_shape[rank - 2],
phi::errors::InvalidArgument(
"The input matrix must be batches of square matrices. "
"But received x's dimension: [%s]",
x_shape));
PADDLE_ENFORCE_EQ(
*UPLO == "L" || *UPLO == "U",
true,
phi::errors::InvalidArgument(
"UPLO must be L or U. But received UPLO is: %s", UPLO->c_str()));
}

// Eigh input validation for static graph
void EighPreProcess(Value* x, std::string* UPLO) {
auto x_shape = pir::GetShapeFromValue(*x);
int64_t rank = x_shape.size();
PADDLE_ENFORCE_GE(rank,
2,
phi::errors::InvalidArgument(
"Input(input) only support >=2 tensor, but received "
"length of Input(input) is %ld.",
rank));
if (x_shape[rank - 1] > 0 && x_shape[rank - 2] > 0) {
PADDLE_ENFORCE_EQ(
x_shape[rank - 1],
x_shape[rank - 2],
phi::errors::InvalidArgument(
"The input matrix must be batches of square matrices. "
"But received x's dimension."));
}
PADDLE_ENFORCE_EQ(
*UPLO == "L" || *UPLO == "U",
true,
phi::errors::InvalidArgument(
"UPLO must be L or U. But received UPLO is: %s", UPLO->c_str()));
}

// Cholesky input validation for dygraph
void CholeskyPreProcess(Tensor* x, bool* upper) {
auto x_shape = x->dims();
int64_t rank = x_shape.size();
PADDLE_ENFORCE_GE(
rank,
2,
phi::errors::InvalidArgument("Shape must have at least 2 dimensions. "
"But received x's dimension: %ld.",
rank));
PADDLE_ENFORCE_EQ(
x_shape[rank - 1],
x_shape[rank - 2],
phi::errors::InvalidArgument("The last two dimensions must be equal. "
"But received x's dimension: [%s]",
x_shape));
}

// Cholesky input validation for static graph
void CholeskyPreProcess(Value* x, bool* upper) {
auto x_shape = pir::GetShapeFromValue(*x);
int64_t rank = x_shape.size();
PADDLE_ENFORCE_GE(
rank,
2,
phi::errors::InvalidArgument("Shape must have at least 2 dimensions. "
"But received x's dimension: %ld.",
rank));
if (x_shape[rank - 1] > 0 && x_shape[rank - 2] > 0) {
PADDLE_ENFORCE_EQ(
x_shape[rank - 1],
x_shape[rank - 2],
phi::errors::InvalidArgument("The last two dimensions must be equal. "
"But received x's dimension."));
}
}

// Renorm preprocessing: handle negative axis
void NegativeAxisPreProcess(Tensor* x, int* axis) {
int rank = x->dims().size();
Expand Down
9 changes: 9 additions & 0 deletions paddle/fluid/pybind/arg_pre_process.h
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,15 @@ void NegativeAxisPreProcess(Value* x, int* axis);

void PixelShufflePreProcess(std::string* data_format);

// Eigh input validation: check shape >= 2D, last two dims equal, UPLO is 'L' or
// 'U'
void EighPreProcess(Tensor* x, std::string* UPLO);
void EighPreProcess(Value* x, std::string* UPLO);

// Cholesky input validation: check shape >= 2D, last two dims equal
void CholeskyPreProcess(Tensor* x, bool* upper);
void CholeskyPreProcess(Value* x, bool* upper);

// Inplace API broadcast validation for dygraph
void InplaceShapePreProcess(Tensor* x, Tensor* y);

Expand Down
19 changes: 19 additions & 0 deletions paddle/phi/ops/yaml/python_api_info.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -287,6 +287,13 @@
args_alias :
use_default_mapping : True

- op : cholesky

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 优先级:P1

这里把 cholesky 改成由生成绑定导出,同时删除了 python/paddle/tensor/linalg.py 里原来的 Python wrapper。被删 wrapper 的 legacy static 分支会用 LayerHelper('cholesky') 追加旧 IR op;而当前生成的 eager/PIR 入口只解析 Tensor/PIR Value,PIR static 对 out= 也只是 warning 后忽略,不能替代旧 VariableLayerHelper 构图路径。当前文档和兼容测试已经声明 input=/out= 语义,请恢复 Python wrapper,在 wrapper 中统一处理 alias/out,动态/PIR 调 _C_ops.cholesky,legacy static 保留原 append_op(type='cholesky', ...) 路径,并补 OldIrGuard 下的回归用例。

建议形态:

@ParamAliasDecorator({"x": ["input"]})
def cholesky(x, upper=False, name=None, *, out=None):
    if in_dynamic_or_pir_mode():
        result = _C_ops.cholesky(x, upper)
    else:
        check_variable_and_dtype(x, 'dtype', ['float32', 'float64'], 'cholesky')
        check_type(upper, 'upper', bool, 'cholesky')
        helper = LayerHelper('cholesky', **locals())
        result = helper.create_variable_for_type_inference(dtype=x.dtype)
        helper.append_op(
            type='cholesky',
            inputs={'X': [x]},
            outputs={'Out': result},
            attrs={'upper': upper},
        )
    if out is not None:
        paddle.assign(result, out)
        return out
    return result

name : [paddle.cholesky, paddle.linalg.cholesky, paddle.Tensor.cholesky]
args_alias :
use_default_mapping : True
pre_process :
func : CholeskyPreProcess(x, upper)

- op : conj
name: [paddle.conj, paddle.Tensor.conj]
args_alias :
Expand Down Expand Up @@ -325,12 +332,24 @@
axis1 : [dim1]
axis2 : [dim2]

- op : det
name : [paddle.det, paddle.linalg.det, paddle.Tensor.det]
args_alias :
x : [input, A]

- op : dot
name : [paddle.dot, paddle.Tensor.dot]
args_alias :
x : [input]
y : [tensor]

- op : eigh

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 优先级:P1

这里把 paddle.linalg.eigh / Tensor.eigh 改由生成绑定提供,同时删除了 linalg.py 中原来的 Python wrapper。原 wrapper 在 legacy static 下会先做形状、UPLO 和 dtype 检查,再用 LayerHelper('eigh') 追加 eigh op;当前生成的 eager/PIR 入口只解析 Tensor/PIR Value,PIR static 对 out= 也只是 warning 后忽略,不能替代这段 legacy static fallback。请恢复 wrapper 或在生成路径中补齐等价的 legacy static 构图和 out 写回,否则 paddle.enable_static() 且未启用 PIR 的环境会丢掉原有 API 行为,文档声明的 out=(w, v) 也不会生效。

建议形态:

@ParamAliasDecorator({"x": ["input"]})
def eigh(x, UPLO='L', name=None, *, out=None):
    _check_eigh_input(x, UPLO)
    if in_dynamic_or_pir_mode():
        result = _C_ops.eigh(x, UPLO)
    else:
        check_variable_and_dtype(x, 'dtype', ['float32', 'float64', 'complex64', 'complex128'], 'eigh')
        helper = LayerHelper('eigh', **locals())
        out_w = helper.create_variable_for_type_inference(dtype=x.dtype)
        out_v = helper.create_variable_for_type_inference(dtype=x.dtype)
        helper.append_op(
            type='eigh',
            inputs={'X': x},
            outputs={'Eigenvalues': out_w, 'Eigenvectors': out_v},
            attrs={'UPLO': UPLO},
        )
        result = (out_w, out_v)
    if out is not None:
        paddle.assign(result[0], out[0])
        paddle.assign(result[1], out[1])
        return out
    return result

name : [paddle.linalg.eigh, paddle.Tensor.eigh]
args_alias :
use_default_mapping : True
pre_process :
func : EighPreProcess(x, UPLO)

- op : erf
name : [paddle.erf, paddle.Tensor.erf]
args_alias :
Expand Down
17 changes: 17 additions & 0 deletions python/paddle/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -444,12 +444,14 @@ def new_init(self, *args, **kwargs):
histogram,
histogram_bin_edges,
histogramdd,
logdet,
matmul,
matrix_transpose,
mv,
norm,
permute,
pinv,
qr,
t,
t_,
transpose,
Expand Down Expand Up @@ -515,6 +517,7 @@ def new_init(self, *args, **kwargs):
dstack,
expand,
expand_as,
expand_copy,
flatten,
flatten_,
flip,
Expand Down Expand Up @@ -622,7 +625,10 @@ def new_init(self, *args, **kwargs):
broadcast_shapes,
cartesian_prod,
ceil,
clamp_max,
clamp_min,
clip,
clip_,
combinations,
conj,
copysign,
Expand Down Expand Up @@ -1055,6 +1061,8 @@ def __dir__(self):
concatenate = concat
take_along_dim = take_along_axis
clamp = clip
clamp_ = clip_
true_divide_ = divide_
ger = outer
div = divide
div_ = divide_
Expand All @@ -1080,6 +1088,7 @@ def __dir__(self):
negative_ = neg_
pinverse = pinv


__all__ = [
'block_diag',
'gt',
Expand Down Expand Up @@ -1215,7 +1224,11 @@ def __dir__(self):
'less_',
'kron',
'clip',
'clip_',
'clamp',
'clamp_',
'clamp_max',
'clamp_min',
'Tensor',
'FloatTensor',
'DoubleTensor',
Expand Down Expand Up @@ -1329,6 +1342,7 @@ def __dir__(self):
'CPUPlace',
'matmul',
'pinverse',
'qr',
'seed',
'acos',
'acos_',
Expand Down Expand Up @@ -1377,6 +1391,7 @@ def __dir__(self):
'sub',
'sub_',
'true_divide',
'true_divide_',
'gammaln',
'gammaln_',
'ceil',
Expand Down Expand Up @@ -1457,6 +1472,7 @@ def __dir__(self):
'set_default_tensor_type',
'disable_signal_handler',
'expand_as',
'expand_copy',
'stack',
'hstack',
'vstack',
Expand Down Expand Up @@ -1488,6 +1504,7 @@ def __dir__(self):
'cosh',
'log',
'log_',
'logdet',
'log2',
'log2_',
'log10',
Expand Down
141 changes: 141 additions & 0 deletions python/paddle/_paddle_docs.py
Original file line number Diff line number Diff line change
Expand Up @@ -3399,6 +3399,43 @@ def diag(
...


@add_doc_and_signature
def det(
x: Tensor,
name: str | None = None,
*,
out: Tensor | None = None,
) -> Tensor:
r"""

Calculates determinant value of a square matrix or batches of square matrices.

Args:
x (Tensor): the input matrix of size `(n, n)` or the
batch of matrices of size `(*, n, n)` where `*` is one or more
batch dimensions. Alias: ``input``.
name (str|None, optional): Name of the output.It's used to print debug info for
developers. Details: :ref:`api_guide_Name`. Default is None.

Returns:
Tensor, the determinant value of a square matrix or batches of square matrices.

Examples:
.. code-block:: pycon

>>> import paddle
>>> paddle.seed(2023)
>>> x = paddle.randn([3, 3, 3])
>>> A = paddle.linalg.det(x)
>>> print(A)
Tensor(shape=[3], dtype=float32, place=Place(cpu), stop_gradient=True,
[-1.29280925, 0.77832544, 0.89754158])


"""
...


@add_doc_and_signature
def diagonal(
x: Tensor,
Expand Down Expand Up @@ -5618,3 +5655,107 @@ def square_(
Inplace version of ``square`` API, the output Tensor will be inplaced with input ``x``.
"""
...


@add_doc_and_signature
def cholesky(
x: Tensor,
upper: bool = False,
name: str | None = None,
*,
out: Tensor | None = None,
) -> Tensor:
r"""
Computes the Cholesky decomposition of one symmetric positive-definite
matrix or batches of symmetric positive-definite matrices.

If ``upper`` is ``True``, the decomposition has the form :math:`A = U^{T}U`,
and the returned matrix :math:`U` is upper-triangular. Otherwise, the
decomposition has the form :math:`A = LL^{T}`, and the returned matrix
:math:`L` is lower-triangular.

Args:
x (Tensor): The input tensor. Its shape should be ``[*, M, M]``,
where ``*`` is zero or more batch dimensions, and matrices on the
inner-most 2 dimensions all should be symmetric positive-definite.
Its data type should be float32 or float64. Alias: ``input``.
upper (bool, optional): The flag indicating whether to return upper or lower
triangular matrices. Default: False.
name (str|None, optional): Name for the operation (optional, default is None).
For more information, please refer to :ref:`api_guide_Name`.

Keyword Args:
out (Tensor|optional): The output tensor. Default: None.

Returns:
Tensor: A Tensor with same shape and data type as ``x``. It represents
triangular matrices generated by Cholesky decomposition.

Examples:
.. code-block:: pycon

>>> import paddle
>>> paddle.seed(2023)

>>> a = paddle.rand([3, 3], dtype="float32")
>>> a_t = paddle.transpose(a, [1, 0])
>>> x = paddle.matmul(a, a_t) + 1e-03

>>> out = paddle.linalg.cholesky(x, upper=False)
>>> print(out)
Tensor(shape=[3, 3], dtype=float32, place=Place(cpu), stop_gradient=True,
[[1.04337060, 0. , 0. ],
[1.06467676, 0.17859183, 0. ],
[1.30602181, 0.08326342, 0.22790733]])
"""
...


@add_doc_and_signature
def eigh(
x: Tensor,
UPLO: Literal['L', 'U'] = 'L',
name: str | None = None,
*,
out: tuple[Tensor, Tensor] | None = None,
) -> tuple[Tensor, Tensor]:
r"""
Compute the eigenvalues and eigenvectors of a
complex Hermitian (conjugate symmetric) or a real symmetric matrix.

Args:
x (Tensor): A tensor with shape ``[*, N, N]``. The data type of the input Tensor x
should be one of float32, float64, complex64, complex128. Alias: ``input``.
UPLO (str, optional): ``'L'`` represents the lower triangular matrix,
``'U'`` represents the upper triangular matrix. Default: ``'L'``.
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 (tuple(Tensor, Tensor)|optional): The output tensors. If provided, the eigenvalues
and eigenvectors will be stored in these tensors. Default: None.

Returns:
2-element tuple containing

- out_value(Tensor): A Tensor with shape ``[*, N]`` and data type of float32 and float64.
The eigenvalues of eigh op.
- out_vector(Tensor): A Tensor with shape ``[*, N, N]`` and data type of float32, float64,
complex64 and complex128. The eigenvectors of eigh op.

Examples:
.. code-block:: pycon

>>> import paddle

>>> x = paddle.to_tensor([[1, -2j], [2j, 5]])
>>> out_value, out_vector = paddle.linalg.eigh(x, UPLO='L')
>>> print(out_value)
Tensor(shape=[2], dtype=float32, place=Place(cpu), stop_gradient=True,
[0.17157286, 5.82842731])
>>> print(out_vector)
Tensor(shape=[2, 2], dtype=complex64, place=Place(cpu), stop_gradient=True,
[[(-0.92387950+0.00000000j), (-0.38268340+0.00000000j)],
[ (0.00000000+0.38268340j), (0.00000000-0.92387950j) ]])
"""
...
Loading
Loading