Skip to content

Conversation

@zhwesky2010
Copy link
Contributor

@zhwesky2010 zhwesky2010 commented Dec 31, 2025

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的兼容性开发:

torch.fmax
torch.fmin
torch.bincount
torch.diag
torch.atan
torch.tan
torch.bitwise_and
torch.bitwise_not
torch.bitwise_xor
torch.nextafter
torch.angle
torch.heaviside
torch.asinh
torch.reciprocal
torch.square

主要修改内容

1. AI编程规则文件(提交至 PaddlePaddle/docs#7676

适用于《Paddle API兼容性项目》工作,定义了以下规则文件:

  • API兼容性主控规则 (0-api-compatibility.mdr)
  • 方案决策规则 (1-scheme-decision.mdr)
  • C++下沉规则 (2-2-sink-to-cpp.mdr)
  • Pytorch对齐测试规则 (3-paconvert-test.mdr)
  • 文档修改规则 (4-modify-docs.mdr)

规则文件本身无法独立运行,必须与Agent配合使用,作为Agent执行的指令依据。系统采用主控智能体 + 子智能体的协作架构,上述5份规则文件分别对应不同智能体的执行指令。通过各智能体的协同工作,完成了以下Paddle / PaConvert / Docs的开发。

2. 代码开发

  • Paddle C++下沉开发:实现了15个API的C++下沉优化,AI整体优化 python_api_info.yaml_paddle_docs.py 内容格式,代码提交至本PR
  • PaConvert开发:在 PaConvert上进行了兼容性测试,代码提交至 API Compatibility Edit by AI Agent PaConvert#797

3. 文档更新

技术特点

  • 自动化开发流程:代码主体均基于AI Agent自动编码生成,确保了代码风格和实现的一致性
  • 完整的测试覆盖:每个API均包含全面的兼容性测试,覆盖Pytorch与Paddle两套签名的各种可能用法,测试用例完备且规范

本PR描述由 AI 辅助生成

@paddle-bot
Copy link

paddle-bot bot commented Dec 31, 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.

SigureMo
SigureMo previously approved these changes Jan 5, 2026
Copy link
Contributor

Copilot AI left a 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/other and x/y parameter names)
  • Moved several API implementations from individual modules to centralized _C_ops imports
  • Added comprehensive compatibility tests covering positional args, keyword args, and tensor methods
  • Updated documentation to include the out parameter 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.

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``.
Copy link

Copilot AI Jan 5, 2026

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.

Suggested change
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``.

Copilot uses AI. Check for mistakes.
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)
Copy link

Copilot AI Jan 5, 2026

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.

Copilot uses AI. Check for mistakes.
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)
Copy link

Copilot AI Jan 5, 2026

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.

Suggested change
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

Copilot uses AI. Check for mistakes.
SigureMo
SigureMo previously approved these changes Jan 5, 2026
@zhwesky2010 zhwesky2010 force-pushed the coding_agent branch 2 times, most recently from 69e66ee to 9914df0 Compare January 6, 2026 11:45
@codecov-commenter
Copy link

Codecov Report

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

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.
📢 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.

@zhwesky2010 zhwesky2010 requested review from XiaoguangHu01 and removed request for XiaoguangHu01 January 7, 2026 03:57
Copy link
Contributor

@XiaoguangHu01 XiaoguangHu01 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 merged commit a791e6b into PaddlePaddle:develop Jan 7, 2026
118 of 125 checks passed
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.

5 participants