mhc: allow a model to supply its own output contraction (hc_head_contraction spec slot) - #89
Open
Zhichenzzz wants to merge 1 commit into
Open
mhc: allow a model to supply its own output contraction (hc_head_contraction spec slot)#89Zhichenzzz wants to merge 1 commit into
Zhichenzzz wants to merge 1 commit into
Conversation
TransformerBlock's mHC output contraction was fixed to DeepSeek-V4's:
learned_output_contract over three block-owned parameters, projecting to a
per-stream scalar, summing over streams, and taking one RMS across the whole
n*C vector. A model whose hyper-connections contract differently had no way in.
Both the parameter allocation and the call are inside TransformerBlock, and
GPTModel constructs TransformerBlock directly, so there was no seam short of
monkeypatching the module-level function.
Adds TransformerBlockSubmodules.hc_head_contraction: a module that owns its own
parameters and is called as module(hidden_states). Qwen3.8-Next needs it -- its
contraction is the same low-rank gated mean as its per-layer hyper-connections
(sglang builds both from one GatedResidual class), with the RMS taken per stream.
Strictly opt-in. Leaving the field None keeps the existing code path verbatim,
parameter names included, so checkpoints keyed on decoder.hc_head_{fn,base,scale}
load unchanged -- moving those into a submodule unconditionally would have
renamed them out from under every existing mHC checkpoint.
This was referenced Aug 27, 2026
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.
Adds an
hc_head_contractionModuleSpec slot so a model can supply its own output contraction for hyper-connection layers, instead of being locked to the built-in mHClearned_output_contract.Qwen3.8-Flash-Next (Qwen4Exp) shares mHC's structure (widen at block input, per-layer working vector, write-back to every stream) but gates differently: a low-rank two-matrix SiLU read gate with a mean over streams, and no
h_resSinkhorn mixing. With this slot, miles builds it as a uniform GPT stack with zero further Megatron changes (miles PR: radixark/miles#2777).Backward compatible: when the slot is not set, behavior and checkpoint layout are unchanged — existing mHC checkpoints load as before. +51/-20 in transformer_block.py / spec plumbing.