Repository navigation
Conversation
ormandj
requested review from
BBuf,
DarkSharpness,
HaiShaw,
HydraQYH,
celve and
yuan-luo
as code owners
October 7, 2026 03:10
ormandj
force-pushed
the
mhc-mix-vec-reduce
branch
from
October 7, 2026 05:42
6dc0988 to
d57e9f7
Compare
17 of 56 tasks
…, 160 K slices for SM120 decode On SM120, hc_mix_stats_sinkhorn reduces its K-slice partials with one tl.sum over a [slices, cols] tile instead of a serial per-slice loop in a single-warp CTA per row; the tree depends only on the slice count, so results stay deterministic and batch-invariant. Other GPUs keep the serial reduce. On SM120 (188-SM RTX PRO 6000), decode and target-verify forward passes split K=20480 into 160 slices instead of 80: one row tile otherwise leaves most SMs idle at decode sizes. Prefill, which does not benefit, keeps 80. The slice count depends on K, the device and the forward mode, never on M.
…g from the layer Run the batch-invariance test as SM100 and SM120 on any host GPU, checking the reducer and slice count, with subsets that cross the 8/16/32 row tiles. Add a CPU test that decode, idle and target-verify forwards pass decode=True to hc_mix_stats_sinkhorn for both hyper-connections and prefill modes do not. Say that 160 slices are limited to the measured decode/verify mode.
A decode row can run in a DECODE batch (160 slices on SM120) or beside prefill rows in a MIXED batch (80), so with batch-invariant mode enabled hc_mix_stats_sinkhorn always gets decode=False, as the compensated projections already honor that mode. Test that every forward mode then selects the same slice count.
ormandj
force-pushed
the
mhc-mix-vec-reduce
branch
from
October 29, 2026 22:19
d57e9f7 to
74c736c
Compare
6 tasks done
Contributor
|
Thanks @ormandj. Closing this because you have 25 PRs open and none updated in 7 days, over our soft cap of 5 for idle PRs. Reopen the two or three you most want reviewed - a short active set moves faster than a long idle one. Some directories moved recently, so an older branch may need retargeting: |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Motivation
hc_mix_stats_sinkhornis the CUDA Triton path for DeepSeek-V4.x mHC mixing statistics and Sinkhorn, run twice per layer. It is used at every row count on SM120, on SM100 when the DeepGEMM prenorm GEMM is not used (including below 128 rows), and on SM90 at one row. It has two launches:_hc_mix_stats_partial_kernel: one CTA per (row tile, K slice). K=20480 is split into 80 slices._hc_mix_reduce_sinkhorn_kernel: one single-warp CTA per row, which adds the 80 slice partials in a serialstatic_rangeloop before the Sinkhorn.At decode sizes the serial loop takes about as long as the partial kernel. With one row tile, 80 CTAs also occupy fewer than half of the 188 SMs on an RTX PRO 6000.
Modifications
_hc_mix_reduce_sinkhorn_vec_kernel: loads the partials as one[slices, cols]tile and reduces them withtl.sum, then runs the unchanged Sinkhorn. There is still one CTA per row, and the reduction tree depends only on the slice count, so results are deterministic and batch-invariant. The summation order differs from the serial loop.hc_mix_stats_sinkhornuses it on SM120 (compute capability 12.0), where it was measured; other GPUs keep the serial reducer, so their results are unchanged. The bf16x3 and DeepGEMM paths keep the serial reducer with 16 slices; DeepGEMM also keeps its residual input.hc_mix_stats_sinkhorn(..., decode=False): withdecode=Trueon SM120 (compute capability 12.0 only), it splits K into 160 slices when the number of 64-wide K blocks is a multiple of 160.DeepseekV4DecoderLayer.forward_hc_pre_from_prevsetsdecodefor decode/idle and target-verify forward passes and passes it throughmhc.run_attn_post/run_moe_post,_compute_triplet,mix_statsand_mix_stats_impltohc_mix_stats_sinkhorn. Each newdecodeparameter defaults to False. Prefill/extend, other callers (including the DSpark draft layer, which callsmix_statsdirectly), other GPUs, and the unfusedhc_mix_statskeep the existing choice (80 for K=20480). The slice count depends on K, the device, and the forward mode, never on M. A row therefore gets the same bits at any batch size within decode/verify on this backend, and likewise within prefill. A decode row can also run beside prefill rows in a MIXED batch, which takes the prefill split, so with batch-invariant mode enabled (--enable-deterministic-inference)_mix_stats_implpassesdecode=Falsein every mode, as it already disables the compensated projections in that mode.Accuracy Tests
New
test_hc_mix_stats_sinkhorn.py(GPU) andtest_deepseek_v4_mhc_decode_split.py(CPU). With this branch head'smhc.pyand tests, all 23 tests intest_hc_mix_stats_sinkhorn.pypassed on an RTX PRO 6000 Blackwell (SM120), and the 4 tests intest_deepseek_v4_mhc_decode_split.pypassed on CPU. I have not run the ported model code end to end on a GPU (deepseek_v4.py,deepseek_v4_mhc.pyon current main). The tests cover:hc_mix_stats(serial sum, 80 slices at K=20480) followed by the Sinkhorn within rtol 1e-5 / atol 1e-6. It also matches FP64 mixing statistics followed by the FP32 Sinkhorn within rtol 1e-4 / atol 1e-5.forward_hc_pre_from_prev, posts andmix_statspassdecode=Truetohc_mix_stats_sinkhornfor both hyper-connections in decode, idle and target-verify forward passes, anddecode=Falsein extend, mixed, draft-extend and split-prefill passes. With batch-invariant mode enabled, every forward mode passesdecode=False, so decode and MIXED batches select the same slice count (80 on SM120). A directmix_statscall defaults todecode=False.On 2026-10-29 this branch was rebased onto main
974831643f, where the boundary read (HcReadCall.read) records the decode flag andHcUpdate.postpasses it to the posts; on the new head the 4 CPU tests intest_deepseek_v4_mhc_decode_split.py(now drivingHcReadCall.readandHcUpdate.post) pass, and the SM120 GPU results in this description are from the previous head and will be re-run.Speed Tests and Profiling
Per call (partial + reduce/Sinkhorn,
us) on one RTX PRO 6000 Blackwell Max-Q Workstation Edition (SM120, 188 SMs, 250 W power limit, used only by the benchmark), torch 2.14.1+cu130, Triton 3.8.0. Inputs are BF16[M, 20480]. Each CUDA graph covers 24 distinct[24, 20480]FP32 weights at M <= 64 and 4 weights above; the time is the best of 20 graph replays divided by the number of calls. Columns:hc_mix_stats_sinkhornfrom the base commit'smhc.py(serial reduce, 80 slices);decode=False: this PR'smhc.py(vectorized reduce, 80 slices);decode=True: this PR'smhc.py(vectorized reduce, 160 slices, the SM120 decode/verify setting);pre,postandcomboutputs betweendecode=Trueand main, for the first weight.decode=Falsedecode=TrueWith 80 slices, the vectorized reduce lowers latency by 8-23% versus main at every M measured. With 160 slices, latency is a further 15-18% lower up to 16 rows (26-35% lower than main) and 6% lower at 32 rows. At 48-256 rows, 160 slices changes latency by -5% to +5% relative to 80 slices (these sizes occur in large verify batches) and is 4-16% lower than main.
I measured the following with the same kernel change on my branch before the port onto #42245, and have not repeated them on this port.
DeepSeek-V4.1-Flash on 4x RTX PRO 6000 Blackwell (PCIe), TP4/EP2, DSpark speculative decoding:
160 slices is limited to SM120 decode/verify, the only architecture and mode where I measured it; I have no same-build prefill A/B, so prefill keeps 80 slices.
Checklist
Review and Merge Process
/tag-and-rerun-ci,/tag-run-ci-label,/rerun-failed-ciDeveloped with AI assistance.
CI States
Latest PR Test (Base): ❌ Run #40964957784
Latest PR Test (Extra): ❌ Run #40964957689
Latest PR Test (AMD ROCm 10): ❌ Run #40964957549