Skip to content

feat(kimi): carry K3.1 source and bounded calibration adapters - #3608

Merged
Qubitium merged 1 commit into
ModelCloud:mainfrom
tpurtell:upstream/28-kimi-k31-calibration-20261108
Nov 9, 2026
Merged

Qubitium merged 1 commit into
ModelCloud:mainfrom
tpurtell:upstream/28-kimi-k31-calibration-20261108

Conversation

@tpurtell

@tpurtell tpurtell commented Nov 8, 2026

Copy link
Copy Markdown
Contributor

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:#b22
Loading
Before this extraction layer Carried implementation
API absent in the previous stack layer (path/symbol checked) gptqmodel/utils/kimi_k31.py:38: KimiK31Source
API absent in the previous stack layer (path/symbol checked) gptqmodel/utils/kimi_k31.py:112: capture_routed_hessian
API absent in the previous stack layer (path/symbol checked) gptqmodel/utils/kimi_k31.py:92: DenseRawHessian

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

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/28-kimi-k31-calibration-20261108 branch from 7f34a87 to 47c2a66 Compare November 9, 2026 09:50

@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 K3.1 adapter is appropriately narrow:

  • KimiK31Source pins the snapshot revision, model_type, and architecture, validates every shard name/presence, and rejects a checkpoint whose quantization is not mxfp4-pack-quantized.
  • decoded keeps the native MXFP4 dequantizer while adding the KDA A_log contract: 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_block keeps a strict int layer type, materializes on meta, and only applies the transient F32 indexer cast/pre-hook when an indexer exists — export bytes are untouched.
  • DenseRawHessian accumulates real observations only, exposes raw_dict/as_dict with the count/finalized contract, and rejects non-positive covariance.
  • capture_routed_hessian preserves 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
Qubitium marked this pull request as ready for review November 9, 2026 09:51
@Qubitium
Qubitium merged commit 858386b 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