Skip to content

Fix torch-latest workflow unit failures - #8950

Merged
tohtana merged 10 commits into
masterfrom
ci/fix-workflow-failures
Nov 4, 2026
Merged

tohtana merged 10 commits into
masterfrom
ci/fix-workflow-failures

Conversation

@sfc-gh-truwase

@sfc-gh-truwase sfc-gh-truwase commented Oct 30, 2026 •

Copy link
Copy Markdown
Collaborator

Summary

  • Run the workflow Python on 3.12 so transformers main can be installed. The Modal image was already 3.12; the runners and the AWS capacity fallback were still preparing 3.10.
  • Fix the unit failures those suites hit on current PyTorch and CUDA: stop forking pytest after CUDA is initialized, size the full-suite workers to the GPU count, and correct Gloo subgroups, fp-quantizer zeros, FP8 GEMM shared memory, ZeRO-3 linear autocast, AutoSP dead-code elimination, and CUDA synchronize.
  • Pin the Accelerate installer, and compare AutoEP fused parity with an fp32 reference so fp16 reassociation does not fail the test.

Test plan

mps-torch-latest stopped in the runner device check (no MPS device on this runner) before any unit test.

sfc-gh-truwase and others added 2 commits October 27, 2026 01:32
The Modal image was already 3.12, but the workflow runners and the AWS capacity fallback still prepared CPython 3.10, which cannot install transformers main.

Signed-off-by: Olatunji Ruwase <[email protected]>
Co-authored-by: Cursor <[email protected]>
Current PyTorch rejects forked CUDA tests, Gloo subgroup splits, and several kernels the suites still run.

Signed-off-by: Olatunji Ruwase <[email protected]>
Co-authored-by: Cursor <[email protected]>
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 30, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-10-30T01:53:02.091880Z 097ba64 PR opened
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 097ba64b81

ℹ️ About Codex in GitHub

Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

Comment thread csrc/fp_quantizer/fp_quantize.cpp Resolved
Comment thread deepspeed/comm/torch.py Resolved
sfc-gh-truwase and others added 2 commits October 30, 2026 12:16
Co-authored-by: Cursor <[email protected]>

# Conflicts:
#	ci/test_torch_latest.py
#	ci/torch_latest.py
@sfc-gh-truwase
sfc-gh-truwase requested a review from delock October 30, 2026 13:41
sfc-gh-truwase and others added 3 commits October 30, 2026 13:42
The full unit suite took 3h17 of pytest on 4x H200, and this job runs unit/v1 on slower L40S runners.

Signed-off-by: Olatunji Ruwase <[email protected]>
Co-authored-by: Cursor <[email protected]>

@ghost ghost left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I only looked at the Gloo subgroup change in deepspeed/comm/torch.py, not the rest of this PR.

The fix works, and the problem isn't limited to PyTorch 2.7–2.10. On torch 2.15 (CPU, gloo), init_process_group("gloo", device_id=torch.device("cpu:0")) followed by new_group([0]) on two ranks raises 'ProcessGroupGloo' object has no attribute 'perform_nocolor_split' on the non-member rank. With _ensure_gloo_subgroup_split() applied, three ranks build [0, 1] and [1, 2], all-reduce on each and on the world in between, and get 2 / 3 / 2. Without it, the non-member raises (seen with two ranks), and the three-rank run hangs.

Two suggestions:

  • The docstring says "PyTorch 2.7 through 2.10"; 2.15 is affected too, so the range could be dropped.
  • No unit test targets it directly, and the CPU job never binds a device, so CPU CI doesn't exercise it. Binding device_id=torch.device("cpu:0") reproduces the failure on CPU, so a small three-rank gloo test like the one above could cover it in the CPU job.

Optional: init_process_group passes device_id on the CUDA accelerator regardless of backend. Passing it only when CUDA tensors use NCCL would keep DeepSpeed-initialized gloo worlds off the split path entirely, leaving this patch as the fallback for externally initialized ones.

The B200 unit run failed in quantization, FP8 GEMM, and empty-expert gradients, and several workflows still targeted the dead V100 pool.

Co-authored-by: Cursor <[email protected]>
Signed-off-by: Olatunji Ruwase <[email protected]>
@sfc-gh-truwase
sfc-gh-truwase force-pushed the ci/fix-workflow-failures branch from 424c0ba to 57a27bb Compare November 2, 2026 16:40

