Skip to content

feat(glm): carry Flash core and MTP calibration adapters - #3611

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

Qubitium merged 1 commit into
ModelCloud:mainfrom
tpurtell:upstream/31-glm-flash-native-calibration-20261108

Conversation

@tpurtell

@tpurtell tpurtell commented Nov 8, 2026

Copy link
Copy Markdown
Contributor

Summary

Carry hybrid KDA/sparse-attention stage boundaries, bounded KDA execution, hyperconnection continuation, original native checkpoint names, and aligned Flash MTP source loading.

This is layer 31/36, extracted from an already-used fork for initial maintainer feedback. It depends on #3610. Review only this feature; the cross-fork Files changed view is cumulative because the PR targets upstream main.

Incremental change: 5 files, +570/−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["GlmFlashBF16Source"]
    M0_0["GlmFlashBF16Source.__init__"]
    M0_1["GlmFlashBF16Source.materialize_block"]
    M0_2["GlmFlashBF16Source.materialize_routed_experts"]
    S1["bounded_kda"]
    S2["staged_forward"]
    S3["GlmFlashMTP"]
    M3_0["GlmFlashMTP.__init__"]
    M3_1["GlmFlashMTP.forward_aligned"]
    E["ValueError"]
    S0 -. "exposes" .-> M0_0
    S0 -. "exposes" .-> M0_1
    S0 -. "exposes" .-> M0_2
    S0 -->|"raises on rejected input/state"| E
    S3 -. "exposes" .-> M3_0
    S3 -. "exposes" .-> M3_1
    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_flash_core.py:76: GlmFlashBF16Source
API absent in the previous stack layer (path/symbol checked) gptqmodel/utils/glm5_flash_core.py:49: bounded_kda
API absent in the previous stack layer (path/symbol checked) gptqmodel/utils/glm5_flash_core.py:267: staged_forward
API absent in the previous stack layer (path/symbol checked) gptqmodel/utils/glm5_flash_mtp.py:70: GlmFlashMTP

Committed reference: docs/glm-flash-native-calibration.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_flash_core.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/31-glm-flash-native-calibration-20261108 branch from a2140ac to d9c7040 Compare November 9, 2026 09:55

@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 Flash adapters stay distinct from the full-GLM path, which is the important invariant:

  • glm5_flash_core loads the non-mHC source, remaps native names, owns the checkpoint buffers, and keeps the KDA head slicing and shared-down SwiGLU clamp native. The staged mHC replay is asserted byte-exact against the native decoder.
  • glm5_flash_mtp.aligned_inputs uses the unweighted mHC stream mean followed by target_norm at t, pairs with token t+1, and uses the shifted-token position t+1. Because positions are shifted, the position-zero embedding mask correctly does not fire for the first pair — the test pins that behavior so it is not "fixed" into the full-GLM convention.
  • FlashMTPDecoder is a plain residual decoder with its own full indexer and the checkpoint's clamped MoE; load_mtp extends only the three GLM schedules, requires exactly one prediction layer, and validates every envelope tensor as BF16 with exact geometry.
  • GlmFlashMTP.forward_aligned applies shared_head.norm exactly once before the shared target head.

Cleanup only: import ordering and dict(...) → literals.

Validation: ruff check clean; pytest tests/test_glm5_flash_core.py reports 8 passed.

@Qubitium
Qubitium marked this pull request as ready for review November 9, 2026 09:55
@Qubitium
Qubitium merged commit 3c93206 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