Repository navigation
model: add Kimi-K3.1-Pro text model - #31779
Merged
Merged
Conversation
Contributor
|
Tested the conversion with tiny-random/kimi-k3.1-pro. llama-completion gives the same tokens on CPU and CUDA. |
CISC
reviewed
Nov 6, 2026
CISC
left a comment
Member
There was a problem hiding this comment.
Rebase and adapt to refactor on master.
usrlocalben
force-pushed
the
k31-text-model
branch
from
November 6, 2026 16:20
85cf1ab to
1fcebb8
Compare
CISC
reviewed
Nov 6, 2026
CISC
left a comment
Member
There was a problem hiding this comment.
Optional:
Update metal fusion table: https://github.com/ggml-org/llama.cpp/actions/runs/42254233341/job/128111418320?pr=31779#step:6:519
K3 with the full-attention MLA layers replaced by DSA: on this checkpoint 24
of the 93 layers carry a lightning indexer (32 heads x 128, top_k 2048, no
rope). The KDA (linear-attention) layers and the rest of the K3 skeleton -
cross-layer residuals, latent MoE, situ, MLA output gate, full-rank KDA gate -
are unchanged, so this reuses the K3 graph and converter and adds the indexer.
Indexer:
- the selection is an additive mask over the whole cache, not a gather of
the top-k rows, so it reuses the existing sparse flash attention path;
off that path the mask stays correct but still costs a kq over the cache
- the indexer key LayerNorm takes its eps from the model's rms_norm_eps,
because dsa_config declares no eps of its own
Graph and cache:
- new arch with four indexer tensors per DSA layer, and a hybrid memory
that keeps a K-only MLA cache for those layers, recurrent state for the
KDA layers, and the indexer key cache
- the graph node budget shares the K3 entry
Conversion:
- KimiK31Model(KimiK3Model), picked by KimiK31ForConditionalGeneration
- dsa_config becomes attention.indexer.{head_count,key_length,top_k,types}
plus the indexer LayerNorm eps; the layer list is 1-indexed like
linear_attn_config's, and the converter asserts that it covers exactly
the full-attention layers
- the routed experts stay MXFP4 and are repacked as in K3, not dequantized
- the vision tower and mm_projector are skipped: text only for now
- the arch key follows the checkpoint's own model_type ("kimi_k31") and the
loader registers KimiK31ForConditionalGeneration; the release name carries
a -Pro suffix that nothing in the config or the tensor names uses
Quantisation: the indexer's q_b, k and proj are kept out of the quant
overrides, since the top-k selection is sensitive to their precision.
Verified on an 8-layer slice against the HF checkpoint: 38 tensors checked
exactly, the indexer metadata against the config, and the selection against
full attention - identical PPL at top_k beyond the context length, divergent
once top_k is forced below it. Arch test fixture and the full arch suite pass.
usrlocalben
force-pushed
the
k31-text-model
branch
from
November 6, 2026 20:26
b04cf49 to
bd0235f
Compare
CISC
approved these changes
Nov 6, 2026
ngxson
approved these changes
Nov 6, 2026
3 of 6 tasks
Maziar123
added a commit
to Maziar123/Strata
that referenced
this pull request
Nov 9, 2026
Upstream ggml-org/llama.cpp#31779 (bcb01528) supports K3.1 natively with arch kimi-k31, which is incompatible with the legacy patch's kimi-k3. - LLAMA_REF defaults to bcb01528; the patch is applied only on older trees - check_arch stops imatrix/quantize/serve on an architecture mismatch - fetch downloads one quant set of a prebuilt GGUF repo and verifies SHA256SUMS; serve accepts MODEL= - docs: upstream status, GGUF incompatibility, candidate model list Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
4 tasks done
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.
K3.1 reuses most of K3, but replaces the full-attention MLA layers with DSA.
The change extracts and reuses the top-k mask impl from build_attn.
The model is sometimes named with the -Pro suffix (e.g. huggingface model name) but not always (e.g. model arch in config.json). It's unclear what the right name to use is but the non-pro-suffix seems the most appropriate in the code, mirroring the strings in the safetensors/json text.
I tested this against the BF16/MXFP4 conversion and a q2/q2/q3 gate/up/down quant without issue. Code review was done with llama.cpp and DeepSeek Harness, three agents in parallel (default -np 4, unified KV) each ending with ~250K sequence length, numerous tool calls, etc. and no errors or hints of badness.
Requirements
Closes #31778