-
Notifications
You must be signed in to change notification settings - Fork 5.6k
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
c_softmax_with_cross_entropy support bf16 for xpu #60472
Merged
Merged
Changes from all commits
Commits
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
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 |
---|---|---|
|
@@ -21,6 +21,7 @@ | |
create_test_class, | ||
get_xpu_op_support_types, | ||
) | ||
from op_test import convert_uint16_to_float | ||
from test_collective_base_xpu import DataTypeCast, TestDistBase | ||
|
||
import paddle | ||
|
@@ -154,15 +155,30 @@ def check_with_place( | |
# get real result | ||
loss0, softmax0, logits_grad0 = tr0_out | ||
loss1, softmax1, logits_grad1 = tr1_out | ||
if dtype == "bfloat16": | ||
loss0 = convert_uint16_to_float(loss0) | ||
softmax0 = convert_uint16_to_float(softmax0) | ||
logits_grad0 = convert_uint16_to_float(logits_grad0) | ||
loss1 = convert_uint16_to_float(loss1) | ||
softmax1 = convert_uint16_to_float(softmax1) | ||
logits_grad1 = convert_uint16_to_float(logits_grad1) | ||
softmax = np.concatenate((softmax0, softmax1), axis=1) | ||
logits_grad = np.concatenate((logits_grad0, logits_grad1), axis=1) | ||
|
||
# compare results | ||
rtol = 1e-6 | ||
np.testing.assert_allclose(loss0, need_loss, rtol=rtol) | ||
np.testing.assert_allclose(loss1, need_loss, rtol=rtol) | ||
np.testing.assert_allclose(softmax, need_softmax, rtol=rtol) | ||
np.testing.assert_allclose(logits_grad, need_logits_grad, rtol=rtol) | ||
atol = 0 | ||
if dtype == "bfloat16": | ||
rtol = 0.1 | ||
atol = 0.1 | ||
np.testing.assert_allclose(loss0, need_loss, rtol=rtol, atol=atol) | ||
np.testing.assert_allclose(loss1, need_loss, rtol=rtol, atol=atol) | ||
np.testing.assert_allclose( | ||
softmax, need_softmax, rtol=rtol, atol=atol | ||
) | ||
np.testing.assert_allclose( | ||
logits_grad, need_logits_grad, rtol=rtol, atol=atol | ||
) | ||
|
||
|
||
support_types = get_xpu_op_support_types('c_softmax_with_cross_entropy') | ||
|
@@ -171,7 +187,7 @@ def check_with_place( | |
globals(), | ||
XPUTestCSoftmaxWithCEOP, | ||
stype, | ||
ignore_device_version=[core.XPUVersion.XPU1], | ||
ignore_device_version=[core.XPUVersion.XPU1, core.XPUVersion.XPU3], | ||
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. 这里把xpu3忽略是因为? 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 __name__ == '__main__': | ||
|
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.
diff设置成0.1是不是太大了?
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.
初始化数据范围[-40, 40],比较大,给0.01过不了