Skip to content

Commit 095afe9

Browse files
committed
fix(recipes): preserve Kimi Muon layout settings
Signed-off-by: Chen Cui <chcui@nvidia.com>
1 parent 1e5fbe5 commit 095afe9

5 files changed

Lines changed: 41 additions & 8 deletions

File tree

‎docs/training/optimizer-scheduler.md‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,11 +53,16 @@ By default, `use_layer_wise_param_layout=True` builds shard-aligned DDP buffers
5353
for the LayerWise optimizer. Set it to `False` to retain compact DDP buffers and
5454
use LayerWise's variable-size parameter synchronization path. This reduces
5555
layout padding while preserving the configured parameter-gather behavior.
56+
Existing Kimi recipes keep the compact layout and parameter-gather overlap
57+
disabled until their MoE and pipeline-parallel configurations are validated
58+
with the shard-aligned layout; other recipes can opt in independently.
5659

5760
Resuming Muon training restores Muon optimizer state. When changing optimization
5861
algorithms between runs, load model weights with fresh optimizer state using
5962
`checkpoint.load_optim=False` or the appropriate finetuning configuration;
6063
Bridge does not convert Adam moments into Muon optimizer state.
64+
Checkpoints created before distributed-optimizer metadata was recorded retain
65+
the historical model-space sharding fallback when that metadata key is absent.
6166

6267
## SchedulerConfig
6368

‎src/megatron/bridge/recipes/kimi/h100/kimi_k2.py‎

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,16 +63,23 @@ def _apply_kimi_k2_optimizer(cfg: ConfigContainer, optimizer_type: str) -> None:
6363
grad_reduce_in_fp32 = False
6464
cfg.ddp.use_distributed_optimizer = True
6565
cfg.ddp.overlap_param_gather = True
66+
if cfg.comm_overlap is not None:
67+
cfg.comm_overlap.overlap_param_gather = True
6668
elif optimizer_type == "muon":
6769
opt_cfg, scheduler_cfg = distributed_muon_with_cosine_annealing(
6870
lr_warmup_iters=2000,
6971
lr_decay_iters=cfg.train.train_iters,
7072
max_lr=3e-4,
7173
min_lr=3e-5,
7274
)
75+
# Preserve this recipe's established compact LayerWise layout until the
76+
# shard-aligned layout is validated with its MoE/pipeline topology.
77+
opt_cfg.use_layer_wise_param_layout = False
7378
grad_reduce_in_fp32 = True
7479
cfg.ddp.use_distributed_optimizer = False
7580
cfg.ddp.overlap_param_gather = False
81+
if cfg.comm_overlap is not None:
82+
cfg.comm_overlap.overlap_param_gather = False
7683
else:
7784
raise ValueError(f"Invalid optimizer type: {optimizer_type}")
7885

‎src/megatron/bridge/recipes/kimi_vl/h100/kimi_k25_vl.py‎

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,9 @@ def kimi_k25_vl_sft_512gpu_h100_bf16_config() -> ConfigContainer:
121121
max_lr=3e-4,
122122
min_lr=3e-5,
123123
)
124+
# Preserve this recipe's established compact LayerWise layout until the
125+
# shard-aligned layout is validated with its MoE/pipeline topology.
126+
opt_cfg.use_layer_wise_param_layout = False
124127
cfg.optimizer = opt_cfg
125128
cfg.scheduler = scheduler_cfg
126129

@@ -162,7 +165,7 @@ def kimi_k25_vl_sft_512gpu_h100_bf16_config() -> ConfigContainer:
162165
cfg.optimizer.exp_avg_sq_dtype = torch.float32
163166

164167
# Communication overlap
165-
cfg.comm_overlap = CommOverlapConfig(tp_comm_overlap=False)
168+
cfg.comm_overlap = CommOverlapConfig(tp_comm_overlap=False, overlap_param_gather=False)
166169
cfg.comm_overlap.delay_wgrad_compute = False
167170
cfg.comm_overlap.overlap_moe_expert_parallel_comm = False
168171
cfg.model.moe_shared_expert_overlap = True
@@ -171,7 +174,8 @@ def kimi_k25_vl_sft_512gpu_h100_bf16_config() -> ConfigContainer:
171174
cfg.checkpoint.save_interval = 2000
172175
cfg.checkpoint.async_save = False
173176

174-
# DDP config — Muon requires distributed_optimizer=False and overlap_param_gather=False
177+
# LayerWise Muon does not use DDP's ordinary DistributedOptimizer mode.
178+
# Keep parameter-gather overlap disabled for this recipe's uneven MIMO inputs.
175179
cfg.ddp.use_distributed_optimizer = False
176180
cfg.ddp.overlap_param_gather = False
177181
cfg.ddp.grad_reduce_in_fp32 = True

