Skip to content

Conversation

@DanielSun11
Copy link
Contributor

@DanielSun11 DanielSun11 commented Aug 13, 2025

PR Category

Operator Mechanism

PR Types

New features

Description

API C++ 下沉方案机制建设。

为了解决装饰器方案开销较大的问题,制定了API下沉至C++层的方案,该方案在C++层面实现了:

  • 参数解析。支持提取Python传入的位置参数、关键字参数等信息。
  • 参数映射。自动完成Paddle API的参数与Torch API参数之间的映射和转换。
  • 默认值处理。将原有的在Python层面实现的默认值参数,在C++层提供同样支持。
  • 自定义处理逻辑。支持将一些Python层的处理逻辑下沉到C++层。支持自定义的参数解析/映射方案,实现更加灵活的参数映射。
  • 文档绑定。提供为下沉至C++的API添加说明文档的功能。 解决原来的C++接口缺少对API的说明文档,导致下沉之后的API没有文档问题。

整体改动:

  • 修改python_c code Gen的生成逻辑。在 paddle/fluid/pybind/eager_op_function.cc 以及 paddle/fluid/pybind/static_op_function.cc 中的代码生成时添加对 参数解析(关键字传参、组合传参)、参数映射(参数重命名)、默认值处理(python api的默认值下沉到C++处理)、自定义处理逻辑(应对复杂的参数映射场景、在python中对参数的预处理场景)

  • utils功能增强。paddle/fluid/pybind/eager_utils.cc paddle/fluid/pybind/op_function_common.cc 中新增了部分用于从args和kwargs里取参数的函数,以及对一些PyObject转C++ 数据类型的一些utils增加了默认值设置功能。

  • 文档与api绑定。新增python/paddle/_paddle_docs.py 用于存放/注册下沉后的API的文档,新增_add_docstr 用于为下称后的C++ API绑定API。

  • 新增monkey pacth自动生成功能。主要用于将下沉后的C++ API注册为Tensor/Value 的method。

  • ops yaml 格式的新增映射条目 。 增加python_api映射条目,用于描述对应的python API,参数别名、自定义处理逻辑的接口。

pcard-67164

@paddle-bot
Copy link

paddle-bot bot commented Aug 13, 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.

@DanielSun11 DanielSun11 changed the title [WIP] Test [WIP] Test CI Aug 13, 2025
@DanielSun11 DanielSun11 changed the title [WIP] Test CI [WIP] Provide mechanical support for the Python API to sink to the C++ layer Aug 15, 2025
@DanielSun11 DanielSun11 changed the title [WIP] Provide mechanical support for the Python API to sink to the C++ layer [API Compatible ]Provide mechanical support for the Python API to sink to the C++ layer Aug 15, 2025
Copy link
Contributor

@wanghuancoder wanghuancoder left a comment

Choose a reason for hiding this comment

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

LGTM 签名问题下一个PR补充

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

Comment on lines +242 to +246
python_api :
name : [paddle.amax,paddle.Tensor.amax]
args_alias:
x : [input,x1]
axis : [dim]
Copy link
Contributor

Choose a reason for hiding this comment

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

这里的配置信息有点多,感觉需要做一些信息压缩

Copy link
Contributor Author

Choose a reason for hiding this comment

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

好!计划增加一些默认规则的转换,比如x和input以及dim和axis的对应关系,这些非常通用的对应关系就不需要在yaml中显示的写出了

@DanielSun11 DanielSun11 merged commit 2bec694 into PaddlePaddle:develop Aug 15, 2025
143 of 156 checks passed
@DanielSun11 DanielSun11 deleted the getargs branch September 18, 2025 06:26
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.

6 participants