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

【开源任务】新 IR API 推全升级 #57097

Closed
YuanRisheng opened this issue Sep 8, 2023 · 19 comments
Closed

【开源任务】新 IR API 推全升级 #57097

YuanRisheng opened this issue Sep 8, 2023 · 19 comments
Assignees
Labels
HappyOpenSource 快乐开源活动issue与PR PFCC Paddle Framework Contributor Club,https://github.com/PaddlePaddle/community/tree/master/pfcc status/close 已关闭

Comments

@YuanRisheng
Copy link
Contributor

YuanRisheng commented Sep 8, 2023

一,背景和任务列表

详情见:#55737

⭐️ 提交PR 模版 ⭐️:

  • // ------- PR 标题 --------
[PIR] No.1 Migrate paddle.mean into pir
  • // ------- PR 内容 --------
PR types
Others

PR changes
APIs

Description
[PIR]Migrate layer_norm into pir
总计 20 个单测打开13个单测7个单测继承自unittest.TestCase没有覆盖到

Pcard-67164

本期需要升级的 API 如下:(整体进展:48/48)

按 merge 的时间顺序,排名不分先后(P0的需尽可能在 9月15日前合入,P1尽可能在10月10前合入❀❀)

序号 Python API 所在文件 贡献者 PR链接 优先级 单测覆盖率
1✅ mean python/paddle/tensor/stat.py @0x45f #56809 p0
2✅ sum python/paddle/tensor/math.py @0x45f #57016 p0
3✅ divide python/paddle/tensor/math.py @changeyoung98 #57186 #57315 p0
4✅ fill_constant python/paddle/tensor/creation.py @0x45f #57020 p0
5✅ layer_norm python/paddle/nn/functional/norm.py @0x45f #57324 p0
6✅ dropout python/paddle/nn/functional/common.py @0x45f #57319 p0
7✅ gelu python/paddle/nn/functional/activation.py @0x45f #57317 p0
8✅ cast python/paddle/tensor/manipulation.py @GreatV #57159 #57527 p0
9✅ add python/paddle/tensor/math.py @enkilee #57166 #57533 p0 余complex
10✅ multiply python/paddle/tensor/math.py @enkilee #57175 #57533 p0
11✅ pow python/paddle/tensor/math.py @gouzil #57297 p0
12✅ subtract python/paddle/tensor/math.py @YuanRisheng #57010 #57608 p0 余complex
13✅ erf python/paddle/tensor/ops.py @YuanRisheng #57340 p0
14✅ greater_equal python/paddle/tensor/logic.py @YuanRisheng #57340 p0
15✅ reshape python/paddle/tensor/manipulation.py @YuanRisheng #57340 p0
16✅ scale python/paddle/tensor/math.py @YuanRisheng #57340 p0
17✅ uniform python/paddle/tensor/random.py @changeyoung98 #57433 p0
18✅ concat python/paddle/tensor/manipulation.py @xiaoguoguo626807 #57333 p0
19✅ expand python/paddle/tensor/manipulation.py @xiaoguoguo626807 #57370 #57478 p0
20✅ embedding python/paddle/nn/functional/input.py @Aurelius84 #57360 p0
21✅ matmul python/paddle/tensor/linalg.py @enkilee #57277 p0
22✅ rsqrt python/paddle/tensor/ops.py @changeyoung98 #57325 p0
23✅ split python/paddle/tensor/manipulation.py @xiaoguoguo626807 #56873 p0
24✅ add_n python/paddle/tensor/math.py @xiaoguoguo626807 #56873 p0
25✅ tanh python/paddle/tensor/math.py @longranger2 #57248 p0
26✅ transpose python/paddle/tensor/linalg.py @longranger2 #57248 p0
27✅ softmax python/paddle/nn/functional/activation.py @Difers #57415 p1
28✅ rms_norm incubate/nn/functional/rms_norm.py @GreatV #57156 p1
29✅ silu python/paddle/nn/functional/activation.py @GreatV #57157 p1
30✅ exp python/paddle/tensor/ops.py @PommesPeter #57122 p1
31✅ reduce_max python/paddle/tensor/math.py @PommesPeter #57123 p1
32✅ bitwise_and python/paddle/tensor/logic.py @BeingGod #57677 p1
33✅ equal python/paddle/tensor/logic.py @BeingGod #57678 p1
34✅ full_like python/paddle/tensor/creation.py @xiaoguoguo626807 #56961 p1
35✅ gather_nd python/paddle/tensor/manipulation.py @zrr1999 #57562 #57640 p1
36✅ arange python/paddle/tensor/creation.py @BeingGod #57344 p1
37✅ shape python/paddle/tensor/attribute.py @huangjiyi #57330 p1
38✅ numel python/paddle/tensor/stat.py @huangjiyi #57330 p1
39✅ slice python/paddle/tensor/manipulation.py @huangjiyi #57341 #57529 p1
40✅ squeeze python/paddle/tensor/manipulation.py @YuanRisheng #57705 p1
41✅ stack python/paddle/tensor/manipulation.py @liyongchao911 #57477 p1
42✅ unsqueeze python/paddle/tensor/manipulation.py @longranger2 #57617 #57681 p1
43✅ where python/paddle/tensor/search.py @longranger2 #57667 p1
44✅ fill_any_like python/paddle/tensor/creation.py @xiaoguoguo626807 #56961 p1
45✅ pad python/paddle/nn/functional/common.py @BeingGod #57348 p1
46✅ tile python/paddle/tensor/manipulation.py @zrr1999 #57700 p1
47✅ tril python/paddle/tensor/creation.py @ccsuzzh #57393 p1
48✅ assign python/paddle/tensor/creation.py @YuanRisheng #57780 p0

