Skip to content
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] arange op support fp16/bf16 #51106

Merged
merged 18 commits into from
Mar 9, 2023
Merged

[AMP OP&Test] arange op support fp16/bf16 #51106

merged 18 commits into from
Mar 9, 2023

Conversation

yangjianfengo1
Copy link
Contributor

@yangjianfengo1 yangjianfengo1 commented Mar 2, 2023

PR types

Others

PR changes

OPs

Describe

增加了单测

@paddle-bot
Copy link

paddle-bot bot commented Mar 2, 2023

你的PR提交成功,感谢你对开源项目的贡献!
请关注后续CI自动化测试结果,详情请参考Paddle-CI手册
Your PR has been submitted. Thanks for your contribution!
Please wait for the result of CI firstly. See Paddle CI Manual for details.

@paddle-bot
Copy link

paddle-bot bot commented Mar 2, 2023

❌ The PR is not created using PR's template. You can refer to this Demo.
Please use PR's template, it helps save our maintainers' time so that more developers get helped.

@CLAassistant
Copy link

CLAassistant commented Mar 2, 2023

CLA assistant check
All committers have signed the CLA.

@CLAassistant
Copy link

CLA assistant check
Thank you for your submission! We really appreciate it. Like many open source projects, we ask that you sign our Contributor License Agreement before we can accept your contribution.
You have signed the CLA already but the status is still pending? Let us recheck it.

self.case = (0, 5, 1)

def test_check_output(self):
self.check_output(atol=1e-3)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这个地方1e-3现在可以去掉了,内部已修改了默认值


namespace phi {

template <typename T>
__global__ void Range(T start, T step, int64_t size, T* out) {
CUDA_KERNEL_LOOP(index, size) { out[index] = start + step * index; }
using MPType = typename phi::dtype::MPTypeTrait<T>::Type;
CUDA_KERNEL_LOOP(index, size) { out[index] = static_cast<T>(static_cast<MPType>(start) + static_cast<MPType>(step) * index); }
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

start和step是在计算中是固定的值,可以在计算前做static_cast成一个临时变量

@@ -39,7 +45,8 @@ void ArangeKernel(const Context& dev_ctx,
T step_value = GetValue<T, Context>(dev_ctx, step);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

建议直接在这里拿到start、end、step的时候直接转成MPType,后续都使用MPType的值去计算

@@ -1,4 +1,4 @@
# Copyright (c) 2020 PaddlePaddle Authors. All Rights Reserved.
# Copyright (c) 2020 PaddlePaddle Authors. All Rights Reserved.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这里其实不用修改,但是如果改了就把2020改成2023吧

or not core.is_bfloat16_supported(core.CUDAPlace(0)),
"core is not compiled with CUDA and not support the bfloat16",
)
def test_check_output(self):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

修改输入输出这部分不建议写在test_check_output中,建议直接继承OpTest重写setUp,其他参考TestArangeOp写就行

self.outputs = {
'Out': convert_float_to_uint16(np.arange(self.case[0], self.case[1], self.case[2]))
}
self.check_output(atol=1e-2)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这个后面也会改成默认值,这里可以不写

@yangjianfengo1
Copy link
Contributor Author

@xiegegege Performance of model ResNet50_bs32_dygraph has been increased from 248.402 to 480.483,(480.483-248.402)/248.402 equals 0.9343,which is greater than threshold 0.06

@yangjianfengo1 yangjianfengo1 changed the title AMP arange_op & test [AMP OP&Arange] Mar 8, 2023
@ZzSean ZzSean changed the title [AMP OP&Arange] [AMP OP&Test] arange op support fp16/bf16 Mar 9, 2023
@@ -1234,7 +1234,7 @@ def arange(start=0, end=None, step=1, dtype=None, name=None):
check_dtype(
dtype,
'dtype',
['float32', 'float64', 'int32', 'int64'],
['float32', 'float64', 'int32', 'int64', 'float16', 'bfloat16'],
Copy link
Contributor

@ZzSean ZzSean Mar 9, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

暂不支持bfloat16,需要改成uint16

class TestBFloat16ArangeOp(OpTest):
def setUp(self):
self.op_type = "range"
self.__class__.op_type = self.op_type
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这句话可以删掉

Copy link
Contributor

@ZzSean ZzSean left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

Copy link
Contributor

@qili93 qili93 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM for @unittest.skip

@qili93 qili93 merged commit f344897 into PaddlePaddle:develop Mar 9, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants