Repository navigation
[3/6] feat(draft): residual hooks with Qwen GR and DeepSeek-V4.1 mHC - #1027
Open
maocheng23 wants to merge 1 commit into
Open
maocheng23 wants to merge 1 commit into
maocheng23 wants to merge 1 commit into
Conversation
maocheng23
requested review from
FlamingoPg,
FrankLeeeee,
shuaills and
sleepcoo
as code owners
October 27, 2026 20:42
This was referenced Oct 27, 2026
Split from #1023. DecoderLayer (and DFlash2's convolution decoder) read and write the residual stream through Residual modules: - residual/standard.py: the existing pre-norm add; parameter-free, so default checkpoints, parameter order and numerics are unchanged (parity test still bit-exact) - residual/gr.py: Qwen3.8-Flash-Next gated residual (per-branch Gemma RMSNorm, low-rank gated read, gated write, learned final readout) - residual/mhc.py: DeepSeek-V4.1 single-pass mHC (lagged pre-mix, FP32 coefficients and Sinkhorn, stream-zero initial read) Opt-in via draft_residual in the DFlash-family config. Non-standard residuals force non-reentrant gradient checkpointing and record their non-parameter semantics in the DFlash/Domino/DSpark resume contracts. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
maocheng23
force-pushed
the
maocheng/pr1023-2-attention
branch
from
October 27, 2026 20:45
1edd72f to
e237fc8
Compare
maocheng23
force-pushed
the
maocheng/pr1023-3-residual
branch
from
October 27, 2026 20:45
87551e0 to
33ca045
Compare
Contributor
|
To support the DeepSeek-V4 MoE DSpark draft, we need the mHC variant (own pre-mix, learned hc_head). Refer to #1068 if you want to support the DeepSeek-V4 MoE DSpark draft as well now. |
This branch has not been deployed
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
This PR adds opt-in residual architectures for DFlash-family drafts: Qwen3.8-Flash-Next gated residual (GR) and DeepSeek-V4.1 single-pass mHC. They are selected by config, not by duplicating draft models.
Modifications
layers/residual/:StandardResidualis the existing pre-norm add, parameter-free.GatedResidualprovides per-branch Gemma RMSNorm, a low-rank gated read, a gated write, and a learned final readout.ManifoldHyperConnectionimplements the lagged pre-mix, FP32 coefficients with Sinkhorn, and a stream-zero first read.DecoderLayerand the DFlash2 decoder read and write throughattention_residualandffn_residual. The DFlash model expands streams at the input and collapses them (mHC) or reads them out (GR) at the head.draft_residualin the HF draft config selects the kind; omitting it keeps the standard layout.Difference from #1023: the EAGLE3 decoder no longer gets always-standard residual modules, since there's no config path for them there.
Reference check (review)
The math matches SGLang:
layers/hyperconnection.py:GatedResidualwithhc_per_branch_norm=True, as used byqwen4_exp.py.models/deepseek_v4_mhc.py: the pre-mix computed at one hyper-connection is consumed by the next, the first read uses stream 0, and the head combines with the last pre-mix (hc_pre_from_prev_sublayer).Open items for discussion
Not servable yet. Parameter names and layouts differ from SGLang/DeepSeek:
[count, hidden]norm_weight; SGLang uses a flathc_norm.weight.mix_weight/mix_scale/mix_bias; DeepSeek useshc_attn_fn/scale/baseand thehc_ffn_*equivalents.Either align the names or add an exporter before training drafts with these.
FSDP1 casts the mHC "FP32" parameters to bf16.
MixedPrecision(param_dtype=bf16)applies to them, so the FP32 coefficient path runs on bf16-rounded weights. DeepSeek keepshc_*in FP32.Initialization lives outside HF's hooks.
ManifoldHyperConnectionbuildsmix_weightwithtorch.emptyand initializes it in__init__, which HF's_init_weightsdoesn't cover. Loading a checkpoint that lacks these keys throughfrom_pretrainedmay leave them uninitialized.Accuracy Test
test_residual.py(from Refactor draft layers and add GR/mHC residuals #1023): GR/mHC reference forward/backward, save/load, checkpointing, plus CUDA BF16 cases that are skipped without a GPU.StandardResidual, the parity test from the previous PR stays bit-exact.tests/test_modelingon CPU: 182 tests, 24 skipped. The only errors are the 4 env-only import errors.Stack
This is part of a split of #1023 (by @jiapingW) into reviewable layers. Each PR targets the branch of the previous one, and only its own commits show in the diff.
The code is @jiapingW's from #1023 (commits are authored by them). The split adds a parity test, legacy import shims, and two fixes in the visibility PR, each noted in the PR it belongs to.
🤖 Generated with Claude Code