其他算子任务:

序号 Python API 所在文件 贡献者 PR链接 优先级 单测覆盖率
1✅ fused_softmax_mask_upper_triangle softmax_mask_fuse_upper_triangle.py @Aurelius84 #57360 p0 2/2

二,任务详情

对Python API进行适配升级,实现在新IR模式下,在Python端调用底层C++端新 IR API。
以组网api mean举例:
升级前:

def mean(x, axis=None, keepdim=False, name=None):
    if in_dygraph_mode():
        # 动态图分支代码
        return _C_ops.mean(x, axis, keepdim)
    else:
        # 静态图分支代码,省略

升级后:

def mean(x, axis=None, keepdim=False, name=None):
    if in_dynamic_or_pir_mode():
        # 动态图 / 新IR分支代码
        return _C_ops.mean(x, axis, keepdim)   # <----- 动静统一
    else:
        # 静态图分支代码,省略

再比如concat:
升级前:

def concat(x, axis=0, name=None):
    input = x
    if in_dynamic_mode():
        # 动态图代码分支
        if isinstance(axis, Variable):
            axis = axis.item(0)
        if not isinstance(input, Variable):
            input = [t for t in input if t.shape.count(0) == 0]
        return _C_ops.concat(input, axis)
    else:
        # 静态图代码分支

升级后:

def concat(x, axis=0, name=None):
    input = x
    if in_dynamic_mode():
        # 动态图代码分支
        if isinstance(axis, Variable):
            axis = axis.item(0)
        if not isinstance(input, Variable):
            input = [t for t in input if t.shape.count(0) == 0]
        return _C_ops.concat(input, axis)
    elif in_pir_mode():
        # 新IR代码分支
        if not isinstance(input, paddle.ir.Value):
            input = [t for t in input if t.shape.count(0) == 0]
        return _C_ops.concat(input, axis)
    else:
        # 静态图代码分支

本任务中,需要关注的有三种模式判断:

# python/paddle/fluid/framework.py

in_dygraph_mode() #动态图模式下为True
in_pir_mode() #新IR模式下为True
in_dynamic_or_pir_mode() #动态图或者新IR模式下为True

为了提高Python端的代码复用,提升代码简洁性降低维护成本,我们对C++端新IR API和动态图API接口进行了统一。正如上述mean所示,_C_ops.mean可以表示在新IR或者动态图下的C++接口,所以为了能够在新IR模式下调用C++接口,只需要将in_dygraph_mode()改为in_dynamic_or_pir_mode()即可,这样就实现了Python端支持新IR API调用。但是在api concat当中,由于动态图中存在无法给新IR复用的代码,所以使用in_pir_mode()新开了一个分支。

