Skip to content

feat(kimi): carry causal core calibration and padded EXL3 source storage - #3607

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

Qubitium merged 1 commit into
ModelCloud:mainfrom
tpurtell:upstream/27-kimi-core-calibration-20261108

Conversation

@tpurtell

@tpurtell tpurtell commented Nov 8, 2026

Copy link
Copy Markdown
Contributor

Summary

Carry explicit attention/MoE/head calibration boundaries, bounded source-shard ownership, padded core projection storage validation and reconstruction, and calibrated EXL3 source replacement. Keep the existing independent format and CUDA oracle tests as carried evidence.

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

Incremental change: 7 files, +1318/−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["quantize_core_projection"]
    S1["reconstruct_core_projection"]
    S2["KimiK3EXL3Source"]
    M2_0["KimiK3EXL3Source.load_block"]
    M2_1["KimiK3EXL3Source.materialize_routed_experts"]
    S3["capture_linear_input"]
    E["KeyError, ValueError"]
    S0 -->|"raises on rejected input/state"| E
    S2 -. "exposes" .-> M2_0
    S2 -. "exposes" .-> M2_1
    S2 -->|"calls where selected"| S1
    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_k3_core_format.py:64: quantize_core_projection
API absent in the previous stack layer (path/symbol checked) gptqmodel/utils/kimi_k3_core_format.py:56: reconstruct_core_projection
API absent in the previous stack layer (path/symbol checked) gptqmodel/utils/kimi_k3_core_format.py:126: KimiK3EXL3Source
API absent in the previous stack layer (path/symbol checked) gptqmodel/utils/kimi_k3_core_stream.py:87: capture_linear_input

Committed reference: docs/kimi-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_kimi_k3_core_format.py, tests/test_kimi_k3_core_stream.py, tests/test_kimi_k3_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.

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/27-kimi-core-calibration-20261108 branch from fe83c3b to caa4e3d 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 core calibration/storage layer is well bounded:

  • kimi_k3_core_format owns the padded EXL3 source layout and the quantize/reconstruct path, including the padded row geometry and crop back to the native shape. The CUDA oracle tests assert packed round-trip mismatch counts of zero, 1e-7-scale normalized Hessian error for the small case, and bit-identical inner-half reconstruction for fp16/bf16.
  • kimi_k3_core_stream keeps a single safetensors reader, returns owned tensors rather than mappings, and materializes routed experts explicitly so the block never holds file-backed pages.
  • The wrapper-inference tests compare native vs reconstructed-inner-GEMM paths at both batch 1 and batch 33 across fp16/bf16 and stay within the expected ~1e-4 max-abs error.
  • test_native_kimi_mla_shape_calibrated_quantization_and_crop is correctly skipped when the required MLA shape/hardware is unavailable.

Cleanup only: import ordering, dict(...) → literals, dict.fromkeys, and two semicolon-split lines in the test harness. Behaviour is unchanged and the full suite still passes.

Validation: ruff check clean; pytest tests/test_kimi_k3_core_format.py tests/test_kimi_k3_core_stream.py tests/test_kimi_k3_core_cuda.py reports 72 passed, 1 skipped.

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