Repository navigation
[Optimizer] Support per-group inner optimizers in Muon sharding - #79844
Merged
GuoxiaWang merged 1 commit intoOct 15, 2026
Merged
Conversation
Member
Author
|
/re-run all-failed |
xxyux
force-pushed
the
mixed-inner-optimizer-sharding
branch
from
October 9, 2026 16:13
4e06902 to
a68d06c
Compare
Contributor
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## develop #79844 +/- ##
==========================================
Coverage ? 96.81%
==========================================
Files ? 7
Lines ? 1318
Branches ? 0
==========================================
Hits ? 1276
Misses ? 42
Partials ? 0 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
xxyux
force-pushed
the
mixed-inner-optimizer-sharding
branch
from
October 10, 2026 03:35
a68d06c to
d4d617d
Compare
Member
Author
|
/re-run all-failed |
Paddle-Review-Bot
suggested changes
Oct 12, 2026
xxyux
force-pushed
the
mixed-inner-optimizer-sharding
branch
2 times, most recently
from
October 13, 2026 05:51
cf12add to
9866944
Compare
Paddle-Review-Bot
approved these changes
Oct 13, 2026
xxyux
force-pushed
the
mixed-inner-optimizer-sharding
branch
from
October 14, 2026 03:40
9866944 to
326ae18
Compare
Member
Author
Member
Author
Paddle-Review-Bot
suggested changes
Oct 14, 2026
Paddle-Review-Bot
suggested changes
Oct 14, 2026
xxyux
force-pushed
the
mixed-inner-optimizer-sharding
branch
from
October 14, 2026 12:34
326ae18 to
1caca50
Compare
Member
Author
xxyux
force-pushed
the
mixed-inner-optimizer-sharding
branch
from
October 14, 2026 13:17
1caca50 to
e4de196
Compare
Paddle-Review-Bot
approved these changes
Oct 14, 2026
Member
Author
|
/re-run all-failed |
Training a model with a different optimizer per parameter group (Muon on the 2-D backbone, AdamW on everything else) currently means forking the sharding optimizer. This adds the two pieces needed to do it in-tree: - InnerOptimizer: a small base class for an optimizer that only owns the per-parameter update (_ensure_accumulators / _update_parameters), with the accumulator, master-weight and grad-clip plumbing shared. V1/V2 sharding is a declared class attribute (keep_whole) exposed through declared_keep_whole() / keep_whole_of(); a sub-class that leaves it unset fails loudly at construction instead of silently sharding the wrong way. weight_decay is required (no implicit 0.0), so a config group that forgets it raises instead of quietly training without decay. - MixedInnerOptimizer: holds N InnerOptimizer sub-optimizers, routes each parameter to its owner, and aggregates their accumulators and optimizer_state_layout() into one state tree. - MixedShardingOptimizer: the sharding shell for the above, next to MuonShardingOptimizer. HybridParallelOptimizer picks it whenever the inner optimizer is a MixedInnerOptimizer (no strategy flag -- the choice follows from the inner optimizer), and unwrap_optimizer / _hybrid_sync_grad accept it like its sibling. Parameters whose owner declares keep_whole stay whole on one owner rank (V1); the rest are sharded element-wise (V2). The rest of the machinery is the same as MuonShardingOptimizer's -- color comm groups, the machine-balanced 2-D owner assignment, comm overlap and fused optimizer states -- while the checkpoint state suffixes come from optimizer_state_layout() instead of AdamW's hard-coded names. Tests: test/legacy_test/test_inner_optimizer.py and test_mixed_inner_optimizer.py cover the single-process contract; test_mixed_2d_partition.py feeds constructed data straight into the machine-balanced 2-D owner assignment (16 ranks over two 8-card machines, dense and expert comm groups, two dtypes); test/collective/fleet/test_parallel_dygraph_mixed_sharding.py (worker hybrid_parallel_sharding_mixed_model.py) covers the 2-card shell -- V1/V2 partition, owner map agreement, convergence against a single-card reference, state_dict round-trip and sharded_state_dict -- under the default, comm_overlap and fused-optimizer-states configurations.
xxyux
force-pushed
the
mixed-inner-optimizer-sharding
branch
from
October 15, 2026 06:05
e4de196 to
5720a5b
Compare
Paddle-Review-Bot
approved these changes
Oct 15, 2026
Member
Author
|
/re-run all-failed |
1 similar comment
Member
Author
|
/re-run all-failed |
Member
Author
|
/re-run all-failed |
Member
Author
|
/re-run all-failed |
XieYunshen
approved these changes
Oct 15, 2026
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 Category
Distributed Strategy
PR Types
New features
Description
MuonShardingOptimizer只能包一个Muon,所有参数共用一套超参;分片和存档用的状态名也写死成 AdamW 的(moment1/2、beta1/2_pow_acc)。本 PR 新增一套可插拔的内层优化器接口,外加一个新的分片壳MixedShardingOptimizer,让一次训练里可以挂多个内层优化器、每组各用自己的超参,新增优化器类型也不需要改分片壳。MuonShardingOptimizer与现有单Muon用法行为不变(本 PR 不改muon_sharding_optimizer.py)。内层优化器接口(内部接口:本 PR 不改
python/paddle/optimizer/__init__.py,两个模块的__all__为空,按模块路径导入)paddle.optimizer.inner_optimizer:InnerOptimizer/ParamInfokeep_whole声明该优化器的更新数学支持哪种切分:True只能 V1(整张 tensor 放在一个 owner rank 上),False只能 V2(逐元素分片),None表示两者都正确、默认解析为 V2;未声明(KEEP_WHOLE_UNDECLARED)则构造时报错。None时可由 Paddle 之上的框架层用resolve_keep_whole/set_keep_whole收窄(我们的 trainer 在展开按组优化器配置时调用),本 PR 内没有收窄的调用方,所以None一律是 V2。MixedInnerOptimizer本身是异构的,没有单一的keep_whole,对它调用set_keep_whole会直接raise TypeError并提示去收窄对应组的子优化器。optimizer_state_layout()由优化器自己声明状态名。_ensure_accumulators(按参数分配状态)和_update_parameters(就地更新本地的整张/分片参数)。paddle.optimizer.mixed_inner_optimizer:MixedInnerOptimizer+register_inner_optimizer/get_inner_optimizer_apply_optimize一次调用内部按组分派。state_dict/set_state_dict、master weight、状态布局与 ZCC 融合存储;grad clip 只在外层做一次。新分片壳
MixedShardingOptimizer(python/paddle/distributed/fleet/meta_optimizers/mixed_sharding_optimizer.py)MuonShardingOptimizer(Sharding Stage1 V3,整张 + 逐元素混合)共用同一套通信 / 分区 / overlap 机制:color自定义通信组、sharding_configs.machine_balanced_2d_partition机器均衡 owner 分配、comm overlap、enable_fuse_optimizer_states、comm_group_call_opt、use_reduce_avg等。差别只在优化器契约:MixedInnerOptimizer;inner.keep_whole_of(name)决定,即由拥有该参数的子优化器的更新数学决定,不由 yaml 配置;set_state_dict/sharded_state_dict的状态后缀从inner.optimizer_state_layout()读取,自定义状态布局不必改分片壳;accumulate_steps、comm_group_call_opt前置条件、入参类型等)一律raise ValueError/TypeError而非assert,python -O下不会被剥离。HybridParallelOptimizer在内层是MixedInnerOptimizer时自动选用该壳,不需要新的 strategy 开关。其他
MuonParamInfo改为继承ParamInfo(纯继承,字段与语义不变)。单测:
test/legacy_test/test_inner_optimizer.py、test/legacy_test/test_mixed_inner_optimizer.py(单进程):接口契约、路由、状态汇总、master weight、ZCC 融合存储;纯 CPU 构建上只 skip 真正要 accelerator 的两个 FusionStorage 用例。test/legacy_test/test_mixed_2d_partition.py(单进程,无通信组/加速器/启动器):直接给_partition_2d_parameters_machine_balanced喂构造数据(pp2 x ep4 x moe_sharding2 = 16 卡跨 2 台 8 卡机、dense/expert 两类通信组、bf16/fp32 两种 dtype),覆盖 owner 不重不漏、owner 数随桶体积增长、跨机负载均衡、与合并顺序无关、机器空闲 rank 耗尽时被剔除。test/collective/fleet/test_parallel_dygraph_mixed_sharding.py(2 卡,3 个 case:默认 / comm overlap /enable_fuse_optimizer_states):V1/V2 混合切分下与单卡参考实现逐步对齐、各 rank 结果一致、state_dict/set_state_dict/sharded_state_dict往返,以及机器均衡分区的端到端链路(两次all_gather_object、各 rank 映射一致)、align 模式下 2D 梯度用ReduceOp.SUM、grad clip、clear_grad 等壳内链路。python/paddle/改动文件合计):96.5%。是否引起精度变化
否