-
Notifications
You must be signed in to change notification settings - Fork 5.9k
API Compatibility Edit by AI Agent #77161
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
|
你的PR提交成功,感谢你对开源项目的贡献! |
d397a48 to
9477fa1
Compare
7b01df7 to
98f0bde
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull request overview
This PR implements API compatibility for 15 PyTorch APIs in Paddle, automatically generated by an AI Agent following specific programming rules. The changes include C++ implementations, comprehensive compatibility tests, and documentation updates.
Key changes:
- Added compatibility layer for PyTorch-style API calls (supporting both
input/otherandx/yparameter names) - Moved several API implementations from individual modules to centralized
_C_opsimports - Added comprehensive compatibility tests covering positional args, keyword args, and tensor methods
- Updated documentation to include the
outparameter support
Reviewed changes
Copilot reviewed 18 out of 18 changed files in this pull request and generated 8 comments.
Show a summary per file
| File | Description |
|---|---|
| test/legacy_test/test_api_compatibility.py | New comprehensive compatibility test suite for 15 APIs with multiple calling patterns |
| test/xpu/test_zero_dim_tensor_xpu.py | Fixed API name handling for private methods using lstrip('_') |
| test/legacy_test/test_zero_dim_binary_api.py | Fixed API name handling for private methods using lstrip('_') |
| test/legacy_test/test_bitwise_op.py | Updated import paths from paddle.tensor.logic to paddle.tensor |
| test/legacy_test/test_bincount_op.py | Added static graph dtype validation test |
| python/paddle/tensor/ops.py | Removed implementations, added imports from centralized modules |
| python/paddle/tensor/math.py | Removed implementations, added imports, fixed variable naming conflicts |
| python/paddle/tensor/logic.py | Removed implementations, added imports, updated function signatures |
| python/paddle/tensor/linalg.py | Moved bincount to centralized import |
| python/paddle/pir/generated_methods_patch.py | Added magic method mapping for PIR Value types |
| python/paddle/_paddle_docs.py | Added/updated documentation for all 15 APIs with out parameter support |
| paddle/phi/ops/yaml/python_api_info.yaml | Reorganized and added API alias mappings alphabetically |
| paddle/fluid/pybind/arg_pre_process.h | Added BinCountPreProcess function declarations |
| paddle/fluid/pybind/arg_pre_process.cc | Implemented dtype validation for bincount |
| paddle/fluid/eager/auto_code_generator/generator/monkey_patch_gen.py | Added magic method patching support |
| test/auto_parallel/*.py | Changed MSELoss to L1Loss for PIR compatibility |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
python/paddle/tensor/ops.py
Outdated
| def round_(x, decimals=0, name=None): | ||
| r""" | ||
| Inplace version of ``round`` API, the output Tensor will be inplaced with input ``x``. | ||
| Inplace version of ``round`` API, output Tensor will be inplaced with input ``x``. |
Copilot
AI
Jan 5, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The comment typo "output Tensor will be inplaced" should be "output Tensor will be updated in-place" for better clarity and grammar.
| Inplace version of ``round`` API, output Tensor will be inplaced with input ``x``. | |
| Inplace version of ``round`` API, output Tensor will be updated in-place with input ``x``. |
| if isinstance(y, (int, bool)): | ||
| y_tensor = paddle.to_tensor(y, dtype=x.dtype) | ||
| return bitwise_and(y_tensor, x, None, None) | ||
| return bitwise_and(y_tensor, x) |
Copilot
AI
Jan 5, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The function call bitwise_and(y_tensor, x, None, None) has incorrect arguments. Based on the new signature in the imports and documentation, bitwise_and should be called as bitwise_and(y_tensor, x) without the extra None arguments, as the function now uses keyword-only out parameter.
| if in_dynamic_or_pir_mode() and out is None: | ||
| return _C_ops.bitwise_or(x, y) | ||
| if in_dynamic_or_pir_mode(): | ||
| return _C_ops.bitwise_or(x, y, out=out) |
Copilot
AI
Jan 5, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The bitwise_or function is modified to always call _C_ops.bitwise_or(x, y, out=out) in dynamic mode, but this will fail when out is None since the C++ op likely doesn't accept out=None. The original code checked out is None before calling the C++ op. This change may cause runtime errors when out parameter is not provided.
| return _C_ops.bitwise_or(x, y, out=out) | |
| if out is None: | |
| return _C_ops.bitwise_or(x, y) | |
| _C_ops.bitwise_or(x, y, out) | |
| return out |
98f0bde to
1fb60d0
Compare
69e66ee to
9914df0
Compare
9914df0 to
4496d99
Compare
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## develop #77161 +/- ##
===========================================
Coverage ? 100.00%
===========================================
Files ? 6
Lines ? 29
Branches ? 0
===========================================
Hits ? 29
Misses ? 0
Partials ? 0 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
XiaoguangHu01
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
PR Category
User Experience
PR Types
New features
Description
本PR由AI Agent基于 PaddlePaddle/docs#7676 中定义的AI编程规则自动开发而成。所有代码均由AI Agent严格遵循这些规则生成,保证了风格和实现的一致性,实现了多个PyTorch API向Paddle的兼容性适配和C++下沉优化。适用于《Paddle API兼容性项目》工作。
涉及的API
本PR涉及以下15个API的兼容性开发:
主要修改内容
1. AI编程规则文件(提交至 PaddlePaddle/docs#7676 )
适用于《Paddle API兼容性项目》工作,定义了以下规则文件:
0-api-compatibility.mdr)1-scheme-decision.mdr)2-2-sink-to-cpp.mdr)3-paconvert-test.mdr)4-modify-docs.mdr)规则文件本身无法独立运行,必须与Agent配合使用,作为Agent执行的指令依据。系统采用主控智能体 + 子智能体的协作架构,上述5份规则文件分别对应不同智能体的执行指令。通过各智能体的协同工作,完成了以下Paddle / PaConvert / Docs的开发。
2. 代码开发
python_api_info.yaml、_paddle_docs.py内容格式,代码提交至本PR3. 文档更新
out关键字参数等技术特点