Repository navigation
Forward the per-head Muon tag at every muon_update call site - #8612
Conversation
Forward `num_heads` at all three. Signed-off-by: Vineeth Sai <[email protected]>
alanhuangyoo
left a comment
There was a problem hiding this comment.
Thanks, good catch, I missed these when I added per-head. Small thing: from what I can see the padded branch of get_flat_partition is picked by zero_optimization.parameter_alignment, not round_robin_gradients (round robin alone stays unpadded on an H20 here), so the description might need a tweak.
Also the AST test feels a bit fragile, a positional arg would trip it. Maybe a small run with parameter_alignment: true could cover the ZeRO path the way your MuonWithAuxAdam test does? 78 pass on an H20 here btw.
Run a real ZeRO 1 and 2 engine with parameter_alignment on, so get_flat_partition takes its padded branch, and check muon_update gets q_proj's head count. The call-site scan now counts positional arguments. Signed-off-by: Vineeth Sai <[email protected]>
|
You're right, thanks: round robin only reorders the params, and the padding comes from |
There was a problem hiding this comment.
Copilot review overview
🟢 Approval recommended
The missing metadata forwarding is consistently fixed and covered by targeted regression tests.
Review effort: Balanced
Findings: None
What changed in this PR
Forwards per-head Muon metadata through previously incomplete optimizer paths.
Changes:
- Passes
muon_num_headsthrough ZeRO 1/2 padding, auxiliary Adam, and BF16 paths. - Adds regression and call-site coverage.
| File | Description |
|---|---|
deepspeed/runtime/zero/stage_1_and_2.py |
Forwards head count in the padded partition path. |
deepspeed/runtime/zero/muon/muon_optimizer.py |
Preserves per-head updates without ZeRO. |
deepspeed/runtime/bf16_optimizer.py |
Preserves per-head updates under BF16 optimization. |
tests/unit/runtime/zero/test_per_head_muon.py |
Adds behavioral and call-site regression tests. |
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
|
Looks right to me. On master, bf16_optimizer, MuonWithAuxAdam.step and the padded branch of get_flat_partition are the only muon_update calls that drop num_heads, and this covers all three. Merged on current master the new test file is 80 passed on a Linux box, and with the source change reverted 4 of them fail, so they do test the fix. |
|
Thanks for running it on Linux and checking that the tests fail with the change reverted. |
stage_1_and_2 now imports muon_update inside get_flat_partition, so the module has no muon_update attribute to patch and the test errored on master. Signed-off-by: Vineeth Sai <[email protected]>
Head branch was pushed to by a user without write access
|
CI failure fixed in 8276340: master now imports muon_update inside get_flat_partition, so the padded-partition test patches it in original_muon instead. |
ghost
left a comment
There was a problem hiding this comment.
LGTM.
- I checked every
muon_updatecall underdeepspeed/on current master. There are 11, and the three this PR fixes are the only ones that dropnum_heads. - The padded branch now matches its unpadded twin.
MuonWithAuxAdam.steponly reachesmuon_updatefor the unsharded weight, sopcarries the tag there.- In
BF16_Optimizer,paramis the model parameter frombf16_groups, and the momentum is reassembled to the full matrix before the call, so a per-head split along dim 0 is well defined.
On CPU (gloo), test_per_head_muon.py passes, 80 tests.
This also matters for #8580 (fused QKV). That PR only tags the fused projection and relies on every call site forwarding muon_num_heads. Without this PR, a fused qkv_proj would still be orthogonalized whole on the BF16 optimizer, on MuonWithAuxAdam and on the padded ZeRO-1/2 branch.
- I merged the two locally. The only conflict is the import block of
test_per_head_muon.py(inspectvslogging). - The combined file passes, 87 tests.
Two nits, neither blocking. They are inline below.
| # --------------------------------------------------------------------------- | ||
| # | ||
| # The head count is tagged on the parameter, so it only reaches Newton-Schulz if the code | ||
| # that calls `muon_update` reads it back off. Three of the six call sites did not, and an |
There was a problem hiding this comment.
Nit: "Three of the six call sites": counting original_muon.py's own optimizers, there are 11 muon_update calls under deepspeed/ today. Maybe "three of the call sites", so the comment doesn't go stale.
There was a problem hiding this comment.
Good point, reworded to "three of the call sites" in 06026e6.
| beta=group['momentum'], | ||
| ns_method=group.get('ns_method', 'gram')) | ||
| ns_method=group.get('ns_method', 'gram'), | ||
| num_heads=getattr(param, 'muon_num_heads', None)) |
There was a problem hiding this comment.
Nit: this site is pinned only by the AST check. A spy test like the padded one would catch it at run time too. Use ZeRO-1, bf16, with data_types.grad_accum_dtype: fp32, which selects BF16_Optimizer.
There was a problem hiding this comment.
Added a spy test for BF16_Optimizer in 06026e6 (ZeRO-1, bf16, fp32 grad accumulation). It fails without the change and passes with it.
…deepspeedai#9020) ## CI: drop the abandoned deepspeed-kernels from the dev requirements ### Problem When Modal has no GPU within 600 s, `modal-torch-latest` falls back to AWS. Since deepspeedai#8950 (merged 2026-11-04) that fallback has failed 6 times out of 6 with `AwsControllerError: AWS prepare failed with exit code 1`, and no tests ran. Five were merge-queue entries whose PRs were not at fault (deepspeedai#8985 twice, deepspeedai#8728, deepspeedai#8612, deepspeedai#8842); one was the scheduled run on master. Examples: - https://github.com/deepspeedai/DeepSpeed/actions/runs/41940811586/job/126960989358 - https://github.com/deepspeedai/DeepSpeed/actions/runs/42061411246/job/127364012408 ### Cause deepspeedai#8950 added `python -m pip check` after "install candidate DeepSpeed" in `build_remote_commands`. On the AWS environment (uv venv, CPython 3.12.14) it exits 1 with: ``` deepspeed-kernels 0.0.1.dev1698255861 is not supported on this platform ``` `deepspeed-kernels` comes from `requirements/requirements-dev.txt`. Its only file on PyPI (last release 2023-10-25) is named `deepspeed_kernels-0.0.1.dev1698255861-py3-none-manylinux1_x86_64.whl`, but the `WHEEL` file inside it says `Tag: cp38-cp38-linux_x86_64`. pip installs by the file name (any Python 3) and `pip check` checks the internal tag (Python 3.8 only). To see the tag: ``` pip download deepspeed-kernels==0.0.1.dev1698255861 --no-deps -d /tmp/dk && unzip -p /tmp/dk/*.whl '*.dist-info/WHEEL' ``` The job logs never show this line: the prepare output is cut at 24,000 characters of stdout (`SSM_INLINE_STDOUT_CHARS`), and the complete output is fetched only when the test phase fails. I found it by running the same prepare commands outside CI. (The Modal sandbox runs the same `pip check` and prints `No broken requirements found.` with the same package; I could not find out why it passes there.) ### Change | Where | What | |---|---| | `requirements/requirements-dev.txt` | Remove `deepspeed-kernels`, which is no longer maintained. | | `ci/torch_latest.py`: `_emit_ssm_output` | Fetch the complete output tail for a failed `prepare` phase too, not only `test`, so the next prepare failure shows its error in the job log. | | `ci/test_torch_latest.py` | One test for the prepare tail; the fake AWS CLI returns the prepare output for prepare-phase S3 keys. | `pip check` itself is unchanged (as deepspeedai#8950 wrote it). The first version of this PR exempted the `deepspeed-kernels` line instead; following review, the package is removed rather than exempted. No active CI job uses `deepspeed-kernels`: - the inference-v2 kernel tests are deselected by `tests/pytest.ini` (`not inference_v2_ops`); the only workflow that selected them (`nv-a6000.yml`) is disabled; - `nv-pre-compile-ops` builds with `DS_BUILD_CUTLASS_OPS=0 DS_BUILD_RAGGED_DEVICE_OPS=0`; - it was the only reason `cmake` was installed, and nothing else in `ci/`, `tests/` or the workflows uses `cmake`. Not removed: `op_builder/ragged_ops.py` and `op_builder/inference_cutlass_builder.py` link prebuilt libraries from the package (`-lblockedflash`, `-ldeepspeedft`) to build the inference-v2 ragged kernels and CUTLASS MoE / mixed GEMM. Inference v2 is not deprecated (deepspeedai#8489), and DeepSpeed-MII (0.3.3) still installs `deepspeed-kernels` as a dependency, so those builders keep working for its users. The AWS prepare installs the requirements of the candidate commit, so this change also applies to its own merge-queue run. ### Duplicate check Searched open PRs and issues on 2026-11-05 for "deepspeed-kernels", "pip check", "AWS prepare failed" and "capacity fallback": none addresses this. deepspeedai#8950 added the check; deepspeedai#8921 moved the AWS fallback to Python 3.12. ### Tests Hardware: CPU only (CI controller code and requirements; no GPU path changed). Intel Xeon Platinum 8375C, Ubuntu 22.04.5, CPython 3.12.14, pip 26.3, pytest 8.3.5. | Command | Result | |---|---| | `python ci/test_torch_latest.py` | 50/50 passed (49 existing + 1 new) | | `python ci/test_tests_fetcher.py` | 27/27 passed | | `pre-commit run --files ci/torch_latest.py ci/test_torch_latest.py requirements/requirements-dev.txt` | all hooks pass | | the new test against the master version of `ci/` | fails (the prepare log ends at "AWS prepare failed with exit code 1" without the late line) | | the AWS prepare commands rerun from scratch outside CI with this `requirements-dev.txt` (uv 0.12.7, CPython 3.12.14, the three requirements files, torch 2.10.0 cu128 pin, Transformers `main`, DeepSpeed master) | RERUN_RESULT | `test_aws_prepare_failure_emits_bounded_s3_tail`: a failed prepare whose output exceeds the inline limit prints the tail, including the last line, read from the prepare-phase S3 key. Not run: the real AWS fallback (needs the CI's AWS credentials) and the Modal sandbox. No workflow runs `ci/test_torch_latest.py`; I ran it by hand. ### Compatibility CI and development requirements only. No DeepSpeed runtime code changes, so no ZeRO stage, offload, precision or parallelism cell is affected. Users who build the inference-v2 ragged or CUTLASS ops from a source checkout now install `deepspeed-kernels` themselves (DeepSpeed-MII does this). ### AI assistance This change, its tests and this description were prepared with AI assistance (Claude), which also ran the tests above. 🤖 Generated with [Claude Code](https://claude.com/claude-code) --------- Signed-off-by: pengdurice <[email protected]> Co-authored-by: Claude Opus 5.5 <[email protected]>
Reword the call-site count in the comment so it does not go stale, and step a real ZeRO-1 bf16 engine with fp32 grad accumulation to check what muon_update is handed. Signed-off-by: Vineeth Sai <[email protected]>
|
@pengdurice thanks for the approval. Is anything else needed before this can be merged? |
Per-head Muon (#8384) is silently ignored on three of the six paths that call
muon_update, so the attention projections it tags are orthogonalized whole.deepspeed.initializetags each attention projection withmuon_num_headsand the call sites read it back off the parameter. Three do not: the padded branch of ZeRO 1/2get_flat_partition(its unpadded twin does),MuonWithAuxAdam.step, and the new BF16_Optimizer Muon support. The padded branch runs whenzero_optimization.parameter_alignmentis on and a parameter's size is off the alignment, so whether the feature takes effect turns on an unrelated setting, and the update stays finite either way. Forwardnum_headsat all three.Test:
TORCHDYNAMO_DISABLE=1 DS_ACCELERATOR=cpu PYTHONPATH=.:tests python -m pytest tests/unit/runtime/zero/test_per_head_muon.py -q. The new tests fail with the fix reverted and 80 pass after: a bf16 ZeRO 1 and 2 engine withparameter_alignment: truetakes a step on the padded branch and checksmuon_updategetsq_proj's head count; one stepsMuonWithAuxAdamon a tagged projection and asserts the applied update is the per-head one rather than the whole-matrix one (0.32 apart here); and one names any call site that drops the tag. yapf 0.43.0 and flake8 5.0.4 pass on the changed files. Executed on Apple M2 Pro CPU (single-rank engine); no GPU or multi-rank run.