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

[PIR] Refine op yaml system #59364

Merged
merged 14 commits into from
Nov 28, 2023

Conversation

zhangbo9674
Copy link
Contributor

@zhangbo9674 zhangbo9674 commented Nov 25, 2023

PR types

New features

PR changes

Others

Description

本 PR 对 PIR 的算子 yaml 定义开展了系统的重构:

1、当前 PIR 算子 yaml 定义体系及存在的问题:

目前 PIR 的算子定义分布在 6 个 yaml 文件中(不区分前反向),包括:

  • phi/ops.yaml:旧 Program 体系下,动静一致的算子定义
  • phi/fused_ops.yaml:旧 Program 体系下,动静一致的fuse算子定义
  • phi/sparse_ops.yaml:旧 Program 体系下,动静一致的sparse算子定义
  • phi/legacy_ops.yaml:旧 Program 体系下,动态图的算子定义
  • pir/dialect/ops.yaml: PIR 独有的算子定义
  • pir/dialect/update_ops.yaml:面向3.0定义,最终态的 PIR 算子定义

当前存在问题包括:

  • 对于用户或开发者来说,查找一个算子的定义很麻烦
  • 复用动态图 legacy_ops.yaml 定义PIR 的算子,导致一些当前动静不统一的算子,在 PIR 下的定义与旧 Program 定义不一致
  • 新增算子定义的位置界定不清晰,如何确定定义到哪个 yaml 中?

基于上述问题,我们对 PIR 的算子 yaml 进行了如下的规范:

2、重构后算子 yaml 定义体系:

将 phi/legacy_ops.yaml 定义的算子移动到 pir/dialect/ops.yaml,由此,PIR下算子定义包括:

  • 动静一致的算子定义:phi/ops.yaml、phi/fused_ops.yaml、phi/sparse_ops.yaml
  • 动静不一致的算子:
    • PIR 独有的算子:pir/dialect/ops.yaml(动态图不需要定义,最终该类算子也会持续存放在该文件)
    • 动静不一致,但尚未确定最终定义的算子:pir/dialect/ops.yaml(未确定终态前,根据静态图的需求暂存在该文件中,完成动静统一后,迁移到 phi/ops.yaml)
  • 面向3.0升级定义的算子:pir/dialect/update_ops.yaml:在动态图未同步升级前,存放于该文件,待动态图同步升级后,迁移到 phi/ops.yaml 中

image

3、PIR 下,参照如下流程图完成算子定义位置的确定:

image

Pcard-67164

Copy link

paddle-bot bot commented Nov 25, 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.

Copy link
Contributor

@Aurelius84 Aurelius84 left a comment

Choose a reason for hiding this comment

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

LGTM


IrSelectedRows::IrSelectedRows(const IrSelectedRows& other) {
dims_ = other.dims();
dtype_ = other.dtype();
Copy link
Contributor

Choose a reason for hiding this comment

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

下面这几个构造函数是不是都可以用=default 就可以了。因为成员里没有指针对象,默认的应该够用?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

感谢建议,单独 pr 完善一下~

return *this;
}

int64_t IrSelectedRows::numel() const { return phi::product(dims_); }
Copy link
Contributor

Choose a reason for hiding this comment

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

这里会出现 [128, 3, -1, -1]的场景么?或者说这里的ddim都是非负数了已经

Copy link
Contributor Author

@zhangbo9674 zhangbo9674 Nov 27, 2023

Choose a reason for hiding this comment

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

可能会出现,IrTensor 和 IrSelectRows 仅会PIR组网的 infer meta 阶段使用,全局搜索了一下框架目前所有的 infer_meta 函数,共有2个使用到 numel 的地方:NanmedianInferMeta、FullWithTensorInferMeta,但这两个函数并未对这种情况做处理。目前执行未发现错误应该是因为执行期间还会执行一次 infer_meta.
后续我单独 pr 对IrTensor 和 IrSelectRows 的 numel 接口进行完善,在存在-1的情况下返回-1,此外再对NanmedianInferMeta、FullWithTensorInferMeta 这两个 infer_meta 的实现进行完善

Copy link
Contributor

@cyber-pioneer cyber-pioneer left a comment

Choose a reason for hiding this comment

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

approve for key composite

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

@zhangbo9674 zhangbo9674 merged commit 7896c17 into PaddlePaddle:develop Nov 28, 2023
28 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants