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] add stop_gradient attribute for defining op #55235

Merged
merged 3 commits into from
Jul 10, 2023

Conversation

kangguangli
Copy link
Contributor

PR types

New features

PR changes

Others

Description

After this op, the attribute stop_attribute of VarDesc will be introduced as the attribute of the defining op of the corresponding value.
The operation will be like:

(%432, %433, %434, %435, %436, %437) = "pd.batch_norm" (%431, %2, %4, %3, %1) {stop_gradient:array[0,1,1,1,1,1],trainable_statistics:0,use_global_stats:0,data_layout:NCHW,epsilon:1e-05,momentum:0.9,is_test:0} : (tensor<-1x64x112x112xf32>, tensor<64xf32>, tensor<64xf32>, tensor<64xf32>, tensor<64xf32>) -> tensor<-1x64x112x112xf32>, tensor<64xf32>, tensor<64xf32>, tensor<64xf32>, tensor<64xf32>, tensor<-1xf32>
(%438) = "pd.relu" (%432) {stop_gradient:array[0]} : (tensor<-1x64x112x112xf32>) -> tensor<-1x64x112x112xf32>

However, it should be noted that not all operation will have a stop_attribute currently.

Others

Pcard-67164

@paddle-bot
Copy link

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

@kangguangli kangguangli requested a review from winter-wang July 7, 2023 07:19
@@ -68,6 +68,14 @@ class IR_API alignas(8) Operation final {
attributes_[key] = value;
}

Attribute GetAttribute(const std::string &key) const {
Copy link
Contributor

Choose a reason for hiding this comment

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

这个函数名直接用attribute就行吧。

Copy link
Contributor Author

Choose a reason for hiding this comment

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

那其他两个接口需要换成set_attribute和has_attribute吗?

Copy link
Contributor

Choose a reason for hiding this comment

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

可以顺便把SetAttribute接口也重命名为 set_attribute。

@@ -68,6 +68,14 @@ class IR_API alignas(8) Operation final {
attributes_[key] = value;
}

Attribute GetAttribute(const std::string &key) const {
return attributes_.at(key);
Copy link
Contributor

Choose a reason for hiding this comment

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

是不是可以加一个判断有无的检查?

Copy link
Contributor

Choose a reason for hiding this comment

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

at好像已经带越界检查了。

Copy link
Contributor Author

Choose a reason for hiding this comment

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

可以,我改成用ir_enforce判断一下吧,但是这样感觉和HasAttribute就有点重叠了。使用的时候一般要先用has_attribute判断,在这里再判断下就会判断两次。

Copy link
Contributor Author

Choose a reason for hiding this comment

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

at好像已经带越界检查了。

但是at的报错提示不太友好

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

@kangguangli kangguangli merged commit c5a191b into PaddlePaddle:develop Jul 10, 2023
@kangguangli kangguangli deleted the add_vardesc_attribute branch July 10, 2023 12:00
cqulilujia pushed a commit to cqulilujia/Paddle that referenced this pull request Jul 24, 2023
* add stop_gradient attribute for defining op

* modify by reviews

* fix
wz1qqx pushed a commit to wz1qqx/Paddle that referenced this pull request Jul 31, 2023
* add stop_gradient attribute for defining op

* modify by reviews

* 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