Skip to content

Add Kimi-Linear-48B-A3B (kimi-linear) - #11

Closed
kotselidis wants to merge 9 commits into
feat/glm53-flashfrom
feat/kimi-linear
Closed

kotselidis wants to merge 9 commits into
feat/glm53-flashfrom
feat/kimi-linear

Conversation

@kotselidis

@kotselidis kotselidis commented Nov 19, 2026 •

Copy link
Copy Markdown
Owner

Adds Kimi-Linear-48B-A3B (moonshotai/Kimi-Linear-48B-A3B-Instruct) as the kimi-linear family, loaded from llama.cpp's kimi-linear GGUFs, on the CPU and on CUDA: single-token decode, sequential prefill/decode and batched prefill, on one GPU or split across several.

The model

48B parameters (49.12B counted), about 3B active per token. 27 layers: 20 KDA (Kimi delta attention) and 7 MLA layers without RoPE (layers 3, 7, 11, 15, 19, 23, 26); a dense SwiGLU in layer 0, then 256 routed experts (top 8, sigmoid routing with a selection bias, scale 2.446) plus one shared expert. Plain pre-norm residual, no hyper-connections. Kimi's tiktoken vocabulary (163 840 tokens) and chat template. See docs/architecture/kimi-linear.md.

How it is built

Kimi-Linear is deepseek2's latent attention and mixture of experts plus glm5next's KDA, so it reuses both:

  • KDA: the host pass, weights and decode/batched kernels glm5next already had, now in family-neutral classes (KdaForward, KdaHostState, KdaWeights, KdaKernels, KdaBatchKernels); only the decay is new (−exp(A_log) · softplus(·), where glm5next uses a bounded sigmoid).
  • MLA: deepseek2's absorbed kernels with a 576-wide cache, unchanged; the 64-wide key tail is "rotated" by identity tables, and the query comes straight from attn_q.
  • Experts: the routed-expert decode and grouped prefill kernels glm5next had, now RoutedExpertKernels and RoutedExpertBatchKernels, with the clamp at infinity; Q8_0 or Q4_0 routed experts.
  • Tokenizer and chat: KimiTokenizer (Kimi's split on Qwen3Tokenizer's byte-level BPE) and KimiChatFormat.

Correctness

  • CPU, Q8_0: greedy text identical to llama.cpp's CPU output for 96 tokens.
  • GPU against the CPU, every run forced to the CPU's tokens: worst relative logit error about 5% for both single-token decode and batched prefill (FP16 and FP32 cache), the five most likely tokens the same at every step, the top token differing only at near-ties (a CPU margin of 0.14–0.18). Greedy text on the Q8_0 + Q4_0-experts file is identical to the CPU's on 2× A10.

Performance

NVIDIA A100 80GB, Q8_0 (48.65 GiB), one GPU. Both sides on the same 427-token prompt, decode of 128 tokens at depth 427, five repetitions; jitllm medians with their range, llama.cpp (11fe021, -fa 1 -ngl 99) mean ± deviation. Tokens per second.

jitllm llama.cpp
prefill, chunk / ubatch 256 2125 (2119–2130) 1681 ± 88
prefill, chunk / ubatch 512 2672 (2665–2685) 2653 ± 106
decode at depth 427 135–137 134 ± 0.7

CUDA graphs change neither number. The single-token plan runs prompt and decode together at 154 tokens per second.

2× NVIDIA A10, Q8_0 projections with Q4_0 routed experts (26.72 GiB), split by layer with the default byte-balanced split (--split-transport host). The same 427-token prompt and depth-427 decode; three repetitions each, jitllm medians with their range, llama.cpp (-sm layer) mean ± deviation:

jitllm llama.cpp
prefill, chunk / ubatch 256 1587 (1582–1590) 1407 ± 13
prefill, chunk / ubatch 512 2059 (2038–2074) 1933 ± 52
decode at depth 427 117 (106–118) 112 ± 0.5

The single-token plan runs prompt and decode together at 127 tokens per second.

Limits

  • One GGUF file: a split GGUF must be merged with llama-gguf-split --merge first.
  • On the GPU, Q8_0 projections only; mixed-type quantizations (bartowski's Q4_0 mixes Q4_0, Q4_1, Q5_0 and Q6_K) load on the CPU only. A Q8_0 file with Q4_0 experts comes from llama-quantize --allow-requantize --tensor-type ffn_gate_exps=q4_0 --tensor-type ffn_up_exps=q4_0 --tensor-type ffn_down_exps=q4_0 in.gguf out.gguf Q8_0.
  • A model split across GPUs runs single-token or with batched prefill, not sequential prefill/decode (as for the other families).

Copilot AI balanced review requested due to automatic review settings November 19, 2026 10:55

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota. Try requesting a review at a lower effort level.

Copilot AI balanced review requested due to automatic review settings November 19, 2026 11:08

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota. Try requesting a review at a lower effort level.

@kotselidis

Copy link
Copy Markdown
Owner Author

Superseded by beehive-lab#275, stacked on beehive-lab#242.

@kotselidis kotselidis closed this Nov 19, 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