@tohtana tohtana left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for the great improvement of CI!

As it increases the runtime, should we also revisit the job-level timeout-minutes: 180? I also left a comment regarding the change in EP.

Comment thread deepspeed/moe/ep_experts.py Outdated
@staticmethod
def backward(ctx, grad):
(active_experts, ) = ctx.saved_tensors
return grad.masked_fill(~active_experts, 0), None

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This causes a noticeable performance regression.
masked_fill creates a full-sized gradient copy for each of the three expert weights, even when all experts are active. In a BF16 grouped-MM benchmark on an RTX PRO 4500 Blackwell (8 experts, D=1024, H=4096, 128 rows per expert), median forward/backward time increased from 1.798 to 3.056 ms (+69.9%), and peak allocated memory increased from 464 to 518 MiB.
Maybe we can zero only the empty-expert slices without creating these full-gradient copies?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The out-of-place masked_fill is gone. When every expert has tokens, backward returns the grouped-GEMM gradient buffer unchanged. When some experts are empty, only those rows are zeroed in that buffer. aws-torch-latest-full is now timeout-minutes: 360, the same GitHub maximum as the unit/v1 job. The H200 full suite was about 3h54m of pytest before environment setup.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for the update!
The in-place masked_fill shows much better performance. It's around 10% slower then the original code.
We could accept it, but I also wonder if this might be caused by this issue. The commnt says a similar issue was resolved in PyTorch v2.10. If you used v2.9 or older, it might be be better to have a fallback rather than zeroing all the time.
If you used v2.10 or newer, let's leave it and merge.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, I used v2.10. I think 2.9 is boundary of DS support since 2.15 is out. If you are fine, please approve to unblock. Thanks!

masked_fill allocated a full gradient for each expert weight even when none were empty. The full-suite job also stays at 180 minutes after the longer unit/v1 run, so raise it to GitHub's maximum.

Signed-off-by: Olatunji Ruwase <[email protected]>
Co-authored-by: Cursor <[email protected]>

@tohtana tohtana left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good, thank you!

@tohtana
tohtana added this pull request to the merge queue Nov 4, 2026
Merged via the queue into master with commit a38957c Nov 4, 2026
17 checks passed
@tohtana
tohtana deleted the ci/fix-workflow-failures branch November 4, 2026 18:04
pengdurice added a commit to pengdurice/DeepSpeed that referenced this pull request Nov 6, 2026
Since deepspeedai#8950, modal-torch-latest runs `pip check` after installing
DeepSpeed, and the AWS capacity fallback has failed every time:

    deepspeed-kernels 0.0.1.dev1698255861 is not supported on this platform

The package has had no release since 2023-10, and the WHEEL metadata of
its only wheel says cp38-cp38-linux_x86_64.

Remove it from requirements-dev.txt instead of exempting it from
`pip check`, and drop the exemption. No active CI job uses it: the
inference-v2 kernel tests are deselected by tests/pytest.ini, and
nv-pre-compile-ops builds with DS_BUILD_CUTLASS_OPS=0 and
DS_BUILD_RAGGED_DEVICE_OPS=0. The inference-v2 op builders still link
its prebuilt libraries when it is installed (DeepSpeed-MII installs it).

Keep fetching the complete output tail when the prepare phase fails, so
the next prepare failure shows its error in the job log.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: pengdurice <[email protected]>
liuyun7345 added a commit to liuyun7345/DeepSpeed that referenced this pull request Nov 6, 2026
Prevent ZeroDivisionError and silent non-finite propagation at four
reported sites:

1. groups._ensure_divisibility: reject denominator == 0 before modulo
2. ThroughputTimer: reject non-positive steps_per_output at init and
   report-boundary time
3. inference_utils.ceil_div: reject divisor == 0
4. FP_Quantize.dequantize/selective_dequantize: reject zero/non-finite
   scales before 1/scale, at the shared front-end so every backend is
   covered

Adds accelerator-agnostic regression tests for each failure mode.

Picks up the inactive draft deepspeedai#7855. Fixes deepspeedai#7838.

