Skip to content
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

[NewIR] elementwise_add 参数名映射修复 #55403

Merged
merged 1 commit into from Jul 14, 2023

Conversation

RedContritio
Copy link
Contributor

@RedContritio RedContritio commented Jul 13, 2023

PR types

Others

PR changes

Others

Description

添加 elementwise_add 的算子参数映射

修复流程简单教学:

假设你要修复的算子是 xxx,你要做的是,

1. 首先判断是否有别名:

项目内搜索 PD_REGISTER_BASE_KERNEL_NAME(xxx, yyy),如果能找到,则表明 xxx 算子的别名是 yyy,后续搜索流程则使用 yyy 来搜索,以 elementwise_add 为例,别名是 add,如果没有,则表示其没有别名。

2. 配置算子映射

首先打开 paddle/phi/api/yaml/op_compat.yaml,全文搜索 op : yyy,看看能否找到,如果不能,那么先插入:

- op : yyy (xxx)

如果没有别名,则直接 - op : xxx 即可。

3. 判断算子动态参数

接下来,你需要判断这个算子的动态参数名,首先打开 paddle/phi/api/yaml/legacy_ops.yaml (和 paddle/phi/api/yaml/legacy_backward.yaml),全文搜索 - op : yyy

比如

- op : add
  args : (Tensor x, Tensor y)
  output : Tensor(out)
  infer_meta :
    func : ElementwiseInferMeta
  kernel :
    func : add
  inplace : (x -> out)
  backward : add_grad

可以看到参数为 x, y,输出为 out,其余内容可以先忽略。

4. 判断算子静态参数

寻找 xxx_op.cc 文件,如果找不到,则查找 REGISTER_OPERATOR(xxx) 的出现文件,随后你就可以通过里面的 OpMaker 判断。

  void AddInputX() override {
    AddInput(
        "X",
        "(Variable), Tensor or phi::DenseTensor of any dimensions. Its dtype "
        "should be int32, int64, float32, float64.");
  }

  void AddInputY() override {
    AddInput(
        "Y",
        "(Variable), Tensor or phi::DenseTensor of any dimensions. Its dtype "
        "should be int32, int64, float32, float64.");
  }

可以看到其中 x、y 是对应大写等等。

5. 基于动静参数配置映射

参考前面得到的参数,如果两者不同,则配置不同部分如下:

  inputs :
    {x : X, y : Y}

6. 配置输出参数、特殊参数等等

根据具体情况而定,不特殊说明,流程基本如上。

@paddle-bot
Copy link

paddle-bot bot commented Jul 13, 2023

你的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.

@paddle-bot paddle-bot bot added contributor External developers status: proposed labels Jul 13, 2023
@luotao1 luotao1 added the HappyOpenSource 快乐开源活动issue与PR label Jul 13, 2023
@kangguangli
Copy link
Contributor

LGTM

Copy link
Contributor

@heavyrain-lzy heavyrain-lzy left a comment

Choose a reason for hiding this comment

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

LGTM

@kangguangli
Copy link
Contributor

kangguangli commented Jul 14, 2023

@RedContritio 可以rerun下失败的CI,其他PR也记得看下

@luotao1 luotao1 merged commit fd72b32 into PaddlePaddle:develop Jul 14, 2023
26 of 27 checks passed
@RedContritio RedContritio deleted the elementwise_add_compat branch July 14, 2023 09:15
cqulilujia pushed a commit to cqulilujia/Paddle that referenced this pull request Jul 24, 2023
wz1qqx pushed a commit to wz1qqx/Paddle that referenced this pull request Jul 31, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
contributor External developers HappyOpenSource 快乐开源活动issue与PR
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants