realize flatten parameters and grads in optimizer, calls in Adam and Adamw optimizer#48810
Closed
pangyoki wants to merge 11 commits intoPaddlePaddle:developfrom
Closed
realize flatten parameters and grads in optimizer, calls in Adam and Adamw optimizer#48810pangyoki wants to merge 11 commits intoPaddlePaddle:developfrom
pangyoki wants to merge 11 commits intoPaddlePaddle:developfrom
Conversation
|
你的PR提交成功,感谢你对开源项目的贡献! |
|
❌ The PR is not created using PR's template. You can refer to this Demo. |
… optimization_support_flatten_param_grads
|
Since you haven't replied for more than a year, we have closed this issue/pr. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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
New features
PR changes
APIs
Describe
背景
在NPU设备上的优化中,ernie模型的优化器阶段耗时非常长,主要原因是优化器阶段需要拉起非常多的小kernel。#33461 这个PR实现了
flatten_params_grads的方法,调用coalesce_tensorop将所有的parameters和grads合并到一起,形成一个parameter和一个grad,这样就只用调用一次优化器op即可,极大的减少了kernel拉起的时间。#33461 这个PR是在fluid/optimizer.py下实现了
flatten_param_grads方法,且主要处理了静态图场景。本PR工作
本PR将该方法迁移到paddle/optimizer/optimizer.py下,并对动态图模式下也做了处理。
但是,因为现在最终态
_C_ops.coalesce_tensor看起来不是inplace的,对输出的flatten_param和flatten_grads的修改无法影响原parameters和grads。所以还是调用的_legacy_C_ops.coalesce_tensor方法。而且,与静态图不同,动态图模式下的
use_align属性暂时设置为False,因为align出来的值无法初始化为0,导致可能出现精度问题。在目前的NPU场景下,暂不处理use_align属性为True的情况。后续TODO
use_align属性设置为True。