Rebased onto master, resolving the overlap with deepspeedai#8950 in
deepspeed/ops/fp_quantizer/quantize.py and
tests/unit/ops/fp_quantizer/test_fp_quant.py: both sets of new tests
are kept, and the accidentally duplicated guard tests from the previous
head are deduplicated.

Co-authored-by: Cursor <[email protected]>
Signed-off-by: liuyun7345 <[email protected]>
xylian86 pushed a commit to xylian86/DeepSpeed that referenced this pull request Nov 7, 2026
…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]>
@tohtana tohtana added the needs-gpu-test GPU testing is recommended to validate the changes in this PR. label Nov 10, 2026
@tohtana tohtana removed the needs-gpu-test GPU testing is recommended to validate the changes in this PR. label Nov 14, 2026
weiji14 added a commit to regro-cf-autotick-bot/deepspeed-feedstock that referenced this pull request Nov 15, 2026
weiji14 added a commit to conda-forge/deepspeed-feedstock that referenced this pull request Nov 16, 2026
* updated v0.20.0

* MNT: Re-rendered with conda-smithy 2026.11.6 and conda-forge-pinning 2026.11.13.06.22.1

* Remove 0002-fp_quantizer-do-not-redeclare-template-parameter.patch

Patch based on deepspeedai/DeepSpeed#8808 probably superseded by deepspeedai/DeepSpeed#8950?

---------

