Repository navigation
feat(glm): carry native full-MTP alignment and source loading - #3610
Merged
Qubitium merged 1 commit intoNov 9, 2026
Merged
Conversation
Extract the existing working fork feature for first maintainer feedback. Preserve carried code and tests; limit validation to lightweight structural checks. See the linked mechanism reference for actual API/call and failure paths.
Qubitium
force-pushed
the
upstream/30-glm-native-mtp-20261108
branch
from
November 9, 2026 09:54
edf9295 to
dd9871d
Compare
Qubitium
reviewed
Nov 9, 2026
Qubitium
left a comment
Collaborator
There was a problem hiding this comment.
Reviewed against current main.
The full-GLM MTP envelope matches the documented contract:
aligned_inputsformsS-1pairs strictly within each prompt (token[t]withtoken[t+1]), applies the target final norm exactly once for the defaultpre_final_normtap, rejects a second norm forpost_final_norm, and zeroes the position-zero embedding beforeenormas the native path does. It validates frontier/token shape, dtype, device, vocabulary range, and consecutive nonnegative positions.GlmMTP.envelopeconcatenatesenorm(embedding) || hnorm(target)so K4 capture follows the same norm boundary as the decoder, andforward_alignedruns the block with its own full DSA indexer (prev_topk_indices=None) and appliesshared_head.normexactly once before the shared head.load_mtprequires exactly one native prediction layer, extends only the three GLM schedules with the MTP entry, loads the layer plusenorm/hnorm/eh_proj/shared_head.normas BF16 with strict geometry, and closes the source reader.- Tests cover envelope order, single final norm, per-prompt shifted pairs, schedule extension, extra-weight loading, prediction-depth rejection, and CUDA dtype/alignment at 128/6144.
Cleanup only: import ordering and one dict(...) → literal in the test.
Validation: ruff check clean; pytest tests/test_glm5_mtp.py reports 24 passed.
Qubitium
marked this pull request as ready for review
November 9, 2026 09:54
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.
Summary
Carry teacher-forced token/frontier alignment, the native MTP block and RMSNorm, optional expert loading, and shared embedding/head behavior through the explicit source adapter.
This is layer 30/36, extracted from an already-used fork for initial maintainer feedback. It depends on #3609. Review only this feature; the cross-fork Files changed view is cumulative because the PR targets upstream
main.Incremental change: 4 files, +527/−0 lines, including carried tests and the mechanism reference. No merge is automatic. Review value and API shape first; substantial rework can follow that feedback.
Flow and existing-code boundary
flowchart TD S0["aligned_inputs"] S1["GlmMTP"] M1_0["GlmMTP.__init__"] M1_1["GlmMTP.forward_aligned"] M1_2["GlmMTP.forward"] S2["load_mtp"] E["ValueError"] S0 -->|"raises on rejected input/state"| E S1 -. "exposes" .-> M1_0 S1 -. "exposes" .-> M1_1 S1 -. "exposes" .-> M1_2 S1 -->|"calls where selected"| S0 S1 -->|"raises on rejected input/state"| E S2 -->|"calls where selected"| S1 S2 -->|"raises on rejected input/state"| E style E fill:#fee,stroke:#b22gptqmodel/utils/glm5_mtp.py:57:aligned_inputsgptqmodel/utils/glm5_mtp.py:120:GlmMTPgptqmodel/utils/glm5_mtp.py:167:load_mtpCommitted reference: docs/glm-native-mtp.md, linked from README. Class entry points/calls and rejected-state paths describe code present in this branch, rather than planned integrations.
Validation
Carried test files:
tests/test_glm5_mtp.pyThis packaging pass checked Python parsing, whitespace, dependency order and balanced Mermaid blocks. The author reports successful prior use of these features. Per the requested resource limit and feedback-first scope, existing model quantization, GPU/ROCm tests, heavyweight CPU workloads and full model benchmarks were not rerun; no new performance or model-accuracy claim is made. Tests accompanying earlier stack layers retain their previously reported results.
Existing model support: upstream already supports this GLM/DeepSeek family. This proposal adds calibration/MTP/recovery capability; it does not add a competing MODEL_MAP registration. Native Transformers blocks and upstream model plans remain the integration basis.