三,单测验证

需要对api相关单测进行修改以进行验证,以mean为例,测试改api的单测在文件test_mean_op.py中,在单测函数中,加入check_new_ir=True,就实现对新IR下api的验证:

class TestMeanOp(OpTest):
    # 其他代码省略
    def test_check_output(self):
        self.check_output(check_new_ir=True)

    def test_checkout_grad(self):
        self.check_grad(['X'], 'Out', check_new_ir=True)

运行这个单测有俩种方式,任意一种跑通即可:
1,编译安装好paddle直接使用python命令执行单测文件
2,编译paddle后,在build目录下,使用命令ctest -R test_mean_op来运行
注1:由于当前新IR还处于机制完善和验证阶段,且单测验证框架也可能存在问题,所以遇到不容易解决的问题先记录到下边任务列表当中,由paddle团队来解决。
注2:为了确保新IR api推全的正确性,单测验证至少需要适配一个check_output()并跑通。

@YuanRisheng YuanRisheng added the PFCC Paddle Framework Contributor Club,https://github.com/PaddlePaddle/community/tree/master/pfcc label Sep 8, 2023
@enkilee
Copy link
Contributor

enkilee commented Sep 8, 2023

认领 12 13

@ccsuzzh
Copy link
Contributor

ccsuzzh commented Sep 8, 2023

认领 21

@Difers
Copy link
Contributor

Difers commented Sep 8, 2023

认领 5-8

@longranger2
Copy link
Contributor

认领40-44

@luotao1 luotao1 moved this to In Progress in Call for Contributions Sep 8, 2023
@luotao1 luotao1 added the HappyOpenSource 快乐开源活动issue与PR label Sep 8, 2023
@GreatV
Copy link
Contributor

GreatV commented Sep 8, 2023

认领 9, 10 ,11

@liyongchao911
Copy link
Contributor

认领38,39

@gouzil
Copy link
Member

gouzil commented Sep 8, 2023

认领14

@PommesPeter
Copy link
Contributor

认领 17,19

@huangjiyi
Copy link
Member

认领 33-35

@BeingGod
Copy link
Contributor

BeingGod commented Sep 8, 2023

认领17-20,22-23,25-26,31-32

@ranchongzhi
Copy link
Contributor

认领37

@jinyouzhi
Copy link
Contributor

认领30

@zrr1999
Copy link
Member

zrr1999 commented Sep 8, 2023

认领28

@BeingGod
Copy link
Contributor

认领45-48

@ccsuzzh
Copy link
Contributor

ccsuzzh commented Sep 14, 2023

认领 50

@BeingGod
Copy link
Contributor

BeingGod commented Sep 14, 2023

No.47 python/paddle/tensor/creation.py中未找到range,原意要表达的是否为arange?如果是arange,其已在任务列表中,可以移除。 @YuanRisheng @Aurelius84

@YuanRisheng
Copy link
Contributor Author

No.47 python/paddle/tensor/creation.py中未找到range,原意要表达的是否为arange?如果是arange,其已在任务列表中,可以移除。 @YuanRisheng @Aurelius84

谢谢,已移除

@YuanRisheng
Copy link
Contributor Author

@ranchongzhi 40题由于项目内部需求,需要尽快推进完成,我这边接手做了哈

@luotao1
Copy link
Contributor

luotao1 commented Sep 27, 2023

新 IR API 推全升级已全部完成,感谢参与的小伙伴们!

@GreatV @enkilee @gouzil @longranger2 @Difers @PommesPeter @BeingGod @zrr1999 @huangjiyi @liyongchao911 @ccsuzzh

欢迎继续参与快乐开源的其他任务!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
HappyOpenSource 快乐开源活动issue与PR PFCC Paddle Framework Contributor Club,https://github.com/PaddlePaddle/community/tree/master/pfcc status/close 已关闭
Projects
Development

No branches or pull requests