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] Reconstruct the Verify system #58052

Merged
merged 9 commits into from
Oct 13, 2023

Conversation

zhangbo9674
Copy link
Contributor

@zhangbo9674 zhangbo9674 commented Oct 12, 2023

PR types

New features

PR changes

Others

Description

针对多 region 场景,重构 PIR 的 Verify 体系,重构背景如下:

  • 在设计控制流算子的时候,我们发现原本的Verify 体系只是检验算子的输入、输出、属性(算子签名),如果该算子存在子 region,Verify 并不会递归的去校验,例如 IfOp 就存在两个子 region。
  • 除上面这个问题,另外一个问题就是对于存在子 region 的算子,其子 region 的构造通常是在 IfOp 的 Operation::Create 之后,再去初始化的,但是目前的 Verify 是在 Operation::Create 函数的末尾自动构造的,这会导致原本的 Verify 体系是不支持校验这种子 region 的。

重构前后 Verify 体系的变化:
image

重构后,算子的校验将分为两个维度:Verify = VerifySig + VerifyRegion

  • VerifySig 仅用于校验是否符合算子签名,即仅对输入、输出、属性进行校验;
  • VerifyRegion 用于对子 Region 进行校验,(默认的校验为空,若没有子 region,用户无需手动注册该函数);

应用方法:

  • 对于含有子 reigon 的算子,用户在完成算子的构造后(包括子 Region 的构造),使用 class Operation 提供的 Verify 函数进行校验:该函数会通过 OpInfo 体系自动调用到底层算子定义的 VerifySig + VerifyRegion;
  • 对于不含子 region 的算子,构造后无需手动调用 Verify 函数:由于 Operation::Create 函数仅用于构造算子自身,并不会递归的对子 Region 进行构造,因此本函数会默认调用 VerifySig 进行检查。

Pcard-67164

@paddle-bot
Copy link

paddle-bot bot commented Oct 12, 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.

void IfOp::Verify() {}
void IfOp::Verify() {
if ((*this)->region(0).empty() && (*this)->region(1).empty()) {
LOG(WARNING)
Copy link
Contributor

Choose a reason for hiding this comment

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

现在operation::create里面是调用了verify函数的。而create的时候,region都是空的。也就是说这个warning是一定会进入的。

return;
}

PADDLE_ENFORCE_EQ(
Copy link
Contributor

Choose a reason for hiding this comment

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

true_region和false_region的size可以不相等。
true_region的size一定等于1。 如果输入为空,false_region的size可以为0, 否则,一定为1;

@zhangbo9674 zhangbo9674 changed the title [PIR] Refine verify of if op [PIR] Reconstruct the Verify system Oct 13, 2023
winter-wang
winter-wang previously approved these changes Oct 13, 2023
Copy link
Contributor

@winter-wang winter-wang 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

@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 52b86df into PaddlePaddle:develop Oct 13, 2023
28 checks passed
Frida-a pushed a commit to Frida-a/Paddle that referenced this pull request Oct 14, 2023
* refine verify of if op

* fix

* fix

* fix

* refine

* fix

* fix

* fix

* fix
jiahy0825 pushed a commit to jiahy0825/Paddle that referenced this pull request Oct 16, 2023
* refine verify of if op

* fix

* fix

* fix

* refine

* fix

* fix

* fix

* fix
danleifeng pushed a commit to danleifeng/Paddle that referenced this pull request Nov 14, 2023
* refine verify of if op

* fix

* fix

* fix

* refine

* fix

* fix

* fix

* fix
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.

3 participants