Skip to content

feat(glm): add bounded native core calibration and EXL3 sources - #3609

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

Qubitium merged 1 commit into
ModelCloud:mainfrom
tpurtell:upstream/29-glm-core-calibration-20261108

Conversation

@tpurtell

@tpurtell tpurtell commented Nov 8, 2026

Copy link
Copy Markdown
Contributor

Summary

Carry the native BF16 GLM source, explicit attention/MoE stage boundaries, independent raw-Hessian ownership, padded projection quantization, and bounded source reads. This exposes the existing runner API without changing the default loader.

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

Incremental change: 5 files, +658/−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["GlmBF16Source"]
    M0_0["GlmBF16Source.__init__"]
    M0_1["GlmBF16Source.materialize_block"]
    M0_2["GlmBF16Source.load_block"]
    S1["quantize_projection"]
    S2["prepare_context"]
    S3["attention_forward"]
    S4["complete_moe"]
    E["ValueError"]
    S0 -. "exposes" .-> M0_0
    S0 -. "exposes" .-> M0_1
    S0 -. "exposes" .-> M0_2
    S0 -->|"raises on rejected input/state"| E
    S1 -->|"raises on rejected input/state"| E
    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_core.py:98: GlmBF16Source
API absent in the previous stack layer (path/symbol checked) gptqmodel/utils/glm5_core.py:31: quantize_projection
API absent in the previous stack layer (path/symbol checked) gptqmodel/utils/glm5_core.py:253: prepare_context
API absent in the previous stack layer (path/symbol checked) gptqmodel/utils/glm5_core.py:290: attention_forward

Committed reference: docs/glm-core-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_core.py, tests/test_glm5_core_cuda.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/29-glm-core-calibration-20261108 branch from ca9f196 to e4110d4 Compare November 9, 2026 09:53

@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 GLM core layer is well contained:

  • GlmBF16Source rejects a checkpoint that already carries a quantization_config, keeps exactly one active safetensors reader, validates shard basenames, and returns owned tensors so a mapping never reaches CUDA. Routed experts stay meta until materialized, and close/__del__ release the reader.
  • quantize_projection validates K4/K6, integer seed, positive finite sigma, native [out,in] geometry with in % 128, a fresh raw FP32 Hessian with positive trace, and finite weights chunk-by-chunk. It copies the Hessian into an owned device tensor, pads outputs to the 128-row storage grid, and requires the quantizer to report the calibrated FP64-congruence LDLQ contract with finite, non-negative metrics and positive reference energy.
  • validate_core_tensors/reconstruct_core_projection are reused from the Kimi core format rather than duplicated, and the returned evidence records hessian_rows/identity_rows without inventing synthetic rows.
  • Router recovery binds the same learned top-8 sigmoid/grouped policy, and the CUDA tests exercise the real kv_a geometry and native-MCG-vs-serialized-BF16 wrapper at batch 1/33.

Cleanup only: dict(...) → literals, import ordering, and semicolon-split lines in the test harness (the Reader context-manager bodies were expanded to normal method bodies).

Validation: ruff check clean; pytest tests/test_glm5_core.py tests/test_glm5_core_cuda.py reports 42 passed.

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