Co-authored-by: Wei Ji <[email protected]>
banxingmjj pushed a commit to openanolis/DeepSpeed that referenced this pull request Nov 23, 2026
…folding (deepspeedai#8847)

# AutoEP: support `combine_impl="fused_weighted_sum"` with AutoEP+AutoTP
folding

**Part of:** deepspeedai#8672 (Q4 2026 roadmap), "Mixture-of-Expert (MoE) Training
Scaling and Kernel Development": "AutoEP Performance Optimization &
Parallel Folding (AutoEP + AutoTP)" (PoC @tohtana @pengdurice). Follows
deepspeedai#8670.

## Problem

`combine_impl="fused_weighted_sum"` was refused whenever
`tensor_parallel.autotp_size > 1`:

- `deepspeed/module_inject/auto_ep_config.py` (`validate_autoep_config`)
raised `ValueError`.
- `deepspeed/module_inject/auto_ep_layer.py`
(`set_deepspeed_parallelism`) raised the same error.

The reason was that the folded path restores tokens with its own
function, `restore_combined` in
`deepspeed/moe/ep_tp_dispatch.py`, and the fused kernel was only wired
into the unfolded path.

`restore_combined` works like this:

1. Each TP peer sends only part of the routed assignments to the experts
(`partition_assignments`).
2. After the experts, it all-gathers the rows, their token index, their
top-k slot and their routing weight over the
   TP group.
3. It casts the routing weights to the activation dtype, multiplies, and
adds the products with one `index_add_` per
   top-k slot, all in the activation dtype.

So under folding, users could not get the memory saving and the FP32
accumulation of the fused kernel, and the
folded restore did its arithmetic in bf16.

## Change

- New `restore_combined_fused` in `deepspeed/moe/ep_tp_dispatch.py`:
- It does the same differentiable all-gathers as `restore_combined` for
the rows and the routing weights, so the
`tp_size` gradient factor that the folded AVERAGE and EXPERT_TP_CANCEL
strategies cancel is unchanged.
- It all-gathers one flat index (`token * top_k + slot`) instead of the
token index and the slot separately.
- It keeps the routing weights in the router dtype, scatters them into
`[tokens, top_k]`, and calls the existing
    `fused_weighted_restore`. The kernel is unchanged.
- It raises a clear `RuntimeError` if the gathered rows do not cover
every (token, slot). The folded payload never
drops or pads assignments today, so this cannot trigger now; it protects
the kernel from reading an unset source
    row if capacity dropping is added later.
- `validate_coverage=True` runs the same coverage check as
`restore_combined`.
- `AutoEPMoELayer._forward` calls `restore_combined_fused` in the folded
branch when
`combine_impl == "fused_weighted_sum"`. The default (`"auto"` →
`"weighted_sum"`) still calls `restore_combined`.
- The two `autotp_size > 1` refusals are removed. The other fused
refusals stay: `expert_tensor_parallel_size > 1`,
DeepEP, `score_apply` other than `"post"`, and unsupported device or
dtype.
- Docs: `docs/code-docs/source/autoep.rst` describes the folded fused
restore and drops the refusal from the list;
`docs/_pages/config-json.md` drops the `autotp_size=1` requirement and
lists float32 among the accepted activation
  dtypes, as the kernel's check does.

## Tests

On master e35282b with this change, pytest 8.3.5:

| Test | What it checks | GPUs | torch 2.8.0+cu126 | torch 2.9.1+cu128 |
|---|---|---|---|---|
| `test_autoep_unit.py` (includes
`TestAutoEPConfig::test_fused_combine_accepts_folded_tensor_parallelism`,
was `..._rejects_...`) | the config is accepted with `tp_size=2`; no
other config change | up to 8 | 214 passed | not run |
| `test_autoep_autotp_dispatch.py` (includes
`test_restore_combined_fused_rejects_a_missing_assignment` and
`TestRestoreCombinedFusedTensorParallel`, fp32 and bf16 rows) | a
missing (token, slot) raises instead of reading an unset row; 2 TP peers
with different row counts, each back-propagating a different gradient:
the output is bitwise equal to the unpartitioned
`fused_weighted_restore`, and the row and score gradients, summed over
the peers, match the unpartitioned gradients | 0 and 2 | 12 passed | 12
passed |
|
`test_autoep_fused_parity.py::TestAutoEPFusedParityFoldedTensorParallel`
(ZeRO 0, 2 and 3, with and without activation checkpointing) | one
training step with TP 2 × EP 2: the loss, output, input gradient, every
parameter gradient and every parameter update of the fused run match the
default folded run | 4 | 6 passed | 6 passed |
| rest of `test_autoep_fused_parity.py` (master's cases) | unchanged |
1-2 | not run (they fail on torch 2.8 on master too, see below) | 17
passed |
| `test_autoep_fused_token_ops.py` | the kernel is unchanged | 1 | 63
passed | not run |
| `test_autoep_autotp_grad_parity.py` with `DEEPSPEED_RUN_H100_TESTS=1`
| no change to the default folded path | up to 8 | 20 passed | not run |
| `test_auto_ep_comm.py`, `test_autoep_autotp_folding_config.py` | other
uses of the combine and folding settings | up to 8 | 65 passed, 3
skipped, 6 failed (see below); 33 passed | not run |
| `test_autoep_expert_activation.py` | other uses of `combine_impl` |
1-2 | not run (stalls on torch 2.8 on master too, see below) | 96
passed, 12 skipped (a grouped path that needs CUDA tensors when Triton
is installed) |

Hardware: 1 node of 8 NVIDIA H100 80GB (driver 595.112.07); torch
2.8.0+cu126 with Triton 3.4.0, and torch
2.9.1+cu128. JIT-built ops used the CUDA 12.8 toolkit (`CUDA_HOME`).

Every failure and stall above also happens on master without this
change, and passes or does not occur on torch 2.9.1:

- `test_auto_ep_comm.py::TestSkipRecomputeCombine` (6 cases, added by
deepspeedai#8745) runs `torch._grouped_mm` on the CPU,
which torch 2.8 does not implement (`Could not run 'aten::_grouped_mm'
with arguments from the 'CPU' backend`); the
  same 6 fail on master e35282b.
- Master's 17 fp16 cases of `test_autoep_fused_parity.py`
(`TestAutoEPFusedParityExpertParallel` x 16,
`TestAutoEPFusedParityLocalExperts`) fail on torch 2.8 with
`RuntimeError: Expected mat_a to be BFloat16 matrix got
Half`, also on master 3fe2d95 without this change: torch 2.8's
`torch._grouped_mm` accepts only bf16, and these
  cases run in fp16 with grouped GEMM.
- On torch 2.8 the backward of `torch._grouped_mm` does not return for
some shapes when one expert receives no rows:

`test_autoep_expert_activation.py::TestFusedGateUp::test_matches_separate_with_skewed_and_empty_experts`
stalls
  there the same way on master 3fe2d95 without this change.

The folded test reads each parameter before and after the step. Under
ZeRO-3 a parameter holds only its partition, so
the test's `_parameters` helper now reads the full fp32 value of ZeRO-3
parameters (`safe_get_full_fp32_param`); in
these fp32 runs that is the parameter itself. Master's cases have no
ZeRO-3 parameters and are unaffected.

The end-to-end folded test runs in FP32, on `MockMoEOnlyTransformer`,
without grouped GEMM:

- FP32: the default folded restore rounds each product and each top-k
addition to the activation dtype. In fp16 the
two restores differ by 1 to 1.5 units in the last place of the MoE
output (about 1,600 in this model), which is more
than `PARITY_TOLERANCE` allows after the LM head. In FP32 the two
forward passes are bitwise equal. Since both paths
run in FP32, the folded test compares them directly; master's fp16 cases
are judged against an FP32 reference
  instead (deepspeedai#8950), which here would equal the default path.
- No attention: the key bias of `nn.MultiheadAttention` has a true
gradient of zero, so its computed gradient is
rounding noise, and Adam's first step turns that noise into ±lr. The
parameter-update check then fails by 2 × lr no
  matter which restore is used.
- No grouped GEMM: on torch 2.8, `torch._grouped_mm` accepts only bf16,
so the fp32 run would fail before reaching the
  restore.

`pre-commit run --files` passes on the changed files.

## Benchmark

One TP group of 2 H200 GPUs on one node. bf16 rows, FP32 routing
weights, random routing with distinct experts per
token. The hidden size, top-k and expert count are the MiniMax-M3 and
GLM-5.2 values. Memory is the peak above the
inputs. Time is one forward and backward, averaged over 10 runs after 3
warm-up runs, and includes the identical
partition step. Errors are against an FP64 reference. (Measured on
master 5f266e2; neither `ep_tp_dispatch.py` nor the kernel's
`fused_weighted_restore` has changed on master since.)

| Shape (tokens per TP group, top-k, experts, hidden) | Forward peak,
GiB (default → fused) | Backward peak, GiB | Time, ms | Output error,
relative L2 | Score gradient error, relative L2 |
|---|---|---|---|---|---|
| 8,192, 4, 128, 6144 (MiniMax-M3) | 1.22 → 0.75 | 1.59 → 0.84 | 13.3 →
7.4 | 3.58e-3 → 1.66e-3 | 2.35e-3 → 8.4e-8 |
| 32,768, 4, 128, 6144 (MiniMax-M3) | 4.88 → 3.00 | 6.38 → 3.38 | 41.1 →
21.0 | 3.57e-3 → 1.66e-3 | 2.34e-3 → 8.3e-8 |
| 8,192, 8, 256, 6144 (GLM-5.2) | 2.35 → 1.50 | 3.09 → 1.60 | 26.7 →
12.0 | 4.36e-3 → 1.66e-3 | 2.34e-3 → 8.6e-8 |
| 32,768, 8, 256, 6144 (GLM-5.2) | 9.39 → 6.01 | 12.38 → 6.38 | 91.9 →
38.8 | 4.36e-3 → 1.66e-3 | 2.35e-3 → 8.7e-8 |

The fused output error of 1.66e-3 is the rounding of the bf16 output
itself. The score gradient is the router
gradient; the default folded path computes it through bf16 weights, the
fused path in FP32.

Script: `bench_folded_restore.py` (run with `torchrun
--nproc_per_node=2`).

## Notes

- The default folded path and the fused path give close but not
bitwise-equal results, because the default path
  multiplies and adds in the activation dtype.
- AutoEP+AutoTP folding runs at ZeRO stages 0 to 3 on master (CPU
optimizer offload at ZeRO-3 since deepspeedai#8829); the
  end-to-end test covers ZeRO 0, 2 and 3.

## Duplicate check

Searched open pull requests on 2026-11-13 and again on 2026-11-17
("fused_weighted_sum", "AutoEP AutoTP folding", "folding universal"):
none
enables the fused combine under folding. deepspeedai#8829 (optimizer offload under
folding) and deepspeedai#8823 (clipping under folding)
are merged and change other parts of folding; deepspeedai#8745 and deepspeedai#8739 change the
DeepEP combine.

## AI assistance

This change, its tests and this description were prepared with AI
assistance (Claude).

---------

Signed-off-by: pengdurice <[email protected]>
Co-authored-by: Claude Opus 5.5 <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants