Skip to content

Conversation

@Manfredss
Copy link
Contributor

@Manfredss Manfredss commented Dec 24, 2025

PR Category

User Experience

PR Types

New features

Description

Sink paddle.inverse to cpp
Add param alias for x
Add new param out

@paddle-bot
Copy link

paddle-bot bot commented Dec 24, 2025

你的PR提交成功,感谢你对开源项目的贡献!
请关注后续CI自动化测试结果,详情请参考Paddle-CI手册
Your PR has been submitted. Thanks for your contribution!
Please wait for the result of CI firstly. See Paddle CI Manual for details.

@paddle-bot paddle-bot bot added the contributor External developers label Dec 24, 2025
@codecov-commenter
Copy link

codecov-commenter commented Dec 25, 2025

Codecov Report

✅ All modified and coverable lines are covered by tests.
⚠️ Please upload report for BASE (develop@304d5c2). Learn more about missing BASE report.

Additional details and impacted files
@@             Coverage Diff             @@
##             develop    #77078   +/-   ##
===========================================
  Coverage           ?   100.00%           
===========================================
  Files              ?         1           
  Lines              ?         1           
  Branches           ?         0           
===========================================
  Hits               ?         1           
  Misses             ?         0           
  Partials           ?         0           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@Manfredss
Copy link
Contributor Author

/re-run all-failed

