Skip to content

feat(glm): carry native full-MTP alignment and source loading - #3610

Merged
Qubitium merged 1 commit into
ModelCloud:mainfrom
tpurtell:upstream/30-glm-native-mtp-20261108
Nov 9, 2026
Merged

Qubitium merged 1 commit into
ModelCloud:mainfrom
tpurtell:upstream/30-glm-native-mtp-20261108

Conversation

@tpurtell

@tpurtell tpurtell commented Nov 8, 2026

Copy link
Copy Markdown
Contributor

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:#b22
Loading
Before this extraction layer Carried implementation
API absent in the previous stack layer (path/symbol checked) gptqmodel/utils/glm5_mtp.py:57: aligned_inputs
API absent in the previous stack layer (path/symbol checked) gptqmodel/utils/glm5_mtp.py:120: GlmMTP
API absent in the previous stack layer (path/symbol checked) gptqmodel/utils/glm5_mtp.py:167: load_mtp

Committed 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.py

This 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.

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
Qubitium force-pushed the upstream/30-glm-native-mtp-20261108 branch from edf9295 to dd9871d Compare November 9, 2026 09:54

@Qubitium Qubitium left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewed against current main.

The full-GLM MTP envelope matches the documented contract:

  • aligned_inputs forms S-1 pairs strictly within each prompt (token[t] with token[t+1]), applies the target final norm exactly once for the default pre_final_norm tap, rejects a second norm for post_final_norm, and zeroes the position-zero embedding before enorm as the native path does. It validates frontier/token shape, dtype, device, vocabulary range, and consecutive nonnegative positions.
  • GlmMTP.envelope concatenates enorm(embedding) || hnorm(target) so K4 capture follows the same norm boundary as the decoder, and forward_aligned runs the block with its own full DSA indexer (prev_topk_indices=None) and applies shared_head.norm exactly once before the shared head.
  • load_mtp requires exactly one native prediction layer, extends only the three GLM schedules with the MTP entry, loads the layer plus enorm/hnorm/eh_proj/shared_head.norm as 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
Qubitium marked this pull request as ready for review November 9, 2026 09:54
@Qubitium
Qubitium merged commit 1a4e9a3 into ModelCloud:main Nov 9, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants