Repository navigation
feat(glm): add bounded native core calibration and EXL3 sources - #3609
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/29-glm-core-calibration-20261108
branch
from
November 9, 2026 09:53
ca9f196 to
e4110d4
Compare
Qubitium
reviewed
Nov 9, 2026
Qubitium
left a comment
Collaborator
There was a problem hiding this comment.
Reviewed against current main.
The GLM core layer is well contained:
GlmBF16Sourcerejects a checkpoint that already carries aquantization_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, andclose/__del__release the reader.quantize_projectionvalidates K4/K6, integer seed, positive finite sigma, native[out,in]geometry within % 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_projectionare reused from the Kimi core format rather than duplicated, and the returned evidence recordshessian_rows/identity_rowswithout inventing synthetic rows.- Router recovery binds the same learned top-8 sigmoid/grouped policy, and the CUDA tests exercise the real
kv_ageometry 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
marked this pull request as ready for review
November 9, 2026 09:53
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 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:#b22gptqmodel/utils/glm5_core.py:98:GlmBF16Sourcegptqmodel/utils/glm5_core.py:31:quantize_projectiongptqmodel/utils/glm5_core.py:253:prepare_contextgptqmodel/utils/glm5_core.py:290:attention_forwardCommitted 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.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.