fix(deepseek_v4): contract mHC comb on the column-normalised axis - #1040
Open
yuankaichen-amd wants to merge 4 commits into
Open
fix(deepseek_v4): contract mHC comb on the column-normalised axis#1040yuankaichen-amd wants to merge 4 commits into
yuankaichen-amd wants to merge 4 commits into
Conversation
HyperMixer.expand computed matmul(comb, x), contracting comb's second index, while the DeepSeek-V4 inference kernels (SGLang hc_post and its tilelang mhc_post) contract the first. sinkhorn_normalize ends on a column normalisation, so comb's columns sum to 1 while its rows sum to 0.93-1.07; contracting the second index therefore leaves each output stream carrying the row mass rather than 1. The two conventions differ by 5.5% per call on real layer-0 weights, and expand runs twice per layer, so the error compounds with depth: on an 8-layer DeepSeek-V4-Flash proxy the residual stream diverged from SGLang by 13.3% at layer 0 and 30.9% at layer 7. Transposing comb makes the eager and Triton paths agree with the inference kernel to bf16 noise (5.5e-2 -> 9e-4) and cuts trainer-vs-engine KL on sampled sequences from 0.265 to 0.148 nats/token.
yuankaichen-amd
requested review from
Xiaoming-AMD,
limou102 and
wenxie-amd
as code owners
August 25, 2026 19:32
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.
HyperMixer.expand computed matmul(comb, x), contracting comb's second index, while the DeepSeek-V4 inference kernels (SGLang hc_post and its tilelang mhc_post) contract the first. sinkhorn_normalize ends on a column normalisation, so comb's columns sum to 1 while its rows sum to 0.93-1.07; contracting the second index therefore leaves each output stream carrying the row mass rather than 1.
Link to SGLang implementation: https://github.com/sgl-project/sglang/blob/7ddf92d5f481e79abd6db4f6c28dd27641fd2a7e/python/sglang/srt/models/deepseek_v4.py#L2041-L2048
The two conventions differ by 5.5% per call on real layer-0 weights, and expand runs twice per layer, so the error compounds with depth: on an 8-layer DeepSeek-V4-Flash proxy the residual stream diverged from SGLang by 13.3% at layer 0 and 30.9% at layer 7. Transposing comb makes the eager and Triton paths agree with the inference kernel to bf16 noise (5.5e-2 -> 9e-4) and cuts trainer-vs-engine KL on sampled sequences from 0.265 to 0.148 nats/token.