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] Mark ShareData as an inplace OP and fix inplace pass #64195

Merged

Conversation

SigureMo
Copy link
Member

@SigureMo SigureMo commented May 10, 2024

PR Category

Execute Infrastructure

PR Types

Bug fixes

Description

修改 ShareData 为一个 inplace OP,否则 Inplace Pass 识别不到 ShareData 的写语义,导致错误地将一个 OP 转为 inplace 的,导致输入错误被更新(比如单测里的 u 被错误更新了)

目前 Inplace Pass 处理的是有 bug 的,进而没有正确处理上面的情况,因此修改 inplace 判断策略

inplace-pass drawio

对于一个待替换的 OP b 来说(黄色 ac 已经遍历过,绿色 b 正在遍历,蓝色 df 待遍历),最多可能的情况如图所示,但如果 OP d 存在,那么不会在 b 进行 inplace,因为不是 eager deletion op

我们会在遍历时维护一个 use_count_map 和一个 inplace_map,前者用于表示各个 Value 当前的引用计数(初始是 Value.use_count(),之后会逐渐递减),只有自身 use_count 为 0 且相应的 inplace Value use_count 也为 0 的情况才能将该 OP inplace

cc @HydrogenSulfate

PCard-66972

Copy link

paddle-bot bot commented May 10, 2024

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

Aurelius84
Aurelius84 previously approved these changes May 14, 2024
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.

Greate work!

@SigureMo SigureMo changed the title [PIR] Mark ShareData as an inplace OP [PIR] Mark ShareData as an inplace OP and fix inplace pass May 14, 2024
@@ -67,6 +67,19 @@ bool CanBeDeleted(pir::Value value) {
return !(persist_attr && persist_attr.data());
}

bool HasNotUser(const pir::Value& value,
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
bool HasNotUser(const pir::Value& value,
bool IsLastestUser(const pir::Value& value,

Copy link
Contributor

Choose a reason for hiding this comment

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

这个函数名字感觉含义不是很清楚,是不是换成 IsLastestUser 更明确一点

Copy link
Member Author

Choose a reason for hiding this comment

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

好的,下个 PR 优化下~

Copy link
Contributor

Choose a reason for hiding this comment

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

好的,下个 PR 优化下~

是Latest不是Lastest

Copy link
Member Author

Choose a reason for hiding this comment

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

是Latest不是Lastest

不说还没注意 😂,不过这里语义应该是 Last,已在 #64317 修改

Copy link
Contributor

@zhangbo9674 zhangbo9674 left a comment

Choose a reason for hiding this comment

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

LGTM overrall

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

@SigureMo SigureMo merged commit 4bedcd0 into PaddlePaddle:develop May 15, 2024
31 checks passed
@SigureMo SigureMo deleted the pir/mark-share-data-op-as-inplace branch May 15, 2024 03:38
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.

None yet

6 participants