Skip to content

Add dedicated Kimi-K3 GGUF support - #621

Merged
justinchuby merged 4 commits into
mainfrom
justinchuby-kimi-k3-gguf
Aug 25, 2026
Merged

Add dedicated Kimi-K3 GGUF support#621
justinchuby merged 4 commits into
mainfrom
justinchuby-kimi-k3-gguf

Conversation

@justinchuby

@justinchuby justinchuby commented Aug 25, 2026

Copy link
Copy Markdown
Member

Summary

  • add a dedicated Kimi-K3 config, model, and heterogeneous-state task with exact KDA/NoPE gated-MLA scheduling, AttnRes mixing, SiTU latent MoE, shared experts, and an untied output head
  • import pinned llama.cpp kimi-k3 GGUF metadata and tensors with strict metadata/tensor/shape/storage closure and malformed-input rejection
  • preserve lossless quantization routes under Fail closed on lossy GGUF quantization preservation #609: separate rank-3 MLA projections fail closed unless explicitly dequantized, while fused Q4_0 KV-B is split by exact packed-row reordering across weights, scales, and zero-points
  • preserve valid KDA convolution history across padding, validate kernel/state/task contracts, and cover replay, reorder, float/quantized import, roundtrip, CLI, and negative paths
  • keep generic OGA runtime packaging truthfully deferred under Represent heterogeneous state and auxiliary graph topology in runtime packages #605 because released cache schemas cannot represent the heterogeneous state ABI

Reconstruction

Reconstructed after #619 was admin squash-merged. The PR contains only the four-commit Kimi-K3 delta and review follow-ups on live-main base 04b7e3f6f2d9de5d5741aafb8fa6375a18eee693. This preserves #611 graph-driven ORT GenAI decoder configs, #618 ORT GenAI end-to-end CI, #624 generic decoder config migration, and the Kimi Linear, MiniMax, runtime, and fail-closed quantization changes already on main. git range-diff reports all four replayed commits as patch-identical (=).

Validation

  • Kimi-K3 model and GGUF tests: 30 passed
  • focused builder/build-graph Kimi-K3 checks: 4 passed, 1900 deselected
  • affected generic ORT config/runtime/E2E tests: 250 passed
  • affected OGA metadata tests: 94 passed, 1 skipped
  • broad non-integration suite: 7765 passed, 56 skipped, 1 subtest passed
  • repository lintrunner passed
  • final GPT-5.6 Sol medium review reported no findings

Real-checkpoint note

The pinned yujiepan/kimi-k3-tiny-random@a5c86ee03f07f7b141508b0108304a1447fbb345 checkpoint was assessed, but macOS cannot run its required fla-core kernels and its selective compressed-tensors MXFP4 expert representation is unsupported by the generic HF loader. That format fails explicitly rather than producing an incorrectly quantized graph.

Comment thread src/mobius/integrations/gguf/_kimi_k3_test.py Fixed
Comment thread src/mobius/models/kimi_k3.py Fixed
@github-actions

github-actions Bot commented Aug 25, 2026

Copy link
Copy Markdown

Performance Comparison

Comparing 04b7e3f4e50827

Model Metric Baseline Current Delta
bert (feature-extraction) model_size_bytes 359 KB 359 KB +0.0%
bert (feature-extraction) num_nodes 68 68 +0.0%
falcon model_size_bytes 364 KB 364 KB +0.0%
falcon num_nodes 66 66 +0.0%
gemma2 model_size_bytes 428 KB 428 KB +0.0%
gemma2 num_nodes 105 105 +0.0%
gpt2 model_size_bytes 388 KB 388 KB +0.0%
gpt2 num_nodes 54 54 +0.0%
llama model_size_bytes 425 KB 425 KB +0.0%
llama num_nodes 60 60 +0.0%
llama (static-cache) model_size_bytes 425 KB 425 KB +0.0%
llama (static-cache) num_nodes 56 56 +0.0%
mamba (ssm-text-generation) model_size_bytes 296 KB 296 KB +0.0%
mamba (ssm-text-generation) num_nodes 94 94 +0.0%
phi3 model_size_bytes 421 KB 421 KB +0.0%
phi3 num_nodes 58 58 +0.0%
phi3 (static-cache) model_size_bytes 421 KB 421 KB +0.0%
phi3 (static-cache) num_nodes 54 54 +0.0%
qwen2 model_size_bytes 425 KB 425 KB +0.0%
qwen2 num_nodes 60 60 +0.0%
qwen2 (static-cache) model_size_bytes 425 KB 425 KB +0.0%
qwen2 (static-cache) num_nodes 56 56 +0.0%
qwen3_5_moe (hybrid-text-generation) model_size_bytes 506 KB 506 KB +0.0%
qwen3_5_moe (hybrid-text-generation) num_nodes 265 265 +0.0%
qwen3_5_text (hybrid-text-generation) model_size_bytes 458 KB 458 KB +0.0%
qwen3_5_text (hybrid-text-generation) num_nodes 127 127 +0.0%
qwen3_5_vl (hybrid-qwen-vl) model_size_bytes 977 KB 977 KB +0.0%
qwen3_5_vl (hybrid-qwen-vl) num_nodes 429 429 +0.0%
t5 (seq2seq) model_size_bytes 836 KB 836 KB +0.0%
t5 (seq2seq) num_nodes 176 176 +0.0%
whisper (speech-to-text) model_size_bytes 1008 KB 1008 KB +0.0%
whisper (speech-to-text) num_nodes 128 128 +0.0%

