Repository navigation
Conversation
* Add DistributedMuon to overlap packed all-to-all redistribution with optimizer compute while separating parameter storage and Muon compute layouts. * Use per-head Muon by default in Kimi K2.7, Kimi K2.5, and Moonlight recipes. * Support FSDP2 + EP. TP and PP are not supported yet but can be extended later. * Leave oversharded Shard(0) QKV support to a later PR in the stack. * The packed all-to-all redistribution and optimizer-compute overlap ideas are informed by [FSDP-Canzona](https://github.com/liangyuwang/FSDP-Canzona) and [Canzona: A Unified, Asynchronous, and Load-Balanced Framework for Distributed Matrix-based Optimizers](https://arxiv.org/abs/2602.06079) (Wang et al., 2026). * Resolve pytorch/torchtitan#3353. **Profiler trace** showing all-to-all overlapping during Muon: https://fburl.com/o7pyeuuy <img width="608" height="322" alt="Screenshot 2026-08-09 at 7 12 39 PM" src="https://github.com/user-attachments/assets/22e344bd-1459-432d-a023-cc71efe72da1" /> **Memory snapshot** showing the expected sharded optimizer state dict. ghstack (bottom to top): * [#4060 - DistributedMuon with all-to-all/compute overlap (this PR)](pytorch/torchtitan#4060) * [#4078 - Support oversharded QKV heads](pytorch/torchtitan#4078) * [#4077 - Support explicit replicated Muon compute](pytorch/torchtitan#4077) ghstack-source-id: 8fce56e Pull-Request: pytorch/torchtitan#4060 Co-authored-by: Liangyu Wang <[email protected]>
* Add DistributedMuon to overlap packed all-to-all redistribution with optimizer compute while separating parameter storage and Muon compute layouts. * Use per-head Muon by default in Kimi K2.7, Kimi K2.5, and Moonlight recipes. * Support FSDP2 + EP. TP and PP are not supported yet but can be extended later. * Leave oversharded Shard(0) QKV support to a later PR in the stack. * The packed all-to-all redistribution and optimizer-compute overlap ideas are informed by [FSDP-Canzona](https://github.com/liangyuwang/FSDP-Canzona) and [Canzona: A Unified, Asynchronous, and Load-Balanced Framework for Distributed Matrix-based Optimizers](https://arxiv.org/abs/2602.06079) (Wang et al., 2026). * Resolve pytorch/torchtitan#3353. **Profiler trace** showing all-to-all overlapping during Muon: https://fburl.com/o7pyeuuy <img width="608" height="322" alt="Screenshot 2026-08-09 at 7 12 39 PM" src="https://github.com/user-attachments/assets/22e344bd-1459-432d-a023-cc71efe72da1" /> **Memory snapshot** showing the expected sharded optimizer state dict. ghstack (bottom to top): * [#4060 - DistributedMuon with all-to-all/compute overlap (this PR)](pytorch/torchtitan#4060) * [#4078 - Support oversharded QKV heads](pytorch/torchtitan#4078) * [#4077 - Support explicit replicated Muon compute](pytorch/torchtitan#4077) ghstack-source-id: 54fb071 Pull-Request: pytorch/torchtitan#4060 Co-authored-by: Liangyu Wang <[email protected]>
* Add DistributedMuon to overlap packed all-to-all redistribution with optimizer compute while separating parameter storage and Muon compute layouts. * Use per-head Muon by default in Kimi K2.7, Kimi K2.5, and Moonlight recipes. * Support FSDP2 + EP. TP and PP are not supported yet but can be extended later. * Leave oversharded Shard(0) QKV support to a later PR in the stack. * The packed all-to-all redistribution and optimizer-compute overlap ideas are informed by [FSDP-Canzona](https://github.com/liangyuwang/FSDP-Canzona) and [Canzona: A Unified, Asynchronous, and Load-Balanced Framework for Distributed Matrix-based Optimizers](https://arxiv.org/abs/2602.06079) (Wang et al., 2026). * Resolve pytorch/torchtitan#3353. **Profiler trace** showing all-to-all overlapping during Muon: https://fburl.com/o7pyeuuy <img width="608" height="322" alt="Screenshot 2026-08-09 at 7 12 39 PM" src="https://github.com/user-attachments/assets/22e344bd-1459-432d-a023-cc71efe72da1" /> **Memory snapshot** showing the expected sharded optimizer state dict. ghstack (bottom to top): * [#4060 - DistributedMuon with all-to-all/compute overlap (this PR)](pytorch/torchtitan#4060) * [#4078 - Support oversharded QKV heads](pytorch/torchtitan#4078) * [#4077 - Support explicit replicated Muon compute](pytorch/torchtitan#4077) ghstack-source-id: e09970f Pull-Request: pytorch/torchtitan#4060 Co-authored-by: Liangyu Wang <[email protected]>
ghstack-source-id: 2c5cda8 Pull-Request: pytorch/torchtitan#4077
ghstack-source-id: 36c01a4 Pull-Request: pytorch/torchtitan#4077
DistMuon issues one Newton-Schulz call per parameter. A layer with many same-shaped sibling matrices therefore produces a long tail of small NS calls, each with its own GEMM sequence and its own compute scratch. Batch such siblings into a single NS call, while keeping momentum preparation and the parameter update per parameter. Which parameters batch together is declared, never inferred. Declaring the group A bucket is sized for communication, so it is deliberately heterogeneous: coarse buckets amortize collective launch overhead. Local compute wants the opposite. Rather than re-deriving a compute partition from FQN strings and tensor shapes, `BucketConfig.batch_groups` declares it directly, as fnmatch patterns resolved against the FQNs the bucket already matched. * The bucket remains the communication unit. `batch_groups` is a separate axis that only subdivides the bucket's local work. * Members must share a matrix shape, dtype, and device. `DistMuon` validates this at construction and raises, so a bad declaration fails loudly instead of silently degrading. * A group whose patterns select nothing is a configuration error, not a silently unbatched parameter. A stale pattern cannot quietly cost performance at every step. * Parameters that no group names execute one at a time, as before. Executing the group * `_LocalBucketExecutor` is a new seam on the redistribution runtime (`_plan_local_bucket` / `_execute_local_bucket`) so scratch for a batch is preplanned and eagerly reserved during construction; a steady-state step does not allocate. * A declared group is still split into scratch-bounded runs at `_MAX_LOCAL_MATRIX_BATCH_BYTES` (256 MiB), because the bound is physical and local shard shapes are not known until construction. That split warns, so a silently chunked group is visible. * No Newton-Schulz settings are re-checked at execution time. `_validate_groups` already requires exactly one parameter group, so every member reads the same ns_coefficients, ns_steps, and eps even if that group dict is mutated after construction. Kimi `config_registry` declares two groups per routed-experts bucket: w1_EFD and w3_EFD share the [F, D] matrix shape, and w2_EDF is its transpose. Both groups span the bucket's layer pair, so `layers.1-2.routed-experts` costs two batched NS calls rather than one per projection per layer. A future group could also absorb w2_EDF through a transposed view, since Newton-Schulz commutes with transpose and match_rms_adamw is transpose-invariant. Not implemented here, but the declaration can express it where a shape-derived key could not. Test `pytest tests/unit_tests/flex_shard/test_dist_muon.py` -- 6 passed on 2 GPUs. `test_matches_plain_muon_across_flat_checkpoint` exercises both paths in one optimizer: an oversharded stack whose storage shard boundary splits a matrix (unbatched redistribution path), plus two aligned siblings declared as one batch group. Both are compared against per-matrix `torch.optim.Muon` references across a flat checkpoint save/load. `TestDistMuonDeclaredBatchGroups` covers the contract: batching happens only where declared -- an identically shaped undeclared sibling stays unbatched -- and each rejection path raises. Submitted standalone against main rather than in the original ghstack stack: the lower entries #4078 and #4102 have landed, and this change does not depend on the still-open #4077. ghstack-source-id: 74987c6 Pull-Request: #4280
DistMuon issues one Newton-Schulz call per parameter. A layer with many same-shaped sibling matrices therefore produces a long tail of small NS calls, each with its own GEMM sequence and its own compute scratch. Batch such siblings into a single NS call, while keeping momentum preparation and the parameter update per parameter. Which parameters batch together is declared, never inferred. Declaring the group A bucket is sized for communication, so it is deliberately heterogeneous: coarse buckets amortize collective launch overhead. Local compute wants the opposite. Rather than re-deriving a compute partition from FQN strings and tensor shapes, `BucketConfig.batch_groups` declares it directly, as fnmatch patterns resolved against the FQNs the bucket already matched. * The bucket remains the communication unit. `batch_groups` is a separate axis that only subdivides the bucket's local work. * Members must share a matrix shape, dtype, and device. `DistMuon` validates this at construction and raises, so a bad declaration fails loudly instead of silently degrading. * A group whose patterns select nothing is a configuration error, not a silently unbatched parameter. A stale pattern cannot quietly cost performance at every step. * Parameters that no group names execute one at a time, as before. Executing the group * `_LocalBucketExecutor` is a new seam on the redistribution runtime (`_plan_local_bucket` / `_execute_local_bucket`) so scratch for a batch is preplanned and eagerly reserved during construction; a steady-state step does not allocate. * A declared group is still split into scratch-bounded runs at `_MAX_LOCAL_MATRIX_BATCH_BYTES` (256 MiB), because the bound is physical and local shard shapes are not known until construction. That split warns, so a silently chunked group is visible. * No Newton-Schulz settings are re-checked at execution time. `_validate_groups` already requires exactly one parameter group, so every member reads the same ns_coefficients, ns_steps, and eps even if that group dict is mutated after construction. Kimi `config_registry` declares two groups per routed-experts bucket: w1_EFD and w3_EFD share the [F, D] matrix shape, and w2_EDF is its transpose. Both groups span the bucket's layer pair, so `layers.1-2.routed-experts` costs two batched NS calls rather than one per projection per layer. A future group could also absorb w2_EDF through a transposed view, since Newton-Schulz commutes with transpose and match_rms_adamw is transpose-invariant. Not implemented here, but the declaration can express it where a shape-derived key could not. Test `pytest tests/unit_tests/flex_shard/test_dist_muon.py` -- 6 passed on 2 GPUs. `test_matches_plain_muon_across_flat_checkpoint` exercises both paths in one optimizer: an oversharded stack whose storage shard boundary splits a matrix (unbatched redistribution path), plus two aligned siblings declared as one batch group. Both are compared against per-matrix `torch.optim.Muon` references across a flat checkpoint save/load. `TestDistMuonDeclaredBatchGroups` covers the contract: batching happens only where declared -- an identically shaped undeclared sibling stays unbatched -- and each rejection path raises. Submitted standalone against main rather than in the original ghstack stack: the lower entries #4078 and #4102 have landed, and this change does not depend on the still-open #4077. ghstack-source-id: 74987c6 Pull-Request: #4280
DistMuon issues one Newton-Schulz call per parameter. A layer with many same-shaped sibling matrices therefore produces a long tail of small NS calls, each with its own GEMM sequence and its own compute scratch. Batch compatible local matrices into a single NS call, while keeping momentum preparation and the parameter update per parameter. Grouping Two local tensors can share one call exactly when they agree on matrix shape, dtype, and device, so that is the whole grouping key. Nothing is read from the FQN and nothing is declared in configuration: * A bucket already bounds a batch, because local work is executed one bucket at a time and members of different buckets are never resident together. That is a property of the runtime, not a naming convention, so bucketing stays a pure communication concern and compute batching follows from it. * Muon settings need no key either. `_validate_groups` requires exactly one parameter group, so every layout reads the same ns_coefficients, ns_steps, and eps even if that group dict is mutated after construction. * A layout whose local compute is a lone matrix has no batch dimension to concatenate along and runs by itself. Execution * `_LocalBucketExecutor` is a new seam on the redistribution runtime (`_plan_local_bucket` / `_execute_local_bucket`) so scratch for a batch is preplanned and eagerly reserved during construction; a steady-state step does not allocate. * A group is split into runs bounded by `_MAX_LOCAL_MATRIX_BATCH_BYTES` (256 MiB), because the bound is physical and local shard shapes are unknown until construction. The split warns, so a chunked group is visible rather than silent. Measured on moonlight_16b_a3b at a simulated world size of 32: 26 batched Newton-Schulz calls become 9, covering 78 parameters, with reserved buffers unchanged at 292 MiB. Test `pytest tests/unit_tests/flex_shard/test_dist_muon.py` -- 5 passed on 2 GPUs. `test_matches_plain_muon_across_flat_checkpoint` exercises both paths in one optimizer: an oversharded stack whose storage shard boundary splits a matrix (unbatched redistribution path), plus two aligned siblings that share one batched call. Both are compared against per-matrix `torch.optim.Muon` references across a flat checkpoint save/load. `TestDistMuonLocalMatrixBatching` covers the grouping rule directly: compatible matrices batch across layers inside one bucket, incompatible matrix shapes stay in separate batches, and a batch never spans two buckets. Submitted standalone against main rather than in the original ghstack stack: the lower entries #4078 and #4102 have landed, and this change does not depend on the still-open #4077. ghstack-source-id: 1f125d0 Pull-Request: #4280
|
Hi @weifengpy, I opened Draft PR #4411 to deduplicate DistMuon compute across With HSDP, replicas hold the same local parameter shards and currently execute My understanding is that #4077 adds Could you please take a look at whether this should remain a separate follow-up The persistent optimizer-state and checkpoint layouts remain unchanged, so I |
Stack from ghstack (oldest at bottom):