Skip to content

Conversation

DanielSun11
Copy link
Contributor

@DanielSun11 DanielSun11 commented Aug 19, 2025

PR Category

Operator Mechanism

PR Types

New features

Description

Python API 下沉C++的机制支持Args mapper

- op : amax
  args : (Tensor x, int64_t[] axis={}, bool keepdim=false)
  python_api :
    name : [paddle.amax, paddle.Tensor.amax]   # 对应的python API
    args_mapper: 
      func : AmaxArgsMapper                   # 自定义Mapper 
  output : Tensor(out)
  infer_meta :
    func : ReduceInferMeta
  kernel :
    func : amax
  backward : amax_grad
  interfaces : paddle::dialect::InferSymbolicShapeInterface, paddle::dialect::LayoutTransformationInterface

yaml中python_api映射条目下支持args_mapper配置自定义的函数参数解析逻辑。

args_mapper(可选) :自定义的参数转换方法。用于处理复杂的参数转换场景,针对于api进行定制实现。有如下几种可选的配置方法:

  • func: 动态图和静态图都使用的args_mapper
  • dygraph_func : 指定动态图使用的args_mapper。可以单独使用,效果是只在动态图中有args_mapper,优先级高于func
  • static_func :指定静态图使用的args_mapper。可以单独使用,效果是只在静态图中有args_mapper,优先级高于func

自定义和args mapper的声明放在:paddle/fluid/pybind/args_mapper.h 实现放在:paddle/fluid/pybind/args_mapper.cc
pcard-67164

@DanielSun11 DanielSun11 changed the title [API Compatiblity] Support the ArgMapper mechanism when the Python API is integrated into the C++ layer [API Compatiblity] Support the Arg Mapper mechanism when the Python API is integrated into the C++ layer Aug 19, 2025
@DanielSun11 DanielSun11 changed the title [API Compatiblity] Support the Arg Mapper mechanism when the Python API is integrated into the C++ layer [API Compatiblity] Support the Args Mapper mechanism when the Python API is integrated into the C++ layer Aug 19, 2025
Copy link
Contributor

@XieYunshen XieYunshen left a comment

Choose a reason for hiding this comment

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

LGTM

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

@wanghuancoder wanghuancoder merged commit 632615c into PaddlePaddle:develop Aug 22, 2025
326 of 383 checks passed
Luckycheng222 pushed a commit to Luckycheng222/Paddle that referenced this pull request Aug 25, 2025
…API is integrated into the C++ layer (PaddlePaddle#74750)

* support args mapper

* format

* fix none

* add test time out
@DanielSun11 DanielSun11 deleted the arg_mapper 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.

5 participants