Move layer norm to phi#40193
Merged
phlrain merged 26 commits intoPaddlePaddle:developfrom Mar 17, 2022
Merged
Conversation
|
Thanks for your contribution! |
… move_layer_norm_to_phi
… move_layer_norm_to_phi
… move_layer_norm_to_phi
|
|
||
| template <typename T> | ||
| static void BaseTest(const bool is_fp16 = false) { | ||
| std::cerr << "1" << std::endl; |
|
|
||
| #include <time.h> | ||
|
|
||
| #include <iostream> |
Contributor
There was a problem hiding this comment.
下边的调试信息删除了,这里也要删除
| DenseTensor temp_norm; | ||
| if (d_scale || d_x) { | ||
| x_tmp.Resize(matrix_shape); | ||
| temp.mutable_data<T>(matrix_shape, dev_ctx.GetPlace()); |
Contributor
There was a problem hiding this comment.
用 dev_ctx.template Alloc() 替换 mutable_data
| x_tmp.Resize(matrix_shape); | ||
| temp.mutable_data<T>(matrix_shape, dev_ctx.GetPlace()); | ||
|
|
||
| temp_norm.mutable_data<T>(matrix_shape, dev_ctx.GetPlace()); |
| } | ||
|
|
||
| if (d_bias) { | ||
| d_bias->mutable_data<T>(dev_ctx.GetPlace()); |
| colwise_sum(dev_ctx, d_y, d_bias); | ||
| } | ||
| if (d_scale) { | ||
| d_scale->mutable_data<T>(dev_ctx.GetPlace()); |
| auto dx_dim = d_x->dims(); | ||
| DenseTensor temp_vec; | ||
| temp_vec.mutable_data<T>(vec_shape, dev_ctx.GetPlace()); | ||
|
|
|
|
||
| y->mutable_data<T>(dev_ctx.GetPlace()); | ||
| mean->mutable_data<T>(dev_ctx.GetPlace()); | ||
| var->mutable_data<T>(dev_ctx.GetPlace()); |
|
|
||
| #include "paddle/phi/backends/cpu/cpu_context.h" | ||
| #include "paddle/phi/backends/gpu/gpu_context.h" | ||
| #include "paddle/phi/core/device_context.h" |
| }, | ||
| fetch_list=fetch_list) | ||
| # print(y) | ||
| # print(out[0]) |
| "bias_grad") | ||
|
|
||
| places = [core.CPUPlace()] | ||
| places = [] |
zyfncg
reviewed
Mar 11, 2022
| // dy_dx | ||
| phi::funcs::ElementwiseCompute<funcs::MultiplyFunctor<T>, T, T>( | ||
| dev_ctx, d_y, *scale, /*axis*/ 1, funcs::MultiplyFunctor<T>(), &temp); | ||
| paddle::framework::TensorCopy(temp, dev_ctx.GetPlace(), dev_ctx, d_x); |
Contributor
There was a problem hiding this comment.
可以尝试使用Copy kernel替换TensorCopy
| &temp); | ||
| } else { | ||
| // dy_dx | ||
| paddle::framework::TensorCopy(d_y, dev_ctx.GetPlace(), dev_ctx, d_x); |
| #include "paddle/phi/backends/gpu/gpu_context.h" | ||
| #include "paddle/phi/core/kernel_registry.h" | ||
| #include "paddle/phi/kernels/funcs/layer_norm_util.h" | ||
| #include "paddle/phi/kernels/layer_norm_grad_kernel.h" |
Contributor
There was a problem hiding this comment.
layer_norm_grad_kernel.h放在开头
| auto *var_data = variance.data<U>(); | ||
|
|
||
| auto *d_x_data = | ||
| (d_x == nullptr ? nullptr : d_x->mutable_data<T>(dev_ctx.GetPlace())); |
| #include "paddle/phi/backends/gpu/gpu_context.h" | ||
| #include "paddle/phi/core/kernel_registry.h" | ||
| #include "paddle/phi/kernels/funcs/layer_norm_util.h" | ||
| #include "paddle/phi/kernels/layer_norm_kernel.h" |
|
|
||
| #pragma once | ||
|
|
||
| #include "paddle/phi/api/include/tensor.h" |
Contributor
There was a problem hiding this comment.
"paddle/phi/api/include/tensor.h" 引用可以去掉
Collaborator
Author
There was a problem hiding this comment.
这是因为下面有一个函数使用了stream_t
Contributor
There was a problem hiding this comment.
gpuStream_t在paddle/phi/backends/gpu/gpu_declas.h中,phi core,kernels等目录中不能include api目录下的文件
… move_layer_norm_to_phi
… move_layer_norm_to_phi
… move_layer_norm_to_phi
… move_layer_norm_to_phi
… move_layer_norm_to_phi
… move_layer_norm_to_phi
… move_layer_norm_to_phi
zyfncg
approved these changes
Mar 17, 2022
Comment on lines
+218
to
+219
| # print(y) | ||
| # print(out[0]) |
liqitong-a
pushed a commit
to liqitong-a/Paddle
that referenced
this pull request
Mar 17, 2022
* update * fix bugs; test=develop * update; test=develop * fix test compile error; test=develop * fix cpu compile error; test=develop * fix test error; test=develo * fix layer_norm_op plugin error; test=develop * fix error; test=develop * fix test bug; test=develop * update; test=develop * polish code; test=develop * fix bugs; test=develop * remove unused depency; test=develop * polish code; test=develop
This file contains hidden or 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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
PR types
Breaking changes
PR changes
OPs
Describe
move layer norm to phi