Repository navigation
Conversation
jayhenry
added this pull request to stack #2112
September 23, 2026 06:54
This was referenced Sep 23, 2026
jayhenry
force-pushed
the
feat/glm53flash-f4-mhc
branch
from
October 8, 2026 10:12
8ffc8e2 to
34eafef
Compare
This was referenced Oct 8, 2026
jayhenry
commented
Oct 9, 2026
| assert state == ForwardState.TRAINING, "mHC-wrapped GLM-5.3-Flash decoder layers only support SFT training" | ||
|
|
||
| # ---- attention site: hidden_states is [B, S, hc_mult, hidden_size] | ||
| fn, scale, base = _unshard_hc_site(self, "attn") |
Collaborator
Author
There was a problem hiding this comment.
直接用 self.hc_attn_fn 等属性,不要这么隐晦地做
jayhenry
force-pushed
the
feat/glm53flash-f4-mhc
branch
from
October 9, 2026 06:32
34eafef to
6841448
Compare
This was referenced Oct 10, 2026
Adds xtuner/v1/module/decoder_layer/mhc.py (MHCConfig / hc_split_sinkhorn / hc_pre / hc_post / unshard_hc_params) and xtuner/v1/ops/hc_post.py (fused Triton hc_post_fused), following doc/xtuner_glm5p3flash_design.md F4. The core math is ported from xtuner's dsv4 branch (DeepSeek-V4's Hyper- Connections, commit 01c31a8, not merged into this branch) into the model-agnostic public location the design doc calls for, dropping V4's XTUNER_V4_HF_PARITY global toggle (the default bf16-fast path already degrades to HF-exact math under fp32 inputs, which the tests use as the parity anchor) and the unported 721-line TileKernels backend (left as a documented NotImplementedError gap rather than a blind port with no hardware to validate it against). Adds xtuner/v1/model/moe/glm53/decoder_layer.py: Glm53DenseDecoderLayer (overrides DenseDecoderLayer._forward) and Glm53MoEDecoderLayer, which only overrides MoEDecoderLayer's _pre_moe_forward/_post_moe_forward seams so the ~400-line EP/dispatcher/domino-micro-batch pipeline stays untouched; the mHC residual rides through those methods as an opaque _MHCResidual payload in place of the base class's plain Tensor. mhc_cfg=None degrades both layers to the base class's ordinary residual math unchanged, for reuse by the MTP layer in F6. Also fixes a real bug surfaced while testing: KDA's dt_bias/A_log were left torch.empty-uninitialized in xtuner/v1/module/attention/kda.py; now initialized to match HF's Glm5NextTextForgetGate _init_weights policy (A_log zeroed when a safe gate lower bound is set, dt_bias log-uniform). Verified with 26 tests across tests/model/test_glm53_mhc.py (Sinkhorn math + exact HF parity in fp32, bf16 parity within ULP tolerance), tests/ops/test_hc_post.py (fused kernel vs eager reference, forward/ backward/compile), and tests/model/test_glm53_decoder_layer.py (both decoder layers, mhc_cfg=None passthrough equivalence, gradient flow). Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
HF normalizes the flattened mHC streams with the text-config RMS epsilon, not the hyper-connection eps. The hc_pre norm_eps parameter existed but all four call sites relied on the 1e-6 default, so checkpoint gradients drifted from HF. Pass input/post-attention layernorm variance_epsilon at each site; the five-layer crop gradient oracle now agrees with HF within 5%.
The build-only MoE test compiled shared decoder class methods globally and made later GLM-5.3 cases fail by test order. Disable compilation for that constructor check. Move the dynamic cu_seqlens compile case to F6, where the KDA custom-op boundary is implemented.
jayhenry
force-pushed
the
feat/glm53flash-f4-mhc
branch
from
October 10, 2026 19:01
6841448 to
b245bb8
Compare
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.
Stack (bottom to top):
feat/glm53flash-materialize-full-f0→mainfeat/glm53flash-f3-kda→feat/glm53flash-materialize-full-f0feat/glm53flash-f4-mhc→feat/glm53flash-f3-kda← you are herefeat/glm53flash-f5-nope-dsa→feat/glm53flash-f4-mhcfeat/glm53flash-f1-vl-data→feat/glm53flash-f5-nope-dsafeat/glm53flash-f2-vision-tower→feat/glm53flash-f1-vl-datafeat/glm53flash-f6-text-moe→feat/glm53flash-f2-vision-towerSummary
Stack layer 3/7 of GLM-5.3-Flash support (base: layer 2, F3 KDA).
Adds
xtuner/v1/module/decoder_layer/mhc.py(MHCConfig/hc_split_sinkhorn/hc_pre/hc_post/unshard_hc_params) andxtuner/v1/ops/hc_post.py(fused Tritonhc_post_fused), perdoc/xtuner_glm5p3flash_design.mdF4. The core math is ported from xtuner'sdsv4branch (DeepSeek-V4's Hyper-Connections) into the model-agnostic public location the design doc calls for, dropping V4'sXTUNER_V4_HF_PARITYglobal toggle and the unported 721-line TileKernels backend (left as a documentedNotImplementedErrorgap rather than a blind, unvalidated port).Adds
xtuner/v1/model/moe/glm53/decoder_layer.py:Glm53DenseDecoderLayer/Glm53MoEDecoderLayer, which only override the pre/post-forward seams so the existing EP/dispatcher/domino-micro-batch pipeline stays untouched — the mHC residual rides through as an opaque_MHCResidualpayload in place of a plainTensor.mhc_cfg=Nonedegrades both layers to ordinary residual math unchanged, for reuse by the MTP layer later in the stack.Also fixes a real bug surfaced while testing: KDA's
dt_bias/A_logwere lefttorch.empty-uninitialized; now initialized to match HF'sGlm5NextTextForgetGate._init_weightspolicy.Test Plan
26 tests across
tests/model/test_glm53_mhc.py(Sinkhorn math + exact HF parity in fp32, bf16 parity within ULP tolerance),tests/ops/test_hc_post.py(fused kernel vs eager reference, forward/backward/compile), andtests/model/test_glm53_decoder_layer.py(both decoder layers,mhc_cfg=Nonepassthrough equivalence, gradient flow).