Skip to content

Fuse DSv3 router forward/backward - #5258

Draft
ydwu4 wants to merge 4 commits into
gh/ydwu4/23/basefrom
gh/ydwu4/23/head
Draft

ydwu4 wants to merge 4 commits into
gh/ydwu4/23/basefrom
gh/ydwu4/23/head

Conversation

@ydwu4

@ydwu4 ydwu4 commented Oct 10, 2026 •

Copy link
Copy Markdown
Contributor

Stack from ghstack (oldest at bottom):

Fuse sigmoid, grouped top-k, routing weights/map/counts, and score/routing
gradients. Preserve the native gate and auxiliary-loss boundaries.

Keep kernels, custom operators, autograd and override in one file, with
one CPU test file and one GPU test file.

Recorded GB300 FP32 [4096,256], native -> CuTeDSL:
Fwd 170.41 -> 13.06 us; Bwd 27.08 -> 3.52 us; F+B 193.87 -> 15.75 us.
Bitwise checks pass; roofline acceptance remains open. Requires CuTeDSL 4.8+.

[ghstack-poisoned]
@pytorch-bot pytorch-bot Bot added the ciflow/fake-pg Run 1-GPU Fake PG integration tests label Oct 10, 2026
@meta-cla meta-cla Bot added the CLA Signed This label is managed by the Meta Open Source bot. label Oct 10, 2026
@ydwu4 ydwu4 changed the title Add an opt-in DeepSeek V3 router autograd override Fuse DSv3 router and auxiliary loss forward/backward Oct 10, 2026
@ydwu4
ydwu4 marked this pull request as draft October 10, 2026 04:02
@pytorch-bot pytorch-bot Bot removed the ciflow/fake-pg Run 1-GPU Fake PG integration tests label Oct 10, 2026
ydwu4 added 2 commits October 9, 2026 22:37
[ghstack-poisoned]
[ghstack-poisoned]
@ydwu4 ydwu4 changed the title Fuse DSv3 router and auxiliary loss forward/backward Fuse DSv3 router forward/backward Oct 10, 2026
[ghstack-poisoned]
sanketpurandare added a commit that referenced this pull request Oct 20, 2026
## Agent details (AI-generated)

Adapted from Yidi Wu (@ydwu4), #5258, revision
a5d8990, with original credit and license
preserved. This is an integration and generalization, not an unmodified port.

Keep the gate native and fuse sigmoid, group-limited top-k, routing weights,
map/usage counts and backward. Preserve NVIDIA's BF16 logit/selected-weight
boundaries and independent BF16 rounding for route and auxiliary score
gradients. Forced round-robin remains an explicit benchmark deviation.

Accept general legal token/expert/top-k/group dimensions with parameterized
Triton kernels. Preserve the tuned CuTe launch for the production geometry.
Match ATen's FP32 reduction order, including output-major upstreams, four
virtual-thread accumulators and unaligned vector tails. Use fresh integer
counts in the general path rather than a shape-dependent shared-counter budget.
Keep padding, remat, rank-local counters, checkpoint parameters and native
auxiliary-loss composition. Required unsupported precision/mesh/device
contracts fail explicitly; supported shapes stay fused.

## Test Plan (AI-generated)

python -m pytest tests/unit_tests/cpu/test_fused_dsv3_router.py tests/unit_tests/gpu/test_fused_dsv3_router.py -q
pre-commit run --all-files

40 CPU/GPU tests passed, including original tuned-path cases, exact general
FP32/BF16 gradients, forced routing, transposed gradients, unaligned top-129
tails, FakeTensor metadata, fullgraph compilation and CUDA capture/replay.
Strict owning documentation rendering passed. All non-type lint hooks passed;
only unchanged baseline type findings remained.

Matched GB300 graph-replay F+B, excluding the common gate GEMM: the production
path measured 28.7795us versus 28.7770us before (0.009%, within trial spread).
General cases outperformed the same native reference: E64/K6/T8193 8.114x,
E512/K8/T4097 6.633x, and E512/K129/T17 4.288x. Seed14536; three trials of
50 replays, with separate eager GPU trace collection and exact reference checks.
These are kernel results, not distributed throughput or convergence claims.
Full updated PP2/PP4 composition and expanded memory accounting remain pending.
sanketpurandare added a commit that referenced this pull request Oct 23, 2026
## Agent details (AI-generated)

Adapted from Yidi Wu (@ydwu4), #5258, revision
a5d8990, with original credit and license
preserved. This is an integration and generalization, not an unmodified port.

Keep the gate native and fuse sigmoid, group-limited top-k, routing weights,
map/usage counts and backward. Preserve NVIDIA's BF16 logit/selected-weight
boundaries and independent BF16 rounding for route and auxiliary score
gradients. Forced round-robin remains an explicit benchmark deviation.

Accept general legal token/expert/top-k/group dimensions with parameterized
Triton kernels. Preserve the tuned CuTe launch for the production geometry.
Match ATen's FP32 reduction order, including output-major upstreams, four
virtual-thread accumulators and unaligned vector tails. Use fresh integer
counts in the general path rather than a shape-dependent shared-counter budget.
Keep padding, remat, rank-local counters, checkpoint parameters and native
auxiliary-loss composition. Required unsupported precision/mesh/device
contracts fail explicitly; supported shapes stay fused.

## Test Plan (AI-generated)

python -m pytest tests/unit_tests/cpu/test_fused_dsv3_router.py tests/unit_tests/gpu/test_fused_dsv3_router.py -q
pre-commit run --all-files

40 CPU/GPU tests passed, including original tuned-path cases, exact general
FP32/BF16 gradients, forced routing, transposed gradients, unaligned top-129
tails, FakeTensor metadata, fullgraph compilation and CUDA capture/replay.
Strict owning documentation rendering passed. All non-type lint hooks passed;
only unchanged baseline type findings remained.

Matched GB300 graph-replay F+B, excluding the common gate GEMM: the production
path measured 28.7795us versus 28.7770us before (0.009%, within trial spread).
General cases outperformed the same native reference: E64/K6/T8193 8.114x,
E512/K8/T4097 6.633x, and E512/K129/T17 4.288x. Seed14536; three trials of
50 replays, with separate eager GPU trace collection and exact reference checks.
These are kernel results, not distributed throughput or convergence claims.
Full updated PP2/PP4 composition and expanded memory accounting remain pending.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

CLA Signed This label is managed by the Meta Open Source bot.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant