Qwen3.6-35B-A3B with a 2.5× smaller KV cache at the same cache dtype. Only the 10 full-attention layers were
retrained, by distillation from the original model. The 30 Gated DeltaNet layers, the MoE experts, the embeddings and
the vision tower are byte-identical to the base model; the stock shards in this repo are untouched, and
tinykv-patch.safetensors (560 MB) is the whole delta.
| KV cache per token | bf16 cache | fp8 cache | NVFP4 (4.5 bit) |
|---|---|---|---|
| Qwen3.6-35B-A3B | 20,480 B | 10,240 B | 5,760 B |
| TinyKV (this repo) | 8,192 B | 4,096 B | 2,304 B |
Measured in vLLM 0.32.0 on one RTX PRO 6000 (96 GB, gpu_memory_utilization=0.9): the KV cache holds
1.93M tokens instead of 820k (2.35×; the Gated DeltaNet state is a fixed cost that doesn't shrink), so 58.8
concurrent 32k-token requests fit instead of 25. With --kv-cache-dtype fp8: 3.21M tokens instead of 1.43M.
Status (read this first):
| Repo | For |
|---|---|
| this repo (bf16) | vLLM, ≥80 GB GPU |
| Qwen3.6-35B-A3B-TinyKV-NVFP4 | vLLM on Blackwell, ~22 GB weights |
| Qwen3.6-35B-A3B-TinyKV-FP8 | vLLM on Ada / Hopper / Blackwell, ~37 GB weights |
| Qwen3.6-35B-A3B-TinyKV-GPTQ-Int4 | vLLM with GPTQ, 24 GB class and up; on one Intel Arc Pro B70 the full 262K context in 25 GB, 233 tok/s decode at a 130K prompt (stock: 186) |
| Qwen3.6-35B-A3B-TinyKV-GGUF | llama.cpp (tinykv fork), Q8_0 down to IQ2_M, with a what-fits-on-your-GPU table |
All numbers compare against the original Qwen3.6-35B-A3B (bf16 weights, original cache).
Needle retrieval with 32 near-duplicate distractor facts ("the secret code for amber-123 is …" next to amber-456, …): exact match of the 8-digit answer, and its mean log-probability. These needles were held out: they were not used to choose the checkpoint (see "How the checkpoint was chosen").
| Context | Needles | TinyKV exact | Original exact | TinyKV logp | Original logp |
|---|---|---|---|---|---|
| 30k tokens | 96 | 96.9 % | 97.9 % | −0.503 | −0.372 |
| 130k tokens | 24 | 95.8 % | 91.7 % | −0.677 | −0.427 |
KL divergence from the original model's next-token distribution on held-out 8k-token documents (4 per source), counting only tokens whose target lies in no 32-gram of the training data. The "NVFP4 only" column is the original attention with its cache rounded to NVFP4: the floor any 4-bit cache pays.
| Source | TinyKV KL | NVFP4-only KL | TinyKV ΔCE (nats/token) |
|---|---|---|---|
| books (PG-19) | 0.040 | 0.008 | +0.019 |
| web (FineWeb-Edu) | 0.027 | 0.006 | +0.012 |
| code | 0.050 | 0.009 | +0.007 |
| math (FineMath) | 0.027 | 0.005 | +0.009 |
| reasoning traces (math / code) | 0.024 / 0.027 | 0.003 / 0.005 | −0.001 / +0.001 |
| chat (SmolTalk) | 0.117 | 0.031 | — |
| tool calls (Toucan) | 0.324 | 0.206 | — |
On clean text the cost is roughly +1–2 % perplexity. Chat and tool-call traffic is further from the original (ΔCE is not shown there because the template boilerplate in those sets is partly memorized, which makes ΔCE misleading).
pip install vllm==0.32.0
pip install ./plugin # registers TinyKVQwen3_5MoeForConditionalGeneration with vLLM
vllm serve darioooooo0o/Qwen3.6-35B-A3B-TinyKV --max-model-len 131072 --gpu-memory-utilization 0.9 \
--limit-mm-per-prompt '{"image":0,"video":0}'
Get plugin/ from the repo first (hf download darioooooo0o/Qwen3.6-35B-A3B-TinyKV --include "plugin/*" --local-dir .).
vLLM picks the plugin up through its vllm.general_plugins entry point, also in its engine subprocesses.
--kv-cache-dtype fp8 works and halves the cache again.
vLLM check (offline LLM API, vLLM 0.32.0, FlashAttention 2, eager mode): per-token log-probs of 4 held-out
prompts (~1k tokens each) against the PyTorch reference, with stock Qwen3.6 in vLLM vs PyTorch as the noise floor:
| mean |Δ logp| vs PyTorch | KV cache (tokens) | |
|---|---|---|
| stock, bf16 cache | 0.071 | 820,062 |
| TinyKV, bf16 cache | 0.046 | 1,927,868 |
| stock, fp8 cache | 0.077 | 1,426,897 |
| TinyKV, fp8 cache | 0.042 | 3,212,140 |
Greedy answer to "Explain in three sentences why the sky is blue." (TinyKV in vLLM): "Sunlight appears white but is actually composed of all colors of the rainbow, which travel as waves of different lengths. When this light enters Earth's atmosphere, it collides with gas molecules and other particles, causing shorter blue and violet wavelengths to …"
Not measured yet: throughput, and long-context needles through vLLM (the needle tables above come from the PyTorch path).
A retrofit: only the 10 full-attention layers are rebuilt, trained by distillation against the original model. The 30 Gated DeltaNet layers, the MoE experts and the embeddings are untouched.
Every converted layer computes queries, keys and values exactly like the original (projections, q/k RMSNorm, partial RoPE on the first 64 of 256 dims, output gate). On top of that, small linear maps change what is cached:
Because every map is linear and sits around ordinary attention, the serving engine just sees attention with head size
128 instead of 256 and uses its stock kernels: no custom attention kernel. The compressed cache lives in vLLM's normal
paged KV cache, and the plugin is ~120 lines (plugin/tinykv_vllm/model.py).
On one RTX PRO 6000, training only the attention modules of the 10 full-attention layers, with the cache rounded to NVFP4 throughout (quantization-aware), so the 4-bit cache (2,304 B/token) is what the model learned to work with:
| Step | Tokens | What it does |
|---|---|---|
| Init | — | Closed form: PCA / least squares on calibration activations, a reasonable model before any training |
| 1. Layer-wise distillation | 115M at 8k | Each layer's attention output matched to the original's |
| 2. End-to-end distillation | 160M at 8k | KL to the original's next-token distribution over the full vocabulary, plus 0.3× the layer-wise loss; copy/induction tokens up-weighted, 0.3× learning rate, repeated boilerplate masked out (cross-row 32-gram dedup) |
| 3. Long-context distillation | 10M at 32k | The same KL on long documents; snapshots every 10M, picked by a pre-registered rule (below) |
What mattered along the way:
Prior art it combines: MLA-style retrofits, low-rank KV compression (Palu), cross-layer KV sharing, and KV quantization-aware training, applied here to a hybrid Gated DeltaNet / MoE model with ~300M distillation tokens.
Data: FineWeb-Edu, FineMath, codeparrot-clean, OpenR1-Math, OpenCodeReasoning, SmolTalk, Toucan-1.5M and Hermes function-calling (tool calls rendered in Qwen3.6's native format), PG-19, and synthetic key-value lookups. The whole conversion took 38 GPU-hours.
The rule was written down before the long-context phase ran: among the snapshots taken every 10M tokens whose clean-text KL stayed within 10 % of the stage-2 result, take the one with the best needle score on a fixed needle set (seed 1, 48 needles at 30k), then judge it only on fresh needles (the tables above), with a pass bar of a ≤ 0.2 logp gap at 30k and no collapse at 130k. The 10M snapshot was picked (needle gap 0.07) and passed (0.13 on the fresh needles).
Longer KL-only training at 32k wore retrieval down: the 30M snapshot found 70.8 % of the fresh 30k needles and
83.3 % at 130k. The run was stopped there; results/ has every eval.
| Path | What |
|---|---|
model-*.safetensors |
the unmodified Qwen3.6-35B-A3B shards |
tinykv-patch.safetensors |
trained attention weights (*.self_attn.tk.*) and the cache maps (tk_q/tk_k/tk_v/tk_d) |
config.json |
architecture TinyKVQwen3_5MoeForConditionalGeneration, layout under text_config.tinykv |
plugin/ |
the vLLM plugin (pip install ./plugin) |
training/tinykv/ |
conversion, training, eval and export code |
results/ |
metric logs: stage 1, the stage-2 A/B, stage 2, the long phase, and the held-out gate (gate.jsonl) |
Made by @imdariotoo. I post my local-model releases on X, so follow there for the next ones.
All training, evaluation and the vLLM checks ran on CloudRift RTX PRO 6000 GPUs, provided through their AI Builder Grant. Thanks to CloudRift for the compute.
Apache-2.0, as the base model (Qwen/Qwen3.6-35B-A3B).
model-00001-of-00026.safetensors 4.0 GBmodel-00006-of-00026.safetensors 4.0 GBmodel-00016-of-00026.safetensors 3.9 GBmodel-00008-of-00026.safetensors 3.9 GBmodel-00010-of-00026.safetensors 3.9 GBmodel-00018-of-00026.safetensors 3.9 GBmodel-00025-of-00026.safetensors 3.8 GBmodel-00014-of-00026.safetensors 3.4 GBmodel-00012-of-00026.safetensors 3.4 GBmodel-00020-of-00026.safetensors 3.4 GBmodel-00022-of-00026.safetensors 3.4 GBmodel-00024-of-00026.safetensors 3.4 GBmodel-00004-of-00026.safetensors 3.4 GBmodel-00023-of-00026.safetensors 3.4 GBmodel-00003-of-00026.safetensors 3.4 GBmodel-00005-of-00026.safetensors 3.4 GBmodel-00026-of-00026.safetensors 2.2 GBmodel-00015-of-00026.safetensors 1.6 GBmodel-00021-of-00026.safetensors 1.6 GBmodel-00013-of-00026.safetensors 1.6 GBmodel-00002-of-00026.safetensors 1.3 GBmodel-00007-of-00026.safetensors 1.1 GBmodel-00009-of-00026.safetensors 1.1 GBmodel-00019-of-00026.safetensors 1.1 GBmodel-00011-of-00026.safetensors 1.1 GBmodel-00017-of-00026.safetensors 1.1 GBtinykv-patch.safetensors 560 MBHave the files? Submit a torrent.
Submit a torrentHave the complete files and permission to share them? Replace the example folder path. The script checks the files, makes a torrent and submits its magnet and checksums. Keep your torrent client seeding. Get your community key from your settings, and read the script before running it.
curl -fsSL https://pirateface.co/package.sh | bash -s -- --repo darioooooo0o/Qwen3.6-35B-A3B-TinyKV ./model-foldergh release download v4 -p 'libattn_kernels_xe_2.tinykv.so' -D kernels; SO_FILE=kernels/libattn_kernels_xe_2.tinykv.so TINYKV_PLUGIN=<model>/plugin MODEL_DIR=<model> GPU_UTIL=0.82 ./serve.sh (cookbook serve.sh = vllm serve --quantization gptq --kv-cache-dtype fp8 --max-model-len 262144 --max-num-seqs 8 --speculative-config '{"method":"mtp","num_speculative_tokens":4,"draft_sample_method":"probabilistic"}' + fp8 lm_head, fp8 weight-only attention/GDN/shared expert, int4 MoE decode GEMV)View run on LocalMaxxing Median of 2 community runs on 1 setups, from LocalMaxxing.
Run it yourself: setup guide