-
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
[Dy2St][AMP] add should_auto_cast
attribute for each operator
#58628
Conversation
你的PR提交成功,感谢你对开源项目的贡献! |
should_auto_cast
attribute for each operator
python/paddle/base/framework.py
Outdated
@@ -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 |
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.
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.
LGTMMeao
should_auto_cast
attribute for each operatorshould_auto_cast
attribute for each operator
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