-
Notifications
You must be signed in to change notification settings - Fork 5.7k
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
【AMP OP&Test】instance_norm fp16 and bf16 support. #52241
Conversation
你的PR提交成功,感谢你对开源项目的贡献! |
4027894
to
134fbcc
Compare
const T *x, | ||
const BatchNormParamType<T> *variance, | ||
const BatchNormParamType<AccT> *variance, |
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.
可以看下BatchNormParamType的定义,这里不需要再使用AccT,直接用T就可以,BatchNormParamType(T==fp16orbf16)就是float了
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.
fix it.
self.bias = np.random.random([self.shape[1]]).astype(np.float32) | ||
|
||
def set_err_thre(self): | ||
self.atol = 1e-3 |
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.
fp32的误差阈值就需要这么大嘛
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.
试了1e-4不通过,就还是保持1e-3吧?
self.max_relative_error = 1e-2 | ||
self.inputs = { | ||
'X': convert_float_to_uint16(self.value), | ||
'Scale': convert_float_to_uint16(self.scale), |
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.
bf16这里的scale和bias应该也不需要convert吧
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.
fix it.
return x_norm, mean.reshape(N * C), std.reshape(N * C) | ||
|
||
def test_check_output(self): | ||
place = core.CUDAPlace(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.
这里需要判断下是否编译的是GPU版本,或者直接调用check_output,然后下面bf16的重写一下
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.
fix it.
|
||
def set_err_thre(self): | ||
self.atol = 0.03125 | ||
self.max_relative_error = 8e-3 |
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.
是的
self.init_dtype() | ||
self.init_shape() | ||
self.init_value() | ||
self.atol = 1e-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.
bf16默认值为1e-2,无需设置
@@ -22,6 +22,11 @@ | |||
#include "paddle/phi/kernels/funcs/norm_utils.h" | |||
#include "paddle/phi/kernels/gpu/instance_norm_utils.h" | |||
|
|||
#include "paddle/phi/common/bfloat16.h" | |||
#include "paddle/phi/common/data_type.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.
删除无用头文件,data_type.h应该包含了bfloat16和float16,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.
删除了引用 data_type.h and device_context.h.
@@ -22,8 +22,13 @@ | |||
#include "paddle/phi/kernels/funcs/norm_utils.h" | |||
#include "paddle/phi/kernels/gpu/instance_norm_utils.h" | |||
|
|||
#include "paddle/phi/common/bfloat16.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.
删除无用头文件
|
||
def init_value(self): | ||
np.random.seed(0) | ||
self.value = np.random.random(self.shape).astype(self.dtype) |
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.
这里对于bf16应该是初始化为fp32,然后convert
self.python_api = instance_norm_warpper | ||
self.eps = 1e-5 | ||
self.data_format = "NCHW" | ||
self.init_dtype() |
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.
bf16的单测并没有对init_dtype重写,所以当前还是dtype还是float32
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
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
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
PR types
Others
PR changes
OPs
Describe