-
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] Fix scale kernel and perfect unit test #50998
Conversation
你的PR提交成功,感谢你对开源项目的贡献! |
class TestScaleFp16Op1(TestScaleOp): | ||
def init_dtype_type(self): | ||
self.dtype = np.float16 | ||
self.inputs = {'X': np.random.random((10, 20, 20)).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.
建议用uniform的形式替换random生成
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
def test_check_output(self): | ||
place = core.CUDAPlace(0) | ||
if core.is_float16_supported(place): | ||
self.check_output_with_place(place, atol=0.001, check_eager=True) |
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.
这里的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.
done
def init_dtype_type(self): | ||
self.dtype = np.float16 | ||
self.inputs = { | ||
'X': np.random.uniform(-10, 10, (10, 20, 20)).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.
random里面的给的参数是shape,范围是0-1的,uniform这个建议采用0,1为范围,shape与原测试保持一致
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
@@ -178,6 +178,22 @@ def test_check_grad(self): | |||
self.check_grad(['X'], 'Out', numeric_grad_delta=0.8, check_eager=True) | |||
|
|||
|
|||
class TestScaleFp16Op1(TestScaleOp): |
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.
这里上面就有FP16的测试,直接改那个就可以
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
@@ -41,6 +41,28 @@ struct ScaleFunctor { | |||
} | |||
}; | |||
|
|||
struct ScaleFunctorFp16 { |
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.
可以重写下ScaleFunctor,增加一个模版参数,表示scale和bias的数据类型,如下
template <typename DataT, typename ParamT>
struct ScaleFunctor {}
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
改下PR Title和PR描述 |
@@ -149,15 +149,12 @@ def init_dtype_type(self): | |||
|
|||
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.
你这个不能都删掉,至少得运行一下self.check_output
@@ -149,15 +149,12 @@ def init_dtype_type(self): | |||
|
|||
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.
这行删
place, ["X"], "Out", max_relative_error=0.05, check_eager=True | ||
) | ||
self.check_grad_with_place( | ||
place, ["X"], "Out", max_relative_error=0.001, check_eager=True |
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.check_grad
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.
已修改,位置在#51083
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
* Fix scale kernel for low precision, cherry pick #50998. * Fix the FP16 precision problem of add_n. (#50129) * Change squared_l2_norm to reuse ReduceKernel, and register fp16 and bf16 kernel, which is cherry pick #48315. * Cherry-pick the fix of MPTypeTrait in KP, which is implemented in #50993. * Cherry-pick the multi-precision support of AdamW for bf16, #48041. * Fix compiling error. * Cherry-pick the fix of CubTensorReduceImpl for bfloat16 in #50993. * Fix unittest. --------- Co-authored-by: liuruyan <44316842+liuruyan@users.noreply.github.com>
PR types
Others
PR changes
Others
Describe
修复scale fp16和bf16的精度损失问题,精简scale fp16 单测