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

[Dy2St][AMP] add should_auto_cast attribute for each operator #58628

Merged
merged 9 commits into from
Nov 13, 2023

Conversation

SigureMo
Copy link
Member

@SigureMo SigureMo commented Nov 2, 2023

PR types

New features

PR changes

Others

Description

为 Operator 增加 should_auto_cast 属性,该属性的语义是在全局开启 AMP 的情况下,该 OP 是否应该被 cast,如果全局没有开启 AMP,该属性无效

此为局部 AMP 在旧 IR 下的临时方案,新 IR 会有其他的动静统一的长期方案来做,在旧 IR 退场时可以直接删掉

Usage

在动转静之后拿到 Program 时,根据组网时期记录的局部 AMP 信息 ProgramTranslator.get_instance()._amp_records,调用 prepare_op_should_auto_cast 传入 Program 和该 records,此时所有 OP 都会有 should_auto_cast 属性,之后可根据此属性在后续 PASS 进行 cast,具体示例可参考 test/dygraph_to_static/test_local_cast.py

目前组网时会记录完整的 AmpOptions,但 prepare 仅仅处理了其中的 enable,如果后续有更复杂的需求再考虑将所有 options set 上去

PCard-66972

Copy link

paddle-bot bot commented Nov 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.

@SigureMo SigureMo changed the title [WIP][Dy2St][AMP] test range amp [WIP][Dy2St][AMP] add should_auto_cast attribute for each operator Nov 8, 2023
@@ -2935,6 +2935,9 @@ def __init__(
# attr for static graph mode cuda graph
self._cuda_graph_attr = _current_cuda_graph_mode

# attr for OP should cast in AMP mode
self._should_auto_cast: bool = False
Copy link
Contributor

Choose a reason for hiding this comment

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

True

Copy link
Contributor

@2742195759 2742195759 left a comment

Choose a reason for hiding this comment

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

LGTMMeao

@SigureMo SigureMo changed the title [WIP][Dy2St][AMP] add should_auto_cast attribute for each operator [Dy2St][AMP] add should_auto_cast attribute for each operator Nov 9, 2023
@SigureMo SigureMo merged commit a6dd0e9 into PaddlePaddle:develop Nov 13, 2023
@SigureMo SigureMo deleted the dy2st/range-amp branch November 13, 2023 13:00
danleifeng pushed a commit to danleifeng/Paddle that referenced this pull request Nov 14, 2023
SecretXV pushed a commit to SecretXV/Paddle that referenced this pull request Nov 28, 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.

3 participants