You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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
你的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.
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 Category
Auto Parallel
PR Types
New features
Description
为 sharding tensor-fusion 场景支持 save&load 策略
tensor-fusion save&load 适配方案概要
1. 背景
为了减少通信开销,tensor fusion 通过将多个小的张量合并成一个较大的张量。这种操作会导致原本需要独立切分的张量被合并成一个整体,而这个合并后的张量会分布到不同的设备上,可能会导致 不均匀切分。因此,在 tensor fusion 后,需要对 save&load 适配
2. 方案设计
方案的主要思路是在 save 和 load 的时候对参数进行处理。在 save 的时候,在
state_dict
函数中将不均匀的slice
优化器参数,根据分组的信息通信(all_gather)回全局视角下的 tensor,再根据 sharding 的 axis 保留当前卡的部分。换句话说就是让state_dict
和不开 tensor-fusion 时的状态一样。在 load 的时候,由于我们保存的是均匀切分的参数,我们需要再重新给他转化回到不均匀切分的状态
2.1 保存 (save) 优化器状态
保存优化器状态时,优化器的参数可能已经在多个设备上进行了切分。为了保证保存时的状态和在没有 tensor-fusion 的情况下保持一致,我们需要对每个设备上的优化器参数进行以下处理:
2.2 加载 (load) 优化器状态
加载时,由于保存的参数已经是均匀切分的状态,原本在保存时为非均匀切分的参数需要在加载过程中恢复为原来的非均匀切分状态。具体步骤包括:
Pcard-76459