-
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
[XPU][Phi Kernel] xpu::nonzero support simulator XPUSIM_SKIP_RUN mode #60388
Merged
QingshuChen
merged 1 commit into
PaddlePaddle:develop
from
dynamicheart:xpu_nonzero_simulator_skip_run_mode
Dec 29, 2023
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -46,9 +46,8 @@ void NonZeroKernel(const Context& dev_ctx, | |
std::strcmp(std::getenv("XPUSIM_SKIP_RUN"), "1") == 0) { | ||
VLOG(3) << "WARNING: In the simulator mode, the variable true_num_cpu " | ||
"stores an uninitialized value. To avoid allocating a memory of " | ||
"random size, we limit the value of true_num_cpu to the range 0 " | ||
"<= true_num_cpu < numel"; | ||
true_num_cpu = std::min(std::max(true_num_cpu, 0), static_cast<int>(numel)); | ||
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. 某些case下会被设为0,后续的模型代码可能会报错,因此还是将其设为最大值。单测在这个PR里面:#60224 |
||
"random size, we assign numel to true_num_cpu"; | ||
true_num_cpu = numel; | ||
} | ||
|
||
out->Resize(common::make_ddim({static_cast<int64_t>(true_num_cpu), rank})); | ||
|
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 |
---|---|---|
|
@@ -16,6 +16,8 @@ | |
|
||
#include "paddle/phi/kernels/sigmoid_cross_entropy_with_logits_grad_kernel.h" | ||
|
||
#include "glog/logging.h" | ||
|
||
#include "paddle/phi/backends/xpu/enforce_xpu.h" | ||
#include "paddle/phi/backends/xpu/xpu_context.h" | ||
#include "paddle/phi/core/kernel_registry.h" | ||
|
@@ -79,6 +81,14 @@ void SigmoidCrossEntropyWithLogitsGradKernel( | |
dev_ctx.GetPlace(), | ||
static_cast<void*>(non_zero), | ||
sizeof(int)); | ||
if (std::getenv("XPUSIM_SKIP_RUN") && | ||
std::strcmp(std::getenv("XPUSIM_SKIP_RUN"), "1") == 0) { | ||
VLOG(3) | ||
<< "WARNING: In the simulator mode, the variable non_zero_cpu " | ||
"stores an uninitialized value. To avoid allocating a memory of " | ||
"random size, we assign numel to true_num_cpu"; | ||
non_zero_cpu = x.numel(); | ||
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.
|
||
} | ||
r = xpu::scale(dev_ctx.x_context(), | ||
reinterpret_cast<const XPUType*>(in_grad->data<T>()), | ||
reinterpret_cast<XPUType*>(in_grad->data<T>()), | ||
|
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
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.
写死最大对后续算子的影响还需要实际跑模型的时候再评估下
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.
性能倒是其次,有可能会影响算子规模
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.
skip_run拿不到不出来真实规模,也可能每个step对应的nonzero_count相关算子的规模也不一样
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.
好的