No performance regressions.

@github-actions

github-actions Bot commented Aug 25, 2026

Copy link
Copy Markdown

🏗️ Architecture Diff

Comparing 04b7e3f4e50827

Model Sub-model Changes Status
bert (feature-extraction) model 0
falcon model 0
gemma2 model 0
gemma4 (gemma4) decoder 0
gemma4 (gemma4) embedding 0
gemma4 (gemma4) vision_encoder 0
gemma4_text model 0
gpt2 model 0
llama model 0
llama (static-cache) model 0
mamba (ssm-text-generation) model 0
phi3 model 0
phi3 (static-cache) model 0
qwen model 0
qwen (static-cache) model 0
qwen2 model 0
qwen2 (static-cache) model 0
qwen2_moe model 0
qwen2_moe (static-cache) model 0
qwen3 model 0
qwen3 (static-cache) model 0
qwen3_5_moe (hybrid-text-generation) model 0
qwen3_5_text (hybrid-text-generation) model 0
qwen3_5_vl (hybrid-qwen-vl) decoder 0
qwen3_5_vl (hybrid-qwen-vl) embedding 0
qwen3_5_vl (hybrid-qwen-vl) vision_encoder 0
qwen3_moe model 0
qwen3_moe (static-cache) model 0
qwen3_next (hybrid-text-generation) model 0
t5 (seq2seq) decoder 0
t5 (seq2seq) encoder 0
whisper (speech-to-text) decoder 0
whisper (speech-to-text) encoder 0

No architecture changes detected.


Legend: ⚪ No change · 🔵 Minor (attrs/inits) · 🟡 Moderate (nodes added/removed) · 🔴 Major (interface changed)

