Repository navigation
feat(kimi): carry K3.1 source and bounded calibration adapters - #3608
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/28-kimi-k31-calibration-20261108
branch
from
November 9, 2026 09:50
7f34a87 to
47c2a66
Compare
Qubitium
reviewed
Nov 9, 2026
Qubitium
left a comment
Collaborator
There was a problem hiding this comment.
Reviewed against current main.
The K3.1 adapter is appropriately narrow:
KimiK31Sourcepins the snapshot revision,model_type, and architecture, validates every shard name/presence, and rejects a checkpoint whose quantization is notmxfp4-pack-quantized.decodedkeeps the native MXFP4 dequantizer while adding the KDAA_logcontract: exactly 96 F32 values, or the padded 128-value form only when the 32-value tail is byte-exact zero. That prevents a nonzero pad from leaking into the KDA math.load_blockkeeps a strictintlayer type, materializes on meta, and only applies the transient F32 indexer cast/pre-hook when an indexer exists — export bytes are untouched.DenseRawHessianaccumulates real observations only, exposesraw_dict/as_dictwith the count/finalized contract, and rejects non-positive covariance.capture_routed_hessianpreserves natural-then-recovery order, chunks the gather, applies BF16 SiTU for down inputs, floors to 1024 effective rows with an identity residual, and records a hashed candidate selection plus the accumulation contract.
The FP64 oracle tests cover dense rows, routed selection/floor, and down covariance; the source tests cover one-active-reader/deferred experts and all padded A_log rejection cases.
Cleanup only: unused import, dict(...) → literals, import ordering, and one semicolon split in the test.
Validation: ruff check clean; pytest tests/test_kimi_k31.py reports 10 passed.
Qubitium
marked this pull request as ready for review
November 9, 2026 09:51
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 K3.1 source adapter, native KDA A_log padding validation, bounded FP64-sum Hessian capture, functional indexer input handling, and owned routed source reconstruction.
This is layer 28/36, extracted from an already-used fork for initial maintainer feedback. It depends on #3607. Review only this feature; the cross-fork Files changed view is cumulative because the PR targets upstream
main.Incremental change: 4 files, +344/−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["KimiK31Source"] M0_0["KimiK31Source.__init__"] M0_1["KimiK31Source.load_block"] S1["capture_routed_hessian"] S2["DenseRawHessian"] M2_0["DenseRawHessian.__init__"] E["ValueError"] S0 -. "exposes" .-> M0_0 S0 -. "exposes" .-> M0_1 S0 -->|"raises on rejected input/state"| E S1 -->|"raises on rejected input/state"| E S2 -. "exposes" .-> M2_0 S2 -->|"raises on rejected input/state"| E style E fill:#fee,stroke:#b22gptqmodel/utils/kimi_k31.py:38:KimiK31Sourcegptqmodel/utils/kimi_k31.py:112:capture_routed_hessiangptqmodel/utils/kimi_k31.py:92:DenseRawHessianCommitted reference: docs/kimi-k31-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_kimi_k31.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.