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]fix dtype mismatch error #53712

Merged
merged 1 commit into from
May 12, 2023

Conversation

zhangting2020
Copy link
Contributor

@zhangting2020 zhangting2020 commented May 11, 2023

PR types

Bug fixes

PR changes

Others

Description

Pcard-70458

fix dtype mismatch error for static graph

一些模型中会调用cast api将tensor手动转换为fp16/fp32类型,在之前的升级中cast op被跳过未做处理,所以在amp改写program的过程中,cast op的输入来自于前面的OP,其类型可能已经被修改,从而和in_dtype的属性不一致,另外输出tensor需要根据out_dtype属性去设置。

如果类型不一致,会导致反向cast_grad的输出类型不符合预期,引起后续算子报错

@paddle-bot
Copy link

paddle-bot bot commented May 11, 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 May 11, 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.

Copy link
Contributor

@Xreki Xreki left a comment

Choose a reason for hiding this comment

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

LGTM

@@ -667,6 +670,24 @@ def need_process(op):
"---- Add into keep_fp16_ops because the op in white_list ----"
)
else:
# if cast in orgin program, we only modifiy attr and output's dtype to avoid dtype mismatch errors.
if op.type == 'cast':
Copy link
Contributor

Choose a reason for hiding this comment

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

后续建议把这部分代码封装成一个函数。

@zhangting2020 zhangting2020 merged commit 772b490 into PaddlePaddle:develop May 12, 2023
zhangting2020 added a commit to zhangting2020/Paddle that referenced this pull request May 12, 2023
lanxianghit pushed a commit that referenced this pull request May 15, 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.

2 participants