@justinchuby
justinchuby force-pushed the justinchuby-kimi-linear-gguf branch from eb61cca to 9bf181f Compare August 25, 2026 19:04
Base automatically changed from justinchuby-kimi-linear-gguf to main August 25, 2026 19:04
@justinchuby
justinchuby requested review from a team and a lite review from Copilot August 25, 2026 19:05
@justinchuby
justinchuby force-pushed the justinchuby-kimi-k3-gguf branch from ce26b16 to dfdd697 Compare August 25, 2026 19:44

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Adds first-class support for the Kimi-K3 architecture to Mobius’ model/task stack and GGUF importer, enabling exact graph construction + strict GGUF contract validation while keeping generic runtime packaging deferred due to heterogeneous state ABI limitations (#605).

Changes:

  • Add KimiK3Config, KimiK3CausalLMModel, and a dedicated heterogeneous-state task KimiK3CausalLMTask.
  • Extend GGUF import pipeline to recognize kimi-k3, enforce pinned metadata/tensor closure, and support compatible quantized import paths (including fused KV-B splitting).
  • Add/extend tests and docs to cover build-graph expectations, tensor processors/mapping, and end-to-end GGUF import + runtime behaviors.

Reviewed changes

Copilot reviewed 23 out of 23 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
tests/build_graph_test.py Extends state-output assertions to cover kimi_k3_attention layers.
tests/_test_configs.py Adds a tiny representative config entry for kimi_k3 graph-build coverage.
src/mobius/tasks/_kimi_linear.py Fixes the #605 issue URL in runtime_support metadata.
src/mobius/tasks/_kimi_k3.py New dedicated heterogeneous-state task defining K3 cache inputs/outputs and metadata.
src/mobius/tasks/init.py Exports/registers KimiK3CausalLMTask under a dedicated task name.
src/mobius/models/kimi_k3.py Implements the Kimi-K3 decoder (KDA + NoPE MLA + AttnRes mixing + SiTU latent MoE) and weight preprocessing.
src/mobius/models/kimi_k3_test.py Unit tests for config extraction, graph contracts, dtype behavior, and weight preprocessing.
src/mobius/models/init.py Exports KimiK3CausalLMModel.
src/mobius/integrations/gguf/_tensor_processors.py Adds K3 tensor post-processing (conv kernel layout, decay inversion, MLA reshapes, residual-score expansion).
src/mobius/integrations/gguf/_tensor_processors_test.py Adds focused tests for K3 tensor processing behavior.
src/mobius/integrations/gguf/_tensor_mapping.py Adds kimi-k3 GGUF→HF tensor mapping + suffix rules.
src/mobius/integrations/gguf/_tensor_mapping_test.py Tests exact mapping coverage + rejection of wrong/legacy suffixes for kimi-k3.
src/mobius/integrations/gguf/_kimi_k3_test.py End-to-end tests for the pinned K3 GGUF contract (float/quantized, replay/reorder, padding invariance, CLI, negative paths).
src/mobius/integrations/gguf/_config_mapping.py Adds K3 GGUF metadata key-map + postprocessor; derives hybrid layout with K3 layer-type tag.
src/mobius/integrations/gguf/_builder.py Validates pinned K3 GGUF tensor/metadata closure; enforces dedicated task; supports fused KV-B quantized splitting.
src/mobius/integrations/gguf/_builder_test.py Extends Kimi Linear GGUF tests (conv validation + generic task override rejection) and updates cohort coverage.
src/mobius/integrations/gguf/_arch_registry.py Promotes kimi-k3 to supported config/tensor/graph with runtime deferred.
src/mobius/integrations/gguf/_arch_registry_test.py Updates supported-architecture census + adds explicit K3 support expectations.
src/mobius/_registry.py Registers kimi_k3 model type and adds a tiny-random reference model ID for testing.
src/mobius/_configs/_base.py Adds new config fields and implements KimiK3Config.from_transformers; tightens Kimi Linear conv-kernel validation.
src/mobius/_configs/_base_test.py Adds regression test for Kimi Linear conv-kernel minimum validation.
src/mobius/_configs/init.py Exports KimiK3Config.
docs/api/build_from_gguf.md Updates supported-architecture census + K3 entry and “remaining hybrid cohort” narrative.

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment on lines +1156 to +1179
required_metadata=(
"context_length",
"embedding_length",
"feed_forward_length",
"block_count",
"attention.head_count",
"attention.head_count_kv",
"attention.layer_norm_rms_epsilon",
"attention.q_lora_rank",
"attention.key_length_mla",
"attention.value_length_mla",
"attention.kv_lora_rank",
"rope.dimension_count",
"ssm.conv_kernel",
"kda.head_dim",
"expert_count",
"expert_used_count",
"expert_feed_forward_length",
"expert_shared_count",
"expert_gating_func",
"attn_res.block_size",
"activation.situ_beta",
"activation.situ_linear_beta",
),
@justinchuby
justinchuby force-pushed the justinchuby-kimi-k3-gguf branch from dfdd697 to 4a797f7 Compare August 25, 2026 19:53
justinchuby and others added 4 commits August 25, 2026 12:53
Implement the pinned Kimi-K3 KDA/NoPE-MLA schedule, attention residual topology, latent MoE, heterogeneous cache ABI, and strict GGUF metadata and tensor validation. Preserve compatible quantized projections, safely split fused MLA weights, and cover numerical parity, runtime state behavior, CLI, roundtrip, and rejection paths.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Signed-off-by: Justin Chu <justinchuby@users.noreply.github.com>
Preserve valid KDA convolution history across right padding, align latent-MoE routing weights with low-precision expert outputs, close config and GGUF kernel-size validation, and carry the parent Kimi Linear review fixes and model coverage IDs.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Signed-off-by: Justin Chu <justinchuby@users.noreply.github.com>
Adapt Kimi-K3 quantized import to the fail-closed policy from #609: reject lossy rank-3 MLA reshaping, retain explicit float import, and split fused Q4_0 KV-B with exact packed-row reordering.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Signed-off-by: Justin Chu <justinchuby@users.noreply.github.com>
Reject generic task overrides that cannot represent heterogeneous Kimi state and keep KDA recurrence masks in FP32 while retaining model-dtype output masking. Add targeted task and mixed-Mul regression coverage.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Signed-off-by: Justin Chu <justinchuby@users.noreply.github.com>
@justinchuby
justinchuby force-pushed the justinchuby-kimi-k3-gguf branch from 4a797f7 to 4e50827 Compare August 25, 2026 20:13
@justinchuby
justinchuby merged commit aec175f into main Aug 25, 2026
15 of 24 checks passed
@justinchuby
justinchuby deleted the justinchuby-kimi-k3-gguf branch August 25, 2026 20:14
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.

3 participants