‎tests/unit_tests/recipes/kimi/test_kimi_k2.py‎

Lines changed: 20 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
_get_kimi_k2_pipeline_layout,
2323
kimi_k2_pretrain_config,
2424
)
25-
from megatron.bridge.training.config import ConfigContainer
25+
from megatron.bridge.training.config import ConfigContainer, _validate_and_sync_distributed_optimizer_settings
2626
from megatron.bridge.training.mixed_precision import MixedPrecisionConfig
2727
from tests.unit_tests.recipes.recipe_test_utils import patch_recipe_module_global
2828

@@ -148,18 +148,33 @@ def test_pretrain_config_pipeline_split_settings(self):
148148
assert cfg.model.num_layers_in_last_pipeline_stage is None
149149

150150
def test_pretrain_config_ddp_settings_for_muon(self):
151-
"""Test DDP settings configured for Muon optimizer."""
151+
"""The existing Kimi recipe retains compact, non-overlapped LayerWise Muon."""
152152
cfg = kimi_k2_pretrain_config()
153153

154-
# Muon requires these specific DDP settings
155154
assert cfg.ddp.overlap_grad_reduce is True
156-
assert cfg.ddp.overlap_param_gather is False # Muon needs this to be False
155+
assert cfg.ddp.overlap_param_gather is False
156+
assert cfg.comm_overlap.overlap_param_gather is False
157157
assert cfg.ddp.check_for_nan_in_grad is True
158-
assert cfg.ddp.use_distributed_optimizer is False # Muon needs this to be False
158+
assert cfg.ddp.use_distributed_optimizer is False
159159
assert cfg.ddp.use_megatron_fsdp is False
160160
assert cfg.ddp.grad_reduce_in_fp32 is True
161161
assert cfg.ddp.average_in_collective is True
162162
assert cfg.ddp.data_parallel_sharding_strategy == "no_shard"
163+
assert cfg.optimizer.optimizer == "dist_muon"
164+
assert cfg.optimizer.use_layer_wise_param_layout is False
165+
166+
_validate_and_sync_distributed_optimizer_settings(cfg)
167+
168+
assert cfg.optimizer.optimizer == "muon"
169+
assert cfg.optimizer.use_layer_wise_distributed_optimizer is True
170+
assert cfg.optimizer.use_distributed_optimizer is False
171+
assert cfg.ddp.use_distributed_optimizer is False
172+
assert cfg.optimizer.use_layer_wise_param_layout is False
173+
174+
cfg.comm_overlap.finalize()
175+
cfg.comm_overlap.data_parallel_size = 16
176+
overlap_cfg = cfg.comm_overlap._get_optimizer_overlap_cfgs(cfg.model)
177+
assert overlap_cfg.overlap_param_gather is False
163178

164179
def test_pretrain_config_dataset_configuration(self):
165180
"""Test dataset configuration."""

‎tests/unit_tests/recipes/kimi_vl/test_kimi_k25_vl.py‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -203,17 +203,19 @@ def test_sft_config_pipeline_layout_tracks_supported_runner_override(self):
203203
assert cfg.model.pipeline_model_parallel_layout == _get_kimi_k25_vl_pipeline_layout(4, 1)
204204

205205
def test_sft_config_ddp_settings_for_muon(self):
206-
"""DDP settings respect Muon's constraints (no dist optimizer, no param overlap)."""
206+
"""The existing Kimi-VL recipe retains compact, non-overlapped LayerWise Muon."""
207207
cfg = kimi_k25_vl_sft_config()
208208

209209
assert cfg.ddp.use_distributed_optimizer is False
210210
assert cfg.ddp.overlap_param_gather is False
211+
assert cfg.comm_overlap.overlap_param_gather is False
211212
assert cfg.ddp.overlap_grad_reduce is True
212213
assert cfg.ddp.grad_reduce_in_fp32 is True
213214
assert cfg.ddp.check_for_nan_in_grad is True
214215
assert cfg.ddp.use_megatron_fsdp is False
215216
assert cfg.ddp.average_in_collective is True
216217
assert cfg.ddp.data_parallel_sharding_strategy == "no_shard"
218+
assert cfg.optimizer.use_layer_wise_param_layout is False
217219

218220
def test_sft_config_dataset_configuration(self):
219221
"""Dataset uses sequence length 4096 and the model's HF processor path."""

0 commit comments

Comments
 (0)