-
Notifications
You must be signed in to change notification settings - Fork 877
add python-decorator agent rules #7687
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
base: develop
Are you sure you want to change the base?
Conversation
|
感谢你贡献飞桨文档,文档预览构建中,Docs-New 跑完后即可预览,预览链接:http://preview-pr-7687.paddle-docs-preview.paddlepaddle.org.cn/documentation/docs/zh/api/index_cn.html |
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 pull request adds comprehensive documentation for the Python decorator agent rules used in Paddle API compatibility work with PyTorch. The PR introduces a new detailed guide and updates references in existing documentation.
Changes:
- Adds a complete 597-line Python decorator agent guide (
2-1-python-decorator.mdr) covering decorator types, workflows, testing, and best practices - Updates C++ sink agent guide (
2-2-sink-to-cpp.mdr) to refine section headers and add test coverage foroutparameter - Updates the main API compatibility guide (
0-api-compatibility.mdr) to reflect that Python decorator agent is now implemented (removing "暂未实现" status)
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 29 comments.
| File | Description |
|---|---|
docs/dev_guides/coding_agent_rules/api_compatibility/2-1-python-decorator.mdr |
New comprehensive guide for Python decorator approach to API compatibility, including decorator selection, implementation patterns, testing requirements, and troubleshooting |
docs/dev_guides/coding_agent_rules/api_compatibility/2-2-sink-to-cpp.mdr |
Simplified section headers, removed redundant notes, and added test coverage for out parameter in compatibility tests |
docs/dev_guides/coding_agent_rules/api_compatibility/0-api-compatibility.mdr |
Updated Python decorator agent status from "not implemented" to active, adjusted exemption conditions to include both schemes 1 and 2 |
Comments suppressed due to low confidence (1)
docs/dev_guides/coding_agent_rules/api_compatibility/2-2-sink-to-cpp.mdr:16
- 中英文之间需要使用空格分隔。根据文档规范,"消除Python层逻辑开销" 应改为 "消除 Python 层逻辑开销","在C++层高效解析位置参数和关键字参数" 应改为 "在 C++ 层高效解析位置参数和关键字参数","自动完成Paddle与Torch API参数别名的映射转换" 应改为 "自动完成 Paddle 与 Torch API 参数别名的映射转换","C++层原生支持默认参数" 应改为 "C++ 层原生支持默认参数"。
- **性能提升**:消除Python层逻辑开销
- **参数解析**:在C++层高效解析位置参数和关键字参数
- **参数映射**:自动完成Paddle与Torch API参数别名的映射转换
- **默认值处理**:C++层原生支持默认参数
- **灵活扩展**:支持自定义参数处理逻辑
|
|
||
| ## Step 1: 选择装饰器 | ||
|
|
||
| 根据PyTorch API与Paddle API的**差异分析**来选择装饰器: |
Copilot
AI
Jan 20, 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.
中英文之间需要使用空格分隔。根据文档规范,"根据PyTorch API与Paddle API的" 应改为 "根据 PyTorch API 与 Paddle API 的"。
| 1. **不要修改sparse目录下的API** | ||
| 2. **确保不破坏现有功能** | ||
| 3. **保持向后兼容性** | ||
| 4. **优先使用通用装饰器以获得更好性能** | ||
| 5. **开发专用装饰器时参考现有实现** | ||
| 6. **out参数必须作为keyword-only参数** |
Copilot
AI
Jan 20, 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.
中英文之间需要使用空格分隔。根据文档规范,"不要修改sparse目录下的API" 应改为 "不要修改 sparse 目录下的 API","out参数必须作为keyword-only参数" 应改为 "out 参数必须作为 keyword-only 参数"。
|
|
||
| # 二、现有装饰器体系 | ||
|
|
||
| Paddle现有装饰器统一位于 `Paddle/python/paddle/utils/decorator_utils.py`,按功能分为两类: |
Copilot
AI
Jan 20, 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.
中英文之间需要使用空格分隔。根据文档规范,"Paddle现有装饰器" 应改为 "Paddle 现有装饰器"。
| ``` | ||
|
|
||
| **注意事项**: | ||
| - Alias说明应放在参数描述的末尾 |
Copilot
AI
Jan 20, 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.
中英文之间需要使用空格分隔。根据文档规范,"Alias说明应放在参数描述的末尾" 应改为 "Alias 说明应放在参数描述的末尾"。
| ## Paddle API分层结构 | ||
|
|
||
| **Paddle API架构(5层)**: | ||
| 1. **Python层**:Python函数定义(本方案修改层) | ||
| 2. **Pybind层**:Python与C++绑定(自动生成) | ||
| 3. **Dygraph层**:动态图前反向传播组合(自动生成) | ||
| 4. **C++ API层**:Kernel选择调度(自动生成) | ||
| 5. **Kernel层**:实际计算逻辑实现(C++) |
Copilot
AI
Jan 20, 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.
中英文之间需要使用空格分隔。根据文档规范,"Paddle API分层结构" 应改为 "Paddle API 分层结构","Paddle API架构(5层)" 应改为 "Paddle API 架构(5 层)","Python层" 应改为 "Python 层","Python函数定义" 应改为 "Python 函数定义","Pybind层" 应改为 "Pybind 层","Python与C++绑定" 应改为 "Python 与 C++ 绑定","Dygraph层" 应改为 "Dygraph 层","C++ API层" 应改为 "C++ API 层","Kernel选择调度" 应改为 "Kernel 选择调度","Kernel层" 应改为 "Kernel 层","实际计算逻辑实现(C++)" 应改为 "实际计算逻辑实现(C++)"。
|
|
||
| ## Step 4: 更新文档 | ||
|
|
||
| 在函数文档字符串中为有别名的参数添加Alias Support说明: |
Copilot
AI
Jan 20, 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.
中英文之间需要使用空格分隔。根据文档规范,"在函数文档字符串中为有别名的参数添加Alias Support说明" 应改为 "在函数文档字符串中为有别名的参数添加 Alias Support 说明"。
|
|
||
| # 一、角色定义 | ||
|
|
||
| 你擅长《Paddle API对齐PyTorch项目》中的**C++下沉方案**的代码开发。通过将Python API下沉至C++层,可以减少Python装饰器带来的性能开销,提升API调度效率。 |
Copilot
AI
Jan 20, 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.
中英文之间需要使用空格分隔。根据文档规范,"通过将Python API下沉至C++层" 应改为 "通过将 Python API 下沉至 C++ 层","可以减少Python装饰器带来的性能开销" 应改为 "可以减少 Python 装饰器带来的性能开销","提升API调度效率" 应改为 "提升 API 调度效率"。
| - **适用面广**:支持灵活处理多种重载情况:参数名不同、参数顺序不同、参数个数不同、参数类型不同 | ||
| - **向后兼容**:保持Paddle原有API调用方式 | ||
| - **开发效率**:相比C++下沉方案,修改更快速直接 | ||
| - **性能开销**:Python装饰器层会引入轻微性能开销 |
Copilot
AI
Jan 20, 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.
中英文之间需要使用空格分隔。根据文档规范,"Python装饰器层会引入轻微性能开销" 应改为 "Python 装饰器层会引入轻微性能开销"。
| ## 特点 | ||
| - **零侵入性**:无需修改API的C++底层代码 | ||
| - **适用面广**:支持灵活处理多种重载情况:参数名不同、参数顺序不同、参数个数不同、参数类型不同 | ||
| - **向后兼容**:保持Paddle原有API调用方式 |
Copilot
AI
Jan 20, 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.
中英文之间需要使用空格分隔。根据文档规范,"保持Paddle原有API调用方式" 应改为 "保持 Paddle 原有 API 调用方式"。
| out5 = x.log2() | ||
| paddle_dygraph_out.append(out5) | ||
|
|
||
| # 测试out参数 |
Copilot
AI
Jan 20, 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.
中英文之间需要使用空格分隔。根据文档规范,"测试out参数" 应改为 "测试 out 参数"。
Python装饰器智能体编程规则