Skip to content

AutoEP: one program per token in the fused weighted restore forward - #8678

Merged
tohtana merged 2 commits into
deepspeedai:masterfrom
yh0903:yh0903/autoep-restore-whole-row
Sep 29, 2026
Merged

tohtana merged 2 commits into
deepspeedai:masterfrom
yh0903:yh0903/autoep-restore-whole-row

Conversation

@yh0903

@yh0903 yh0903 commented Sep 26, 2026 •

Copy link
Copy Markdown
Contributor

Summary

  • Keep combine_impl="fused_weighted_sum" opt-in and change only its forward scheduling: one Triton program handles a whole token, walking the hidden dimension in up to 1024-column chunks instead of launching a program per token and 256-column tile. The backward kernel and its row/score gradients are unchanged.
  • Preserve the existing routing, expert reorder, collectives, grouped GEMM and top-k semantics. The default combine path is unaffected.

Numerical contract

  • Each row value and routing score are multiplied in FP32, the top-k products accumulate in FP32 in a fixed slot order, and the output is cast to the row dtype once. FP contraction is disabled so the product rounds before addition. Hidden-tail loads/stores are masked; non-power-of-two top-k requires no padded loads; token and source-row address arithmetic uses int64.
  • Not bitwise unchanged versus eager: eager's top-k reduction may sum FP32 products in a different order. The existing operator and model parity tolerances are unchanged; repeated fused calls are deterministic on fixed inputs. The backward implementation is unchanged.
  • Measured step-0 loss was 13.237928 → 13.237917 at 8k and 13.276934 → 13.276920 at 16k. These are step-0 observations, not upper bounds on differences at later training steps. No long-run convergence claim is made.

Testing Done

  • Previously validated on NVIDIA H100: 241 passed, including fused restore and AutoEP unit coverage. The operator tests compare forward, row gradients and routing-score gradients against the eager weighted sum. Existing separate model parity tests cover gradients through the router and experts; they were not rerun here. The wide-hidden test covers 2048 columns and a 1030-column tail with top-k 6, plus repeated-run determinism.
  • New focused FP32 cancellation case: 1 passed, 0 skipped on one NVIDIA H100 80GB HBM3 (torch 2.10, CUDA 13.0, Triton 3.6). It checks that the product is rounded before it is added, including a non-power-of-two top-k and a 1030-column hidden tail. As a negative control, allowing FP contraction makes this same case fail. The negative-control change is not in this PR; existing tolerances were not relaxed.
  • Changed-files pre-commit checks passed.

Performance and attribution

Within the same NVIDIA H100 allocation, at top-k 8 and hidden 2048, the restore forward fell from about 0.60 → 0.105 ms per call at 8k tokens, and 1.20 → 0.20 ms at 16k. The complete AutoEP native-path old/new comparison (two repeats per arm, identical setup apart from this forward change) is the primary E2E evidence:

Sequence AutoEP before AutoEP after Difference
8192 2547.53 ms 2500.44 ms −47.1 ms (−1.85%)
16384 5244.91 ms 5145.86 ms −99.1 ms (−1.89%)

Peak allocated and reserved memory did not increase. On this allocation, the remaining AutoEP/Megatron step-time gaps were about 0.43%/0.61% at 8k/16k; those numbers are context, not evidence that Transformer Engine's unpermute has identical semantics. Its unpermute does not apply the routing weights, so no direct kernel-to-kernel speedup is claimed.

This PR's code is independent of #8671 and changes different files. The reported E2E baseline already includes #8671's gather-based reorder, so those timings should not be compared with runs that omit it. No new full E2E or convergence run was required for this focused forward review.

🤖 Generated with GitHub Copilot CLI

The forward ran one program per token and 256-column hidden tile, 65536
programs at 8192 tokens, each reducing an [8, 256] tile; it reached about a
fifth of memory bandwidth. One program now walks a whole token's hidden width
and adds its top-k rows in slot order, each as its FP32 product with the
score, without FP contraction. The backward is unchanged.

Co-authored-by: Copilot <[email protected]>
Signed-off-by: yh0903 <[email protected]>
@tohtana tohtana mentioned this pull request Sep 27, 2026
10 of 22 tasks
Describe the whole-token hidden traversal and slot-order FP32 sum without claiming bitwise eager parity. Add a small FP32 cancellation case that detects contracted multiply-adds across a non-power-of-two top-k and a hidden tail, leaving the kernel and existing tolerances unchanged.

Co-authored-by: Copilot <[email protected]>
Signed-off-by: yh0903 <[email protected]>
@yh0903
yh0903 marked this pull request as ready for review September 27, 2026 02:42
@hwchen2017
hwchen2017 requested a balanced review from Copilot September 29, 2026 03:33

Copilot AI 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.

Copilot review overview

🟢 Approval recommended

The focused kernel change is consistent with its documented contract and is covered by targeted numerical and shape tests.

Review effort: Balanced
Findings: None

What changed in this PR

Optimizes the opt-in fused AutoEP restore forward kernel by assigning one Triton program per token while preserving numerical and backward behavior.

Changes:

  • Processes hidden dimensions in chunks up to 1024 columns.
  • Disables FP contraction and accumulates top-k products in fixed slot order.
  • Adds wide-hidden, tail, determinism, and FP32-rounding tests and documentation.
File Description
deepspeed/​ops/​triton_ops/​autoep_fused_token_ops.py Implements token-scoped forward scheduling.
tests/​unit/​v1/​ops/​triton_ops/​test_autoep_fused_token_ops.py Adds correctness and determinism coverage.
docs/​code-docs/​source/​autoep.rst Documents scheduling and numerical semantics.

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

@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 to me, thank you!

@tohtana
tohtana enabled auto-merge September 29, 2026 06:04
@tohtana
tohtana added this pull request to the merge queue Sep 29, 2026
@github-merge-queue
github-merge-queue Bot removed this pull request from the merge queue due to failed status checks Sep 29, 2026
@tohtana
tohtana added this pull request to the merge queue Sep 29, 2026
Merged via the queue into deepspeedai:master with commit 11b24d2 Sep 29, 2026
17 of 21 checks passed
@tohtana tohtana added needs-gpu-test GPU testing is recommended to validate the changes in this PR. and removed needs-gpu-test GPU testing is recommended to validate the changes in this PR. labels Nov 10, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants