Run frontier MoE models on hardware you already own β pure C, zero deps, experts streamed from disk. Tiny engine, immense model. π¦
C
docs: Kimi K3 and MiMo on the shared expert tier
JustVugg2a81ee81fea7
diff --git a/docs/ENVIRONMENT.md b/docs/ENVIRONMENT.mdindex 442f67f5..b332f7d5 100644--- a/docs/ENVIRONMENT.md+++ b/docs/ENVIRONMENT.md@@ -14,14 +14,14 @@ what follows, but the sister engines read their own:|---|---|---|| `colibri` | `c/colibri.c` | everything below except the three sections named for another engine || `glm53` | `c/glm53.c` | the `GLM53_*` family and `COLI_MAP_EXPERTS`: see [GLM-5.3-Flash engine](#glm-53-flash-engine-glm53) |-| `kimi_k3` | `c/kimi_k3.c` | the `K3_*` family β see [Kimi K3 engine](#kimi-k3-engine-kimi_k3) |+| `kimi_k3` | `c/kimi_k3.c` | the `K3_*` family, and the Vulkan expert tier's `COLI_VK_TIER*` β see [Kimi K3 engine](#kimi-k3-engine-kimi_k3) || `inkling` | `c/inkling.c` | `INK_*`, plus `CTX_MAX`, `PIN_N`, `REP_PEN`, `GPU_DEV`, `NOGPU` β see [Inkling engine](#inkling-engine-inkling) || `qwen36` | `c/qwen36.c` | `QWEN_*`, `Q36_*`, its dense/CUDA-tier controls, the `CACHE_ROUTE` family (VRAM tier over RAM cache), and the Vulkan expert tier's `COLI_VK_TIER*` β see [Qwen3.6 engine](#qwen36-engine-qwen36) || `qwen38` | `c/qwen38.c` | `Q38_MAXT`, `Q38_EOS`, `Q38_NATIVE_FP8`, `Q38_NATIVE_BF16`, `Q38_EXPERT_INT4`, `Q38_MTP`, `Q38_PREFILL_BATCH`, `Q38_TRUNK_CPU_INT8`, `Q38_FP8_KERNEL`, `COLI_TIMERS`, the Vulkan expert tier's `COLI_VK_TIER*` β see [Qwen3.8 engine](#qwen38-engine-qwen38) || `olmoe` | `c/olmoe.c` | `HOT`, `WIDE`, `SMOOTH`, `CONF_LIMIT`, `MAX_NEW`, `CHAT`, `EXPERT_DROP`, `WARMUP` β see [OLMoE engine](#olmoe-engine-olmoe) || `deepseek_v4` | `c/deepseek_v4.c` | `CTX`, the `V4_*` / `DSV4_*` families and the two `COLI_CUDA_*_BATCH` gates β see [DeepSeek V4 engine](#deepseek-v4-engine-deepseek_v4); note that the CUDA section below describes `colibri.c` knobs (`COLI_CUDA`, `CUDA_DENSE`, ...) which the V4 engine does not read β its GPU switch is `DSV4_CUDA` || `deepseek_v41` | `c/deepseek_v41.c` | the `V41_*` family: see [DeepSeek V4.1 engine](#deepseek-v41-engine-deepseek_v41) |-| `mimo` | `c/mimo.c` | the `MIMO_*` family: see [MiMo-V2.6 engine](#mimo-v26-engine-mimo) |+| `mimo` | `c/mimo.c` | the `MIMO_*` family, and the Vulkan expert tier's `COLI_VK_TIER*`: see [MiMo-V2.6 engine](#mimo-v26-engine-mimo) |Setting an `INK_*` variable while running `colibri` does nothing, and viceversa; nothing warns you about it. A few variables are genuinely shared because@@ -214,7 +214,7 @@ Per-drive byte counts are reported in a `MIRROR:` stats line. Combine with `DIRE| Variable | Default | Effect ||---|---|---|-| `COLI_VULKAN` | off | Enable the Vulkan backend. Requires a `make VK=1` build. The GLM engine fails at startup (no silent fallback) if libvulkan or the compiled shaders are missing. The other engines (qwen36, qwen38, inkling, olmoe, deepseek_v41, deepseek_v4, mimo, qwenimage) print one line and run on the CPU. What each one puts on the device: [vulkan.md](vulkan.md#the-other-engines). |+| `COLI_VULKAN` | off | Enable the Vulkan backend. Requires a `make VK=1` build. The GLM engine fails at startup (no silent fallback) if libvulkan or the compiled shaders are missing. The other engines (qwen36, qwen38, inkling, olmoe, deepseek_v41, deepseek_v4, kimi_k3, mimo, qwenimage) print one line and run on the CPU. What each one puts on the device: [vulkan.md](vulkan.md#the-other-engines). || `COLI_VK_DEV` | unset | Select the primary Vulkan physical-device enumeration index. Without it, the backend prefers a discrete GPU, then integrated/virtual devices. || `COLI_VK_SHADERS` | auto | Path to the compiled `qmatmul.spv` **or** the directory holding the `.spv` set; the other shaders are found next to it. Unset: `shaders/` next to the binary, then CWD-relative `shaders/qmatmul.spv`. || `COLI_VK_EXPERTS` | `320` | Pinned VRAM expert tier size: top-N experts by `.coli_usage` heat uploaded once at startup and served from VRAM with no RAM slot or disk read. `0` disables the tier (experts stay on the CPU path). ~19 MB VRAM per int4 expert. |@@ -229,7 +229,7 @@ Per-drive byte counts are reported in a `MIRROR:` stats line. Combine with `DIRE| `COLI_VK_GEMM_TILE` | measured | `bm,bn,bk,tm,tn[,pf]`: one tile for every width of the fp32 GEMM instead of the measured pair. Tuning only (`COLI_VK_TEST_GEMM_BENCH`). || `COLI_VK_COOP_TILE` | measured | `bm,bn,wm,wn,bk`: one tile for every width of the cooperative-matrix GEMM. Tuning only. |-### The routed-expert tier (`vk_tier.c`; qwen36, qwen38)+### The routed-expert tier (`vk_tier.c`; qwen36, qwen38, kimi_k3, mimo)With `COLI_VULKAN=1` the engines on the shared tier keep a cache of routed experts on the device that adapts while you chat, and compute the resident ones of each layer step while the CPU computes the rest. See [vulkan.md](vulkan.md#the-routed-expert-tier-vk_tierc). With the CUDA expert tier also on, CUDA wins and this tier stays off.@@ -244,7 +244,7 @@ With `COLI_VULKAN=1` the engines on the shared tier keep a cache of routed exper| `COLI_VK_TIER_BALANCE` | on | `0`: the device takes every resident expert of a step. On, when a join keeps waiting for the device, the step's resident experts the CPU also holds in RAM go back to the CPU beyond the device's share, which moves with every join (down when the CPU waited more than a tenth of its own time, up when the device finished before 80% of it). || `COLI_VK_TIER_GEMM_ROWS` | `16` | Rows from which an expert of a step takes the tiled GEMM (prefill) instead of the per-row GEMV; `0` never. Below it a row's bits do not depend on how many rows share the dispatch. || `COLI_VK_TIER_QUEUE` | a second queue | `0`: the tier's batches share the main queue with the dense matmuls (they then serialize). Unset: a second queue of the main family, else a compute-only family's (RADV), else shared (Lavapipe). |-| `COLI_VK_DENSE` | on; off on a device sharing the CPU's RAM while the tier is on | Where the dense (non-expert) matrices of qwen36, qwen38, inkling, olmoe, mimo, deepseek_v41, deepseek_v4 and qwenimage run. `0`: on the CPU (with the tier on, the device takes the routed experts only); `1`: on the device whatever the device. Unset: on the device, except on an integrated GPU or a CPU device (Lavapipe) while the engine runs the expert tier (today qwen36 and qwen38), where they stay on the CPU: there the dense matmuls cost more than the tier gains (measured on a Radeon 780M). The `[VK] <engine>: device ready, dense matrices on the ...` line says which and why. The GLM engine reads it through the same rule with its own default, off (see above). |+| `COLI_VK_DENSE` | on; off on a device sharing the CPU's RAM while the tier is on | Where the dense (non-expert) matrices of qwen36, qwen38, inkling, olmoe, mimo, deepseek_v41, deepseek_v4 and qwenimage run. `0`: on the CPU (with the tier on, the device takes the routed experts only); `1`: on the device whatever the device. Unset: on the device, except on an integrated GPU or a CPU device (Lavapipe) while the engine runs the expert tier (today qwen36, qwen38, kimi_k3 and mimo), where they stay on the CPU: there the dense matmuls cost more than the tier gains (measured on a Radeon 780M). The `[VK] <engine>: device ready, dense matrices on the ...` line says which and why. The GLM engine reads it through the same rule with its own default, off (see above). |### Second Vulkan device (opt-in)@@ -411,9 +411,10 @@ Read **only** by `c/kimi_k3.c`. The K3 engine has its own loader, cache and quan| `K3_DIRS` | unset | Extra shard directories (`;`/`,`-separated) for a multi-drive split, as `COLI_MODEL_DIRS` is for `colibri`. || `K3_TOPP` | `0` (off) | Prune routed experts to this cumulative gate weight. A quality lever β A/B it against `K3_LOGITS`. || `K3_THINK` | `1` (on) | Emit a reasoning block. `=0` disables. |-| `K3_VK` | `1` (on where built) | Vulkan expert tier. `=0` forces CPU-only. |-| `K3_VK_GB` | `0` (driver budget) | VRAM cap (GB) for the K3 Vulkan expert tier. |-| `K3_VK_UP` | `8` | Expert uploads allowed per step while filling the VRAM tier. |+| `COLI_VULKAN` | `0` | `VK=1` build: the routed experts on the shared expert tier (`COLI_VK_TIER*`, see [Vulkan](#vulkan-any-gpu-with-a-vulkan-12-driver)), as the checkpoint's MXFP4 with SiTU-GLU on the device, warm-started from the expert history `COLI_USAGE`; the shared experts' matrices on the device where `COLI_VK_DENSE` puts the dense matrices. The tier's experts match `K3_IDOT=0` (the CPU's default kernel rounds activations to int8). With `K3_CUDA=1` too, CUDA wins and the Vulkan tier stays off. |+| `K3_VK` | unset (follow `COLI_VULKAN`) | The switch of the engine's tier before the shared one, kept as an alias: `1` opens the device as `COLI_VULKAN=1` does; `0` keeps it closed whatever `COLI_VULKAN` says. Before the shared tier a `VK=1` build opened the device without being asked (`1` was the default); it now waits for one of the two. |+| `K3_VK_GB` | unset | Alias: read as `COLI_VK_TIER_GB` (the routed experts' budget, GiB) when that is unset. |+| `K3_VK_UP` | unset | Alias: a number is read as `COLI_VK_TIER_RATE` (promotions per token) when that is unset. `auto` (and `K3_VK_FILL_FRAC`) is accepted and does nothing: the shared tier uploads on a thread of its own and never holds a step. || `K3_PREFIX_LOG` | unset | Log the KV-prefix reuse decision either way, with the reason when it is "no" β "it did not get faster" is otherwise indistinguishable from "reuse is off". || `K3_CHAT_IDS` | unset | Print the chat-template token ids for the built prompt, then continue. || `K3_TRACE` | unset | Write a routing trace to `K3_TRACE=<file>`. |@@ -543,8 +544,8 @@ Read **only** by `c/mimo.c` (and `MIMO_MAX_IMAGE_TOKENS` by the gateway). See [m| `MIMO_TRACE` | unset | MiMo, oracle: dump the residual after every sublayer of the first block. || `MIMO_DIRS` | unset | MiMo: extra directories holding shards. || `MIMO_STATS` | unset | MiMo: report the vision tower's time per picture. |-| `COLI_VULKAN` | `0` | MiMo, `VK=1` build: the dense matrices of the trunk and of the vision tower run on the GPU in their `MIMO_DENSE_BITS` form (FP8 and BF16, int8 or f32). The router stays on the CPU. |-| `MIMO_VK_EXPERTS` | `0` | MiMo, with `COLI_VULKAN=1`: keep up to this many routed experts (MXFP4) on the GPU once they have run from the RAM cache; never evicted, capped by the device's memory budget. |+| `COLI_VULKAN` | `0` | MiMo, `VK=1` build: the routed experts on the shared expert tier (`COLI_VK_TIER*`, see [Vulkan](#vulkan-any-gpu-with-a-vulkan-12-driver)) as the release's MXFP4, and the dense matrices of the trunk and of the vision tower on the device where `COLI_VK_DENSE` puts them, in their `MIMO_DENSE_BITS` form (FP8 and BF16, int8 or f32). The router stays on the CPU. MiMo keeps no expert history: the tier fills as experts pass by. |+| `MIMO_VK_EXPERTS` | unset | MiMo, with `COLI_VULKAN=1`: the switch of the engine's own tier before the shared one, kept as an alias. `0` keeps the routed experts on the CPU (no tier); `N` sizes the shared tier's budget at N experts (`COLI_VK_TIER_GB`, which wins when set); the tier then evicts as the routing moves, where the old one stopped at N and never let go. Unset: the shared tier with its own budget. |## OLMoE engine (`olmoe`)diff --git a/docs/kimi_k3.md b/docs/kimi_k3.mdindex 289acf44..add3f2cb 100644--- a/docs/kimi_k3.md+++ b/docs/kimi_k3.md@@ -120,8 +120,8 @@ monitors may still show the touched mapping (about 33.8 GB for the full model)in RSS; it is clean file-backed memory, not private heap, so use `/proc` smapsaccounting to distinguish file-backed RSS from private anonymous memory. Theoption has no fallback: tensors that need load-time conversion, non-F32 scale-sidecars, and enabled Vulkan/CUDA backends are refused. A Vulkan build therefore-requires `K3_VK=0 K3_MMAP=1` explicitly.+sidecars, and enabled Vulkan/CUDA backends are refused: `K3_MMAP=1` runs with+`COLI_VULKAN` unset (or `K3_VK=0`) and `K3_CUDA` off.Sizes: source 1.56 TB β β1.50 TB (`--bits 8`) / β1.48 TB (`--bits 4`). Theexperts (93 % of bytes) are already at 4.25 bits/weight and cannot shrink@@ -171,9 +171,10 @@ Judge quantization choices on real-text logits, not synthetic-vector norms.| `K3_HEAD_BITS` | 8 | load-time bits for lm_head || `K3_MMAP` | 0 | map fully prepared U8/F32 weights read-only (experimental, CPU-only, no conversion fallback) || `K3_EXPERT_GB` | 8 | routed-expert LRU budget |-| `K3_VK` | 1 | Vulkan tier when built with `make VK=1 kimi_k3` (0 = pure CPU) |-| `K3_VK_GB` | driver budget | VRAM cap for the Vulkan tier |-| `K3_VK_UP` | 8 | routed-expert uploads per step (fill-once tier) |+| `COLI_VULKAN` | 0 | `make VK=1 kimi_k3`: routed experts on the shared Vulkan expert tier, shared experts where `COLI_VK_DENSE` puts the dense matrices (see [Vulkan](#vulkan-make-vk1-kimi_k3)) |+| `K3_VK` | unset | old switch, an alias: 1 = `COLI_VULKAN=1`, 0 = never open the device |+| `K3_VK_GB` | unset | old switch, read as `COLI_VK_TIER_GB` when that is unset |+| `K3_VK_UP` | unset | old switch, a number read as `COLI_VK_TIER_RATE` when that is unset; `auto` does nothing || `K3_DIRECT` | 1 | O_DIRECT expert reads (0 = buffered + WILLNEED) || `K3_IDOT` | 1 | int8-activation expert matmuls (0 = exact-float kernel) || `K3_PIPE` | 1 | overlap expert loads with compute (loader threads) |@@ -243,37 +244,62 @@ is returned as `reasoning_content`, response text as `content`, andhonoured between generated tokens. Long prefill also polls `CANCEL` betweenlayers and drops the unpublished partial state before serving another request.-## Vulkan tier (`make VK=1 kimi_k3`)--The shared Vulkan backend (`backend_vulkan.c`) gained an **fmt=7 MXFP4**-decode path for K3's expert format β e2m1 nibbles with the ue8m0 exponents-expanded to f32 per-32-group scales at upload, so the QAT bytes are uploaded-exactly as stored and never re-encoded (kernel vs `matmul_mxfp4`: rel_l2-2.2e-07 on an RX 9070/RADV, 2.6e-07 on llvmpipe;-`tests/test_vk_mxfp4.c`). The engine keeps two residency classes on the-card, both with transparent CPU fallback and identical output:--- **shared experts**, uploaded once at init (int4/int8, the existing- fmt-1/4 shaders): they run every token and are the largest always-on- dense slice that fits VRAM (7.5 GB for all 92 MoE layers at int4);-- a **fill-once routed-expert tier** in fmt=7: experts enter from- freshly-read RAM slots (`K3_VK_UP` per step) until the VRAM budget- (`K3_VK_GB`) is reached. At decode, tier-resident experts skip **both**- the 17.5 MB disk read and the CPU matmuls (one paired w1/w3 submit,- SiTU-GLU on CPU, w2 down). Chunked prefill stays on the CPU-batched path- and still warms the tier.+## Vulkan (`make VK=1 kimi_k3`)++Run with `COLI_VULKAN=1`, a `VK=1` build puts the routed experts on the shared Vulkan+expert tier ([vulkan.md](vulkan.md#the-routed-expert-tier-vk_tierc)): the shards'+MXFP4 bytes as they sit in RAM (e2m1 nibbles, the ue8m0 group exponents widened to+the f32 scales the shader reads, never re-encoded; the fmt 7 kernel against+`matmul_mxfp4`: rel_l2 2.2e-07 on an RX 9070/RADV, 2.6e-07 on llvmpipe,+`tests/test_vk_mxfp4.c`), gate, SiTU-GLU and down on the device, in the latent+space (the tier's hidden is the latent, 3584, its intermediate `moe_inter`, 3072).++- **What is resident adapts.** At startup the tier fills its budget from the expert+ history (`<snap>/.coli_usage`, the hottest first, read in parallel); after that+ every expert the CPU computes is a candidate, and a hotter one displaces the+ coldest resident. The engine's own tier before this one filled once and never+ let go.+- **The device and the CPU work at once, prefill included.** Each MoE step sends+ the (position, rank) pairs whose expert is resident to the device as one batch;+ the CPU reads and computes the other experts of the chunk's union and the shared+ experts meanwhile. An expert the device took entirely is not read from disk.+- **The sum keeps the CPU run's order.** Every pair joins its position in the+ union's disk-offset order, the order a CPU-only run adds them, the device's rows+ and the CPU's alike: which experts were resident never changes the order, and an+ expert computed on the CPU keeps the CPU run's bits.+- **The shared experts** go to the device where `COLI_VK_DENSE` puts the dense+ matrices (int8, int4-g64 or f32, as `K3_BITS` made them; one row at a time, so+ decode): on a discrete GPU the device, on an integrated GPU or Lavapipe the CPU+ while the tier runs. KDA, MLA, the latent projections, the router and the head stay+ on the CPU. With `COLI_VK_TIER=0` the shared experts alone go to the device.++The device computes with f32 activations: its experts match `K3_IDOT=0`, the+configuration of the vendor oracle, while the CPU's default kernel rounds+activations to int8 per 32. With `K3_IDOT=0` a run with the tier gives the CPU's+tokens on the tiny fixture and passes Moonshot's oracle, the eviction and warm-start+cases included (`tests/vulkan_engines.sh kimi`). With `K3_CUDA=1` as well, CUDA+wins and the Vulkan tier stays off. Each run and serve turn ends with+`[VK] kimi_k3: N matmuls on the GPU` and the tier's `[VK] tier kimi_k3` line.++The old switches still work, read as the shared tier's (an explicit shared one+wins): `K3_VK=1` opens the device as `COLI_VULKAN=1` does and `K3_VK=0` keeps it+closed, `K3_VK_GB` is the tier's budget (`COLI_VK_TIER_GB`), a numeric `K3_VK_UP`+its promotions per token (`COLI_VK_TIER_RATE`); `K3_VK_UP=auto` and+`K3_VK_FILL_FRAC` do nothing, since the shared tier uploads on a thread of its own+and never holds a step. One default changed: a `VK=1` build used to open the device+without being asked (`K3_VK` defaulted to 1); it now waits for `COLI_VULKAN=1` or+`K3_VK=1`, like every engine, and without either it is the CPU build's bytes.K3's Quantile-Balancing-flat routing caps what any cache tier can do β the-tier's value scales with how long the server lives (fill-once) and with the-measured short-term reuse (temporal locality), not with marginal expert-heat. `K3_VK=0` disables the tier at runtime.+tier's value scales with how long the server lives and with the measured+short-term reuse (temporal locality), not with marginal expert heat.## Current limitations- Decode is single-token (no speculative decoding β K3 has no MTP head).- Tool declarations/calls and image content are not exposed through the sharedgateway yet; unsupported requests fail explicitly.-- CPU + optional Vulkan tier (no CUDA/Metal).+- CPU + optional Vulkan (the shared expert tier; no CUDA/Metal).- The protocol, tokenizer, gateway, TUI, and Web client paths are locallytestable without the 1.5 TB checkpoint. A release claim still requires onefull-model multi-turn TUI/Web run on a host that owns the complete snapshot.diff --git a/docs/mimo.md b/docs/mimo.mdindex 78bd680d..2f5a4cee 100644--- a/docs/mimo.md+++ b/docs/mimo.md@@ -252,6 +252,35 @@ picture's path at the start of the line, and `coli web` with the upload button:+## On a GPU (Vulkan)++A `make mimo VK=1` build run with `COLI_VULKAN=1` puts the routed experts on the+shared Vulkan expert tier ([vulkan.md](vulkan.md#the-routed-expert-tier-vk_tierc)):+the release's MXFP4 bytes as they sit in RAM, the e8m0 group exponents widened to+the f32 scales the shader reads, SwiGLU on the device. Each MoE step sends the+(row, choice) pairs whose expert is resident to the device as one batch, and the+CPU reads and computes the others meanwhile; an expert the device holds is not read+from disk. Every row then adds its experts in its own routing order, the device's+and the CPU's alike, as the CPU run does. The engine keeps no expert history, so+the tier starts empty and fills as experts pass by: the experts the CPU computed are+offered to it after each step (at most `COLI_VK_TIER_RATE` per token), and once its+budget is full a hotter expert displaces the coldest resident. The router stays on+the CPU, so the experts chosen are the CPU's.++The dense matrices follow the backend's one rule (`COLI_VK_DENSE`): on a discrete+GPU they go to the device; on an integrated GPU or Lavapipe, whose memory is the+CPU's RAM, they stay on the CPU while the tier runs. `COLI_VK_TIER=0` (or+`MIMO_VK_EXPERTS=0`) keeps the experts on the CPU and the dense matrices on the+device, as before the tier.++The device computes with f32 activations, as the CPU does by default: a run with the+tier gives the CPU run's tokens on the tiny fixture in every dense format, text and+picture, and passes Xiaomi's oracle (`tests/vulkan_engines.sh mimo-qwenimage`). Its+logits differ from the CPU's in the last digits, which depend on which experts were+resident: the byte-exact properties above (block invariance, a prompt resumed from a+photo equal to the same prompt computed cold) are the CPU's, and hold with+`COLI_VULKAN` unset, where the engine is the bytes it was before the tier.+## Environment| Variable | Default | Effect |@@ -267,5 +296,5 @@ picture's path at the start of the line, and `coli web` with the upload button:| `MIMO_LOGITS` | unset | Oracle: dump every prompt position's logits (f32) to this file. || `MIMO_TRACE` | unset | Oracle: dump the residual after every sublayer of the first block. || `MIMO_DIRS` | unset | Extra directories holding shards (multi-disk). |-| `COLI_VULKAN` | 0 | 1, in a `make mimo VK=1` build: the dense matrices (qkv, o_proj, the dense MLP, lm_head, and the vision tower's) are uploaded at start-up and run on the GPU in the form `MIMO_DENSE_BITS` gave them: FP8 with its 128-column block scales and BF16 by default, int8 with 8, f32 with 32. The router stays on the CPU, so the experts chosen and read from disk are the CPU's. A matrix that does not fit stays on the CPU. |-| `MIMO_VK_EXPERTS` | 0 | With `COLI_VULKAN=1`: up to this many routed experts are copied to the GPU, as the release's MXFP4, the first time they run from the RAM cache, and stay there for the rest of the run; uploads stop at this count or when the device's memory budget (less half a GB) is reached. 0 keeps every expert on the CPU. |+| `COLI_VULKAN` | 0 | 1, in a `make mimo VK=1` build: the routed experts go to the shared Vulkan expert tier, and the dense matrices (qkv, o_proj, the dense MLP, lm_head, and the vision tower's) to the device where `COLI_VK_DENSE` puts them, uploaded at start-up in the form `MIMO_DENSE_BITS` gave them: FP8 with its 128-column block scales and BF16 by default, int8 with 8, f32 with 32. See [On a GPU](#on-a-gpu-vulkan). |+| `MIMO_VK_EXPERTS` | unset | With `COLI_VULKAN=1`: 0 keeps every routed expert on the CPU (no tier); N sizes the expert tier's budget at N experts (`COLI_VK_TIER_GB`, which wins when set). Unset: the tier's own budget. Kept from the engine's own tier before the shared one, which filled up to N and never evicted. |diff --git a/docs/vulkan.md b/docs/vulkan.mdindex 50cce46d..aec699de 100644--- a/docs/vulkan.md+++ b/docs/vulkan.md@@ -85,8 +85,8 @@ re-pin from history.Every engine links the same backend in a `VK=1` build (`make <engine> VK=1`;`make deepseek-v4 VK=1` for DeepSeek V4) and opens it with `COLI_VULKAN=1` once its-weights are loaded. Kimi K3 has its own expert tier (`K3_VK`, see-[ENVIRONMENT.md](ENVIRONMENT.md)) and glm53 its own section in+weights are loaded. Kimi K3 also reads its older switch `K3_VK=1` (see+[ENVIRONMENT.md](ENVIRONMENT.md)), and glm53 has its own section in[glm53-flash.md](glm53-flash.md). For the engines below, a missing device or missingshaders prints `[VK] <engine>: no usable Vulkan device ..., running on the CPU` andthe run continues on the CPU. That differs from the GLM engine above, which exits.@@ -101,16 +101,15 @@ runs the routed-expert tier ([below](#the-routed-expert-tier-vk_tierc)): there tstay on the CPU and the device takes the experts. On a Radeon 780M the dense matmuls,one synchronous call each at the GPU's 800 MHz floor, cost more than the tier gained(Qwen3.8 decode at 2.35 tok/s with them on the device, 3.80 without). Today that-case is qwen36 and qwen38; an engine that moves to the tier inherits it. A discrete+case is qwen36, qwen38, kimi_k3 and mimo; an engine that moves to the tier inherits it. A discreteGPU keeps the dense matrices on the device by default. The GLM engine above readsthe same variable through the same function with its own default, off.What these engines put on the device is their **resident** matrices, in the form-they already hold in RAM, uploaded at the first multiply (MiMo uploads them at-startup). Routed experts arrive from disk on every miss; qwen36 and qwen38 keep a-cache of them on the device with the shared expert tier-([below](#the-routed-expert-tier-vk_tierc)), MiMo an opt-in one of its own, the-others none yet.+they already hold in RAM, uploaded at the first multiply (MiMo and Kimi K3 upload+them at startup). Routed experts arrive from disk on every miss; qwen36, qwen38,+Kimi K3 and MiMo keep a cache of them on the device with the shared expert tier+([below](#the-routed-expert-tier-vk_tierc)), the others none yet.| Engine | On the device | Weight formats | Stays on the CPU ||---|---|---|---|@@ -120,7 +119,8 @@ others none yet.| olmoe | attention q/k/v/o, router, lm_head | f32 | routed experts, embedding || deepseek_v41 | the trunk, vision included | fp8 in 32x32 ue8m0 tiles, bf16 | routed experts || deepseek_v4 | resident dense layers, head, router, compressors | fp8 in 128x128 blocks, bf16 | routed experts, the indexer's `weights_proj`, DSpark stages, the `--oracle` path |-| mimo | trunk and vision tower; up to `MIMO_VK_EXPERTS=N` routed experts | native fp8/bf16, int8, f32 (`MIMO_DENSE_BITS`); experts as MXFP4 | router |+| kimi_k3 (Kimi K3) | the shared experts' matrices (one row at a time: decode); routed experts on the expert tier | shared experts int8 rows, int4-g64, f32 (`K3_BITS`); experts MXFP4 with ue8m0 scales (fmt 7), SiTU-GLU in the latent space | KDA, MLA, the latent projections, router, head, prefill's shared experts, the experts the tier does not hold |+| mimo | trunk and vision tower; routed experts on the expert tier | native fp8/bf16, int8, f32 (`MIMO_DENSE_BITS`); experts MXFP4 with e8m0 scales (fmt 7) | router, the experts the tier does not hold || qwenimage | the DiT's matrices | int8, bf16, f32 (`COLI_IMG_BITS`) | text encoder, VAE, attention |Each engine ends a run, and each serve turn, with@@ -138,7 +138,10 @@ them by f32 activations.kernel (`QWEN_EXPERT_ACT`, int8 by default): the expert tier's experts match`QWEN_EXPERT_ACT=f32`, to 2.5e-7 of the logits on the test fixture;- qwen38's int8 trunk;- - qwenimage's `COLI_IMG_ACT8`.+ - qwenimage's `COLI_IMG_ACT8`;+ - Kimi K3's routed-expert kernel (`K3_IDOT`, on by default): the tier's experts+ match `K3_IDOT=0`, the configuration of its vendor oracle;+ - MiMo's `MIMO_IDOT=1` (off by default).- Two engines keep the CPU's exact arithmetic instead:- deepseek_v4 rounds activations to E4M3 on the host before the call, as its CPUkernel does.@@ -148,7 +151,7 @@ them by f32 activations.**Memory.** The host copy stays as the CPU fallback. On an integrated GPU or APU,which shares RAM with the CPU, the resident set is therefore held twice: size`RAM_GB`/caps with that in mind. Freed tensors give their device memory back (see-the expert tier's section); MiMo's expert tier still never evicts by its own design.+the expert tier's section).**Status.** CI checks every engine above on Lavapipe (`tests/vulkan_engines.sh`, the`vulkan-engines` job): each configuration gives the CPU run's tokens, and its matmul@@ -303,14 +306,27 @@ of them on the device the way a GPU-equipped PC should use its card:qwen36 and qwen38 fixture configuration are the bytes of the build before thetier (110 configurations: bf16, FP8, int4-g64, int8, the MTP head, every prefillmode, both qwen36 expert kernels, the mixed container, four model geometries).+ The same holds for kimi_k3 (30 configurations, every step's logits) and mimo (32,+ text and picture, every prompt position's logits). One default moved with it: a+ `VK=1` build of Kimi K3 used to open the device without being asked (`K3_VK=1` was+ the default); it now waits for `COLI_VULKAN=1` (or `K3_VK=1`) like every engine.Engines on the tier today: **qwen36** (Qwen3.6, Qwen3-Coder, the 2.4T geometry: int8per row or gs64, int4 per row or gs64 from either expert kernel, the mixed int4/int8container) and **qwen38** (Qwen3.8 Flash Next: the int4-g64 sidecar, the release'sFP8 with 128x128 block scales, BF16). The MTP head's layer of qwen38 stays on the CPU-(its experts are FP8 beside an int4 sidecar). GLM-5.2's `COLI_VK_EXPERTS`, Kimi K3's-`K3_VK` and MiMo's `MIMO_VK_EXPERTS` are the older per-engine tiers; the others move-to this one in the next phase, see [Adding an engine](#adding-an-engine-to-the-tier).+(its experts are FP8 beside an int4 sidecar). **kimi_k3** (Kimi K3: the checkpoint's+MXFP4 with ue8m0 scales, SiTU-GLU on the device, the experts in the latent space,+warm-started from its expert history) and **mimo** (MiMo-V2.6 Flash and Pro: the+release's MXFP4, SwiGLU; no history, so the tier fills as experts pass by) joined+it from their own tiers, which filled once and never evicted: Kimi K3's `K3_VK`,+`K3_VK_GB`, `K3_VK_UP` and MiMo's `MIMO_VK_EXPERTS` are now read as this tier's+switches ([ENVIRONMENT.md](ENVIRONMENT.md)). Both add every pair of a row in the+CPU run's order (Kimi K3: its union's disk-offset order; MiMo: the row's routing+order), and offer the experts the CPU computed after the join, so that a promotion+that displaces a resident frees it at once. GLM-5.2's `COLI_VK_EXPERTS` is the older+per-engine tier; the others move to this one in the next phase, see [Adding an+engine](#adding-an-engine-to-the-tier).With the CUDA expert tier built and on (`COLI_CUDA=1`) as well, **CUDA wins**: theVulkan tier stays off and says so (`[VK] tier <engine>: the CUDA expert tier is on@@ -543,10 +559,8 @@ What each remaining engine needs, from reading its code:| colibri.c (GLM-5.2) | int4 per row `I4U_PAIRS_ROW`, int4-gs `I4U_PAIRS_GS`, int3-g64 `I3_G64`; gate, up, down separate | SwiGLU | `moe()`'s Vulkan block replaces the `COLI_VK_EXPERTS` registry | sums per expert in union order today: move to rank order; fmt 6 (E8/IQ3, rotated input) stays on the CPU; the MTP layer is int8 (another format); the block now serves only S <= 4 || glm53 | int4 gs64 `I4U_PAIRS_GS` 64 | SwiGLU with `swiglu_limit` | `ffn_layer` | its CPU clamps even at limit 0 (no guard), the shader treats 0 as no clamp: pass the config's value and check `L > 0` on the CPU side first; shared expert written first || inkling | one `gate_up` tensor [2I, D], rows 0..I-1 gate: pass `g = p13`, `u = p13 + I rows`; int4 per row `I4U_PAIRS_ROW` or int8 `I8_ROW` | SwiGLU | `moe` | routed and shared weights normalized together, `route_scale x rgs` already in the weights |-| kimi_k3 | MXFP4 `MXFP4_E8M0` 32, gate `w1`, up `w3`, down `w2` | SiTU-GLU, a = 4, b = 25 (`VKT_ACT_SITU`) | `moe_forward` / `expert_apply` (experts in the latent space) | replaces `K3_VK` (synchronous, never evicts); the CPU's `K3_IDOT` rounds activations to int8 || deepseek_v41 | MXFP4 `MXFP4_E8M0` 32 | SwiGLU with limit | `moe_run_at` (already sums per (row, rank) in rank order) | DSpark stages have caches of their own || deepseek_v4 | FP4 + ue8m0/32 = `MXFP4_E8M0` 32; pinned experts are repacked rows16 | SwiGLU with limit, **plus** bf16 rounding of gate/up, the route weight applied before down and bf16 rounding of the output | `moe_token_pipeline` (ascending expert id), `v4_moe_batch_union` | needs an activation variant with those roundings and the host's E4M3 rounding of x (as its fp8 dense path does); undo rows16 or keep pinned experts off the tier; hash-routed layers |-| mimo | MXFP4 `MXFP4_E8M0` 32, stored down, ds, gate, gs, up, us | SwiGLU | `moe` | replaces `MIMO_VK_EXPERTS` (synchronous, never evicts) || olmoe | int8 per row `I8_ROW`, one merged tensor g, u, d | SwiGLU | `moe` | history only with `COLI_USAGE` |## Correctness@@ -570,7 +584,12 @@ What each remaining engine needs, from reading its code:independent of the batch, and the tier pool's budget with frees while a batch isin flight. `tests/vulkan_engines.sh qwen` gives the CPU's tokens with the tier onin every qwen36 and qwen38 expert format, under eviction, with MTP and with the- trunk on the CPU; `qwen-sanitize` runs the same under ASan and UBSan.+ trunk on the CPU; `qwen-sanitize` runs the same under ASan and UBSan. `kimi` and+ the mimo half of `mimo-qwenimage` do it for Kimi K3 and MiMo: Moonshot's and+ Xiaomi's oracles with the tier on, the CPU's tokens in every dense format with the+ trunk on the device and on the CPU, a budget of two experts that must evict, the+ old switches, Kimi K3's warm start; `kimi-mimo-sanitize` runs the tier's+ configurations under ASan and UBSan.- int4 weights decode as offset-binary (nibbleβ8), byte-identical layout tothe CPU path β no repacking.- Khronos validation layers: the backend never enables them, so the loader