-
Notifications
You must be signed in to change notification settings - Fork 688
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
optimize prelu alpha grad #7600
Merged
Merged
Changes from 1 commit
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
c5bbb6c
optimize prelu alpha grad
Flowingsun007 516523a
refine
Flowingsun007 d5c4f86
refine
Flowingsun007 de22832
refine
Flowingsun007 d854e5f
Merge branch 'master' into dev_optinal_prelu_alpha_grad
Flowingsun007 bd33885
Merge branch 'master' into dev_optinal_prelu_alpha_grad
Flowingsun007 a310b9c
Merge branch 'master' into dev_optinal_prelu_alpha_grad
Flowingsun007 513a456
auto format by CI
oneflow-ci-bot d9a2fc5
refine
Flowingsun007 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -380,6 +380,7 @@ class GpuPReluGradKernel final : public user_op::OpKernel { | |
user_op::Tensor* dx = ctx->Tensor4ArgNameAndIndex("dx", 0); | ||
user_op::Tensor* alpha_diff = ctx->Tensor4ArgNameAndIndex("alpha_diff", 0); | ||
user_op::Tensor* tmp_buffer = ctx->Tensor4ArgNameAndIndex("tmp_buffer", 0); | ||
const bool alpha_requires_grad = ctx->Attr<bool>("alpha_requires_grad"); | ||
const int32_t elem_cnt = x->shape().elem_cnt(); | ||
T* broadcasted_alpha_diff = tmp_buffer->mut_dptr<T>(); | ||
T* reduce_sum_tmp_buf = reinterpret_cast<T*>(tmp_buffer->mut_dptr<char>() | ||
|
@@ -400,10 +401,12 @@ class GpuPReluGradKernel final : public user_op::OpKernel { | |
alpha->dptr<T>(), dy->dptr<T>(), dx->mut_dptr<T>(), | ||
broadcasted_alpha_diff); | ||
} | ||
NdarrayUtil<DeviceType::kCUDA, T>::ReduceSum( | ||
if(alpha_requires_grad){ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 这个if应该放到386行,并且如果alpha不需要grad的话,底下不需要申请tmp_buffer |
||
NdarrayUtil<DeviceType::kCUDA, T>::ReduceSum( | ||
ctx->stream(), XpuVarNdarray<T>(left_extended_shape, alpha_diff->mut_dptr<T>()), | ||
XpuVarNdarray<const T>(x->shape(), broadcasted_alpha_diff), | ||
XpuVarNdarray<T>(x->shape(), reduce_sum_tmp_buf)); | ||
} | ||
} | ||
bool AlwaysComputeWhenAllOutputsEmpty() const override { return false; } | ||
}; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
broadcasted_alpha_diff 也不应该算,可以在cuda kernel中处理一下不写broadcasted_alpha_diff的情况
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
好的
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
已修改