""",
)

add_doc_and_signature(
Copy link
Contributor

Choose a reason for hiding this comment

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

可以往这个文件里的中间插入,不然PR容易前后自己冲突。

Copy link
Contributor

@zhwesky2010 zhwesky2010 left a comment

Choose a reason for hiding this comment

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

PR冲突了,_paddle_docs.py这个文件容易冲突。可以都往最后面加。

)


add_doc_and_signature(
Copy link
Contributor

Choose a reason for hiding this comment

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

gcd下沉了吗,没下沉直接在python api的位置维护文档和签名,这里不需要加。

)


add_doc_and_signature(
Copy link
Contributor

Choose a reason for hiding this comment

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

这些都是用于c++下沉的

out_res, _ = paddle.static.nn.while_loop(
_gcd_cond_fn, _gcd_body_fn, [x, y]
)
if out is not None:
Copy link
Contributor

Choose a reason for hiding this comment

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

上下两个out分支可以合并下处理


@param_two_alias(['x', 'input'], ['y', 'other'])
def gcd(x: Tensor, y: Tensor, name: str | None = None) -> Tensor:
@ParamAliasDecorator({"x": ["input"], "y": ["other"]})
Copy link
Contributor

Choose a reason for hiding this comment

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

这个装饰器性能要比param_two_alias差点,后面还是可以直接用param_two_alias

zhwesky2010
zhwesky2010 previously approved these changes Dec 26, 2025
@zhwesky2010 zhwesky2010 requested a review from SigureMo December 26, 2025 05:47
Co-authored-by: Nyakku Shigure <[email protected]>
SigureMo
SigureMo previously approved these changes Dec 26, 2025
@Manfredss
Copy link
Contributor Author

/re-run all-failed

Copy link
Contributor

@zhwesky2010 zhwesky2010 left a comment

Choose a reason for hiding this comment

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

冲突需要重新处理下。

zhwesky2010
zhwesky2010 previously approved these changes Jan 22, 2026
@zhwesky2010
Copy link
Contributor

zhwesky2010 commented Jan 22, 2026

@Manfredss 这个下沉后有些case无法通过了,你本地测试下看什么问题。
https://github.com/PaddlePaddle/PaddleTest/blob/develop/framework/api/linalg/test_inv.py

CI-Build / CE-Framework / Test (pull_request) 测试结果失败:
infoflow 2026-01-22 12-14-35

@Manfredss
Copy link
Contributor Author

@Manfredss 这个下沉后有些case无法通过了,你本地测试下看什么问题。

这个测试文件里为什么是 @pytest.mark.api_linalg_det_vartype 而不是 @pytest.mark.api_linalg_inv_vartype?
然后应该要把 apibase.py 里的

if isfunction(func)

判断改为

if isfunction(func) or callable(func) and not hasattr(func, '__mro__')

使其能够正确识别 builtin_function_or_method 类型(如 paddle.linalg.inv)作为函数而不是类

@zhwesky2010
Copy link
Contributor

@Manfredss 这个下沉后有些case无法通过了,你本地测试下看什么问题。

这个测试文件里为什么是 @pytest.mark.api_linalg_det_vartype 而不是 @pytest.mark.api_linalg_inv_vartype? 然后应该要把 apibase.py 里的

if isfunction(func)

判断改为

if isfunction(func) or callable(func) and not hasattr(func, '__mro__')

使其能够正确识别 builtin_function_or_method 类型(如 paddle.linalg.inv)作为函数而不是类

在paddle/_init_.py最后会 monkey_patch_generated_methods_for_tensor,重新将公开API:paddle.*paddle.tensor.*F.* 换成有python接口的,而paddle.linalg.inv导入了原始的pybind的inverse。这里需要看看调整下这一系列导入方式。在patch完之后,再从from paddle.tensor import inverse as inv就没问题。

infoflow 2026-01-22 15-03-38

@Manfredss
Copy link
Contributor Author

@Manfredss 这个下沉后有些case无法通过了,你本地测试下看什么问题。

这个测试文件里为什么是 @pytest.mark.api_linalg_det_vartype 而不是 @pytest.mark.api_linalg_inv_vartype? 然后应该要把 apibase.py 里的

if isfunction(func)

判断改为

if isfunction(func) or callable(func) and not hasattr(func, '__mro__')

使其能够正确识别 builtin_function_or_method 类型(如 paddle.linalg.inv)作为函数而不是类

在paddle/init.py最后会 monkey_patch_generated_methods_for_tensor,重新将公开API:paddle.*paddle.tensor.*F.* 换成有python接口的,而paddle.linalg.inv导入了原始的pybind的inverse。这里需要看看调整下这一系列导入方式。在patch完之后,再从from paddle.tensor import inverse as inv就没问题。

infoflow 2026-01-22 15-03-38

我看看

@Manfredss
Copy link
Contributor Author

@Manfredss 这个下沉后有些case无法通过了,你本地测试下看什么问题。

这个测试文件里为什么是 @pytest.mark.api_linalg_det_vartype 而不是 @pytest.mark.api_linalg_inv_vartype? 然后应该要把 apibase.py 里的

if isfunction(func)

判断改为

if isfunction(func) or callable(func) and not hasattr(func, '__mro__')

使其能够正确识别 builtin_function_or_method 类型(如 paddle.linalg.inv)作为函数而不是类

在paddle/init.py最后会 monkey_patch_generated_methods_for_tensor,重新将公开API:paddle.*paddle.tensor.*F.* 换成有python接口的,而paddle.linalg.inv导入了原始的pybind的inverse。这里需要看看调整下这一系列导入方式。在patch完之后,再从from paddle.tensor import inverse as inv就没问题。

infoflow 2026-01-22 15-03-38

那 linalg.py 中也得改吧

@Manfredss Manfredss dismissed stale reviews from zhwesky2010 and SigureMo via 3608a16 January 24, 2026 09:27
@Manfredss
Copy link
Contributor Author

/re-run all-failed

1 similar comment
@Manfredss
Copy link
Contributor Author

/re-run all-failed

@Manfredss
Copy link
Contributor Author

问题描述

CI 测试中会有 CE-Framework 测试失败,经过本地测试复现失败:

pytest PaddleTest/framework/api/linalg/test_inv.py

这是由于 paddle.linalg.inv 未定义造成的

问题拆解

  1. API 路径缺失:操作在 paddle/phi/ops/yaml/python_api_info.yaml 中仅配置了 paddle.inversepaddle.Tensor.inverse 两个路径,未包含 paddle.linalg.inv
  2. 代码生成器限制:monkey_patch_gen.py 中的 ClassifyAPIByPrefix 函数仅支持三种硬编码前缀:
if prefix == "paddle.":
    paddle_func_map.append(...)
elif prefix == "paddle.Tensor.":
    tensor_method_map.append(...)
elif prefix == "paddle.nn.functional.":
    nn_func_map.append(...)
else:
    raise Exception("Unsupported Prefix " + prefix, "API : " + name)

这意味着即使在 python_api_info.yaml 中直接添加 paddle.linalg.inv 也会因不支持前缀而抛出异常
3. paddle.linalg.inv 只是暴露了这个问题,需要为类似的 API 手动添加特殊处理逻辑

解决方案

生成器增强:扩展 monkey_patch_gen.py 以支持通用模块路径

  1. 新增 generic_funcs_map 储存 (module_path, method_name, method) 元组
  2. 修改 ClassifyAPIByPrefix 函数将未匹配的 paddle.* 前缀纳入通用映射表
  3. 在运行时通过 getattr() 动态调用目标模块并设置属性

优点: 未来添加类似路径的 API,如 paddle.fft.* 等时,只要在 yaml 文件中配置即可,方便快捷

修改文件

  • paddle/fluid/eager/auto_code_generator/generator/monkey_patch_gen.py: 支持通用模块路径
  • paddle/phi/ops/yaml/python_api_info.yaml: 在 inverse 操作配置中添加 paddle.linalg.inv

修改后测试:

python paddle/test/legacy_test/test_inverse_op.py  # 测试通过
pytest PaddleTest/framework/api/linalg/test_inv.py  # 测试通过

@Manfredss
Copy link
Contributor Author

/re-run all-failed

)


def __getattr__(name):
Copy link
Contributor

Choose a reason for hiding this comment

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

这样能解决一个单点的API导入问题。

但这个是一个共性的问题,后续比如这里的

    cholesky,
    cholesky_inverse,
    cholesky_solve,

如果下沉也都会遇到类似的问题,调研下更通用的解决方案,参考:

  1. 修改patch顺序,提前monkey_patch_generated_methods_for_tensor的位置
  2. 修改monkey_patch_generated_methods_for_tensor逻辑,目前只会根据python_api_info.yaml里的paddle.*来配置patch,如果这个name支持paddle.linalg.inv或任意其他路径的patch也能解决问题
infoflow 2026-01-26 11-57-45

method_name = name.split(".")[
-1
] # Extract the method name from full path
if prefix == "paddle.":
Copy link
Contributor

Choose a reason for hiding this comment

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

整体合并成一套逻辑,这一块整体重构,不用在之前局限的设计上 打补丁

@Manfredss
Copy link
Contributor Author

/re-run all-failed

@YqGe585
Copy link
Member

YqGe585 commented Jan 30, 2026

请先不要rerun IXUCA, 预计今天修复,明天rebase此分支到develop即可

@YqGe585
Copy link
Member

YqGe585 commented Jan 30, 2026

可以rebase到develop,重跑CI看下

Copy link
Contributor

@zhwesky2010 zhwesky2010 left a comment

Choose a reason for hiding this comment

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

LGTM

@zhwesky2010 zhwesky2010 requested a review from SigureMo January 30, 2026 03:54
@zhwesky2010 zhwesky2010 requested a review from zyfncg January 30, 2026 04:49
@zhwesky2010 zhwesky2010 merged commit 78499bd into PaddlePaddle:develop Jan 30, 2026
228 of 244 checks passed
@zhwesky2010 zhwesky2010 changed the title [API Compatibility No.360] Sink paddle.inverse to cpp -part [API Compatibility No.360] Improve Cpp sink mechanism and sink paddle.inverse to cpp -part Jan 30, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

7 participants