-
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
Move layer norm to phi #40193
Move layer norm to phi #40193
Conversation
… move_layer_norm_to_phi
Thanks for your contribution! |
… move_layer_norm_to_phi
… move_layer_norm_to_phi
… move_layer_norm_to_phi
@@ -264,6 +264,7 @@ struct TestFusedLayernormResidualDropoutBias { | |||
|
|||
template <typename T> | |||
static void BaseTest(const bool is_fp16 = false) { | |||
std::cerr << "1" << std::endl; |
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.
done
@@ -14,6 +14,7 @@ limitations under the License. */ | |||
|
|||
#include <time.h> | |||
|
|||
#include <iostream> |
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.
done
DenseTensor temp_norm; | ||
if (d_scale || d_x) { | ||
x_tmp.Resize(matrix_shape); | ||
temp.mutable_data<T>(matrix_shape, dev_ctx.GetPlace()); |
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.
用 dev_ctx.template Alloc() 替换 mutable_data
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.
done
x_tmp.Resize(matrix_shape); | ||
temp.mutable_data<T>(matrix_shape, dev_ctx.GetPlace()); | ||
|
||
temp_norm.mutable_data<T>(matrix_shape, dev_ctx.GetPlace()); |
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.
同上
} | ||
|
||
if (d_bias) { | ||
d_bias->mutable_data<T>(dev_ctx.GetPlace()); |
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.
done
colwise_sum(dev_ctx, d_y, d_bias); | ||
} | ||
if (d_scale) { | ||
d_scale->mutable_data<T>(dev_ctx.GetPlace()); |
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.
done
auto dx_dim = d_x->dims(); | ||
DenseTensor temp_vec; | ||
temp_vec.mutable_data<T>(vec_shape, dev_ctx.GetPlace()); | ||
|
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.
还有这的2处
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.
done
|
||
y->mutable_data<T>(dev_ctx.GetPlace()); | ||
mean->mutable_data<T>(dev_ctx.GetPlace()); | ||
var->mutable_data<T>(dev_ctx.GetPlace()); |
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.
done
|
||
#include "paddle/phi/backends/cpu/cpu_context.h" | ||
#include "paddle/phi/backends/gpu/gpu_context.h" | ||
#include "paddle/phi/core/device_context.h" |
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.
done
@@ -215,6 +215,8 @@ def test_with_place(place, | |||
for name in ['x', 'scale', 'bias', 'y@GRAD'] | |||
}, | |||
fetch_list=fetch_list) | |||
# print(y) | |||
# print(out[0]) |
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.
done
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.
注释删一下
@@ -229,6 +231,7 @@ def test_with_place(place, | |||
"bias_grad") | |||
|
|||
places = [core.CPUPlace()] | |||
places = [] |
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.
done
// 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); |
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.
可以尝试使用Copy kernel替换TensorCopy
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.
done
&temp); | ||
} else { | ||
// dy_dx | ||
paddle::framework::TensorCopy(d_y, dev_ctx.GetPlace(), dev_ctx, d_x); |
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.
done
#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" |
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.
layer_norm_grad_kernel.h放在开头
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.
done
auto *var_data = variance.data<U>(); | ||
|
||
auto *d_x_data = | ||
(d_x == nullptr ? nullptr : d_x->mutable_data<T>(dev_ctx.GetPlace())); |
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.
dev_ctx. Alloc
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.
done
#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" |
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.
layer_norm_kernel.h放在开头
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.
done
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.
done
|
||
#pragma once | ||
|
||
#include "paddle/phi/api/include/tensor.h" |
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.
"paddle/phi/api/include/tensor.h" 引用可以去掉
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.
这是因为下面有一个函数使用了stream_t
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.
gpuStream_t在paddle/phi/backends/gpu/gpu_declas.h中,phi core,kernels等目录中不能include api目录下的文件
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.
done
… 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
# print(y) | ||
# print(out[0]) |
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.
[TODO] 后续删除
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.
LGTM
* 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
PR types
Breaking changes
PR changes
OPs
Describe
move layer norm to phi