Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
78 changes: 78 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,84 @@ 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(
*UPLO == "L" || *UPLO == "U",
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));
PADDLE_ENFORCE_EQ(x_shape[rank - 1],

This comment was marked as outdated.

x_shape[rank - 2],
phi::errors::InvalidArgument(
"The input matrix must be batches of square matrices. "
"But received x's dimension."));
PADDLE_ENFORCE(
*UPLO == "L" || *UPLO == "U",
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));
PADDLE_ENFORCE_EQ(

This comment was marked as outdated.

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
72 changes: 72 additions & 0 deletions python/paddle/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -515,6 +515,7 @@ def new_init(self, *args, **kwargs):
dstack,
expand,
expand_as,
expand_copy,
flatten,
flatten_,
flip,
Expand Down Expand Up @@ -623,6 +624,7 @@ def new_init(self, *args, **kwargs):
cartesian_prod,
ceil,
clip,
clip_,
combinations,
conj,
copysign,
Expand Down Expand Up @@ -768,6 +770,7 @@ def new_init(self, *args, **kwargs):
trace,
trapezoid,
true_divide,
true_divide_,

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.tensor.math 导入 true_divide_,但当前同一 PR 已经删除了 python/paddle/tensor/math.py 里的 def true_divide_,只在 python/paddle/tensor/__init__.py 里做了 true_divide_ = divide_paddle/__init__.py 的这个 import 会在 import paddle 阶段直接触发 ImportError: cannot import name 'true_divide_',导致整个包无法导入。请不要从 math.py 导入不存在的符号,而是在顶层按已有 div_ = divide_ 的方式创建别名。

Suggested change
true_divide_,

同时在下面 alias 区域补上:

true_divide_ = divide_

This comment was marked as outdated.

trunc,
trunc_,
vander,
Expand Down Expand Up @@ -1055,6 +1058,7 @@ def __dir__(self):
concatenate = concat
take_along_dim = take_along_axis
clamp = clip
clamp_ = clip_
ger = outer
div = divide
div_ = divide_
Expand All @@ -1080,6 +1084,67 @@ def __dir__(self):
negative_ = neg_
pinverse = pinv


def clamp_max(x, max=None, *, out=None):
"""
Clamps all elements in input into the range [min=None, max].

This is a wrapper around ``paddle.clip`` that only sets the upper bound.

Args:
x (Tensor): The input Tensor. Alias: input.
max (float|Tensor): The upper bound.
out (Tensor|None, optional): The output Tensor. Default: None.

Returns:
Tensor: The clamped Tensor.
"""
return clip(x, min=None, max=max, name=None, out=out)


def qr(input, some=True, *, out=None):
"""
Computes the QR decomposition of one or a batch of matrices.

This is a wrapper around ``paddle.linalg.qr`` with PyTorch-compatible
``some`` parameter.

Args:
input (Tensor): The input tensor of shape ``[*, M, N]``.
some (bool, optional): Controls the shape of Q and R. If ``True`` (default),
returns reduced QR (Q: ``[*, M, K]``, R: ``[*, K, N]`` where ``K = min(M, N)``).
If ``False``, returns complete QR (Q: ``[*, M, M]``, R: ``[*, M, N]``).
out (tuple[Tensor, Tensor]|None, optional): The output tuple of (Q, R). Default: None.

Returns:
tuple[Tensor, Tensor]: A tuple (Q, R).
"""
return linalg.qr(
input,
mode='reduced' if some else 'complete',
out=out,
)


def logdet(x, name=None):
"""
Computes the natural logarithm of the determinant of a square matrix or
batches of square matrices.

For matrices with negative determinant, returns ``nan``.
For matrices with zero determinant, returns ``-inf``.

Args:
x (Tensor): The input tensor of shape ``[*, n, n]`` where ``*``
is zero or more batch dimensions.
name (str|None, optional): Name for the operation. Default: None.

Returns:
Tensor: The log-determinant of ``x``, with shape ``[*]``.
"""
return linalg.det(x).log()


__all__ = [
'block_diag',
'gt',
Expand Down Expand Up @@ -1215,7 +1280,10 @@ def __dir__(self):
'less_',
'kron',
'clip',
'clip_',
'clamp',
'clamp_',
'clamp_max',
'Tensor',
'FloatTensor',
'DoubleTensor',
Expand Down Expand Up @@ -1329,6 +1397,7 @@ def __dir__(self):
'CPUPlace',
'matmul',
'pinverse',
'qr',
'seed',
'acos',
'acos_',
Expand Down Expand Up @@ -1377,6 +1446,7 @@ def __dir__(self):
'sub',
'sub_',
'true_divide',
'true_divide_',
'gammaln',
'gammaln_',
'ceil',
Expand Down Expand Up @@ -1457,6 +1527,7 @@ def __dir__(self):
'set_default_tensor_type',
'disable_signal_handler',
'expand_as',
'expand_copy',
'stack',
'hstack',
'vstack',
Expand Down Expand Up @@ -1488,6 +1559,7 @@ def __dir__(self):
'cosh',
'log',
'log_',
'logdet',
'log2',
'log2_',
'log10',
Expand Down
Loading
Loading