[AMP] Refine found_inf of loss_scaler #37770
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
PR types
Performance optimization
PR changes
APIs
Describe
AmpScaler
类用于混合精度训练过程中对loss进行缩放,其中成员属性:_found_inf
用于标记每轮训练过程中参数梯度是否存在inf。原本框架代码会在调用
![图片](https://user-images.githubusercontent.com/82555433/144237853-abacca0b-40e2-40b5-9cbe-7648f2bf120c.png)
check_finite_and_unscale
op通过to_variable
申请两个bool类型的tensor,导致每轮训练在该时间存在cudaMemcpy,影响GPU性能:优化后,将在
![图片](https://user-images.githubusercontent.com/82555433/144238131-9dbe6c1e-608e-4cd6-a6c9-4fba5ec016d5.png)
AmpScaler
类初始化过程中声明并定义两个bool类型的tensor,消除训练过程中的cudaMemcpy: