Skip to content

Run frontier MoE models on hardware you already own β€” pure C, zero deps, experts streamed from disk. Tiny engine, immense model. 🐦

C

docs: the deepseek engines on the routed-expert tier

JustVuggf4321736dc9a
diff --git a/docs/ENVIRONMENT.md b/docs/ENVIRONMENT.md
index 442f67f5..1e21b197 100644
--- a/docs/ENVIRONMENT.md
+++ b/docs/ENVIRONMENT.md
@@ -19,8 +19,8 @@ what follows, but the sister engines read their own:
| `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) |
+| `deepseek_v4` | `c/deepseek_v4.c` | `CTX`, the `V4_*` / `DSV4_*` families, the two `COLI_CUDA_*_BATCH` gates and the Vulkan expert tier's `COLI_VK_TIER*` β€” 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 and the Vulkan expert tier's `COLI_VK_TIER*`: 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) |
Setting an `INK_*` variable while running `colibri` does nothing, and vice
@@ -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, deepseek_v41 and deepseek_v4), 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)
@@ -495,6 +495,7 @@ usage rewrite; the shared `USAGE_SAVE=0` covers this engine too.
| Variable | Default | Effect |
|---|---|---|
+| `COLI_VULKAN` | `0` | `make deepseek-v4 VK=1` build: the resident dense layers, head, router and compressors on the Vulkan device, and the routed experts on the shared expert tier (`COLI_VK_TIER*`, `COLI_VK_DENSE`, see [Vulkan](#vulkan-any-gpu-with-a-vulkan-12-driver)) with DeepSeek V4's own activation, which makes the CPU kernel's bf16 and E4M3 roundings on the device ([vulkan.md](vulkan.md#deepseek-v4s-activation)). The tier's history is the store's `<model>/.coli_usage`; a routing the device served counts in it as one the CPU computed. With the CUDA tier on (`DSV4_CUDA`), CUDA wins and the Vulkan tier stays off. |
| `COLI_V4_ROWS16` | `1` (on) | Repack hot-pinned experts into the vectorized `rows16` layout. **While this is on, greedy output varies run to run on the same machine** (#1136): rows16 and the reference matvec accumulate in different orders, and which experts take which kernel follows the expert-cache state. `=0` runs the reference matvec for every expert β€” slower, but the kernel variable is gone. **Set `=0` for any quality A/B on this engine**; throughput A/Bs do not need it. |
**Reproducible greedy runs (#1136):** greedy text on this engine varies with
@@ -517,6 +518,7 @@ Read **only** by `c/deepseek_v41.c`. See [deepseek-v41.md](deepseek-v41.md).
| Variable | Default | Effect |
|---|---|---|
| `V41_ENGRAM_ROWS` | 65536 | DeepSeek V4.1: rows of engram cache per table. The n-gram traffic is Zipfian, so a small cache absorbs most of it; 65536 rows is 64 MB per table on the released head_dim. |
+| `COLI_VULKAN` | `0` | DeepSeek V4.1, `VK=1` build: the trunk (vision tower included) on the Vulkan device, and the backbone's routed experts on the shared expert tier (`COLI_VK_TIER*`, `COLI_VK_DENSE`, see [Vulkan](#vulkan-any-gpu-with-a-vulkan-12-driver)); the DSpark stages keep their experts on the CPU. With the tier on, the engine keeps the expert history `COLI_USAGE` (default `<snap>/.coli_usage`), saved at every run and serve turn end; it keeps none otherwise. |
| `V41_INDEX_OWNER` | unset | DeepSeek V4.1: score each layer against its OWN index keys instead of the last published cache. The default reproduces the released inference code; this changes the model's behaviour, see docs/deepseek-v41.md. |
| `V41_MAX_IMAGE_TOKENS` | the checkpoint's `max_image_tokens` | DeepSeek V4.1: ceiling on what one image costs in prompt tokens. |
| `V41_TRACE` | unset | DeepSeek V4.1: print per-sublayer checksums, matching tools/dsv41_ref.py's, to locate a divergence by diffing two columns. `2` follows the first row of a speculative step rather than the last. |
diff --git a/docs/deepseek-v4.md b/docs/deepseek-v4.md
index 30a2b0df..b5d04b20 100644
--- a/docs/deepseek-v4.md
+++ b/docs/deepseek-v4.md
@@ -310,6 +310,49 @@ generic build. It is deliberately independent of what the binary contains: a
`CUDA_ARCH=portable` build has no sm_61/sm_75 cubin, and running it on such a
card fails at launch with `"no kernel image is available"` rather than producing
a wrong answer. Build with `portable-pre-ampere` for those cards.
+## Vulkan (`VK=1`, any GPU with a Vulkan 1.2 driver)
+
+`make deepseek-v4 VK=1` (libvulkan and `glslc` at build time) links the shared
+Vulkan backend and its routed-expert tier; `COLI_VULKAN=1` opens the device once
+the engine has loaded. No usable device, or no shaders, and the run stays on the
+CPU with one `[VK] deepseek_v4:` line that says so. Two things go to the device:
+
+- **The matrices the engine keeps for its whole life**: the resident dense layers
+ (fp8 128x128 blocks as fmt 12, fed the activation after the CPU's own E4M3
+ rounding), the bf16 head, router and compressors (fmt 11). The `--oracle` path's
+ per-forward copies, the indexer's `weights_proj` and the DSpark stages stay on
+ the CPU.
+- **The routed experts**, on the shared tier ([vulkan.md](vulkan.md#the-routed-expert-tier-vk_tierc)):
+ a cache on the device that fills from the history and adapts while you chat,
+ computed while the CPU computes the experts it does not hold. The experts go up
+ as the store reads them, fp4 with a ue8m0 scale per 32 (MXFP4, fmt 7), with an
+ activation of this engine's own that makes every rounding its CPU expert makes:
+ x to E4M3 per 128 (on the host), gate and up to bf16, the weighted activation to
+ bf16, down's input to E4M3 per 128, the output to bf16
+ ([DeepSeek V4's activation](vulkan.md#deepseek-v4s-activation)). The decode step
+ and the prefill union hand the device their routes first, the store lends the CPU
+ only the experts the device did not take, and every position adds its experts in
+ the CPU path's order, so on what was measured (Lavapipe, the tiny fixtures) the
+ device's rows are the CPU's after those roundings: a served prompt's logprobs
+ with every expert on the device come back byte for byte.
+
+Where the dense matrices go follows the backend's one rule: on a device that shares
+the CPU's RAM (an integrated GPU, Lavapipe) they stay on the CPU while the tier is
+on, and `COLI_VK_DENSE=1` puts them on the device anyway. The tier's history is the
+store's `.coli_usage`: its warm start reads the hottest experts straight from disk
+outside the cache, and a routing the device served is counted as a lookup counts
+one (pins, HITS and heat, the saved history). A hot expert the store keeps in its
+rows16 layout is unpacked for the tier, and only when the tier will take it. EMAP
+shows a device-resident expert as tier 2; each run and serve turn ends with a
+`[VK] tier deepseek_v4` line (device and CPU shares, uploads, evictions, the time
+the device hid). With the CUDA tier on, CUDA wins and the Vulkan tier stays off.
+Variables: `COLI_VULKAN`, `COLI_VK_DENSE` and the `COLI_VK_TIER*` family in
+[ENVIRONMENT.md](ENVIRONMENT.md#vulkan-any-gpu-with-a-vulkan-12-driver). CI runs it
+on Lavapipe (`tests/vulkan_engines.sh deepseek`, `deepseek-sanitize`). The only GPU
+it has run on is an Intel Iris Xe through Mesa's Dozen (Direct3D 12 under WSL),
+for correctness: the same ids as the CPU in every configuration above. No speed
+has been measured.
+
## Environment reference (V4 engine)
Defaults in parentheses; all read by `c/deepseek_v4.c` unless noted `.cu`.
diff --git a/docs/deepseek-v41.md b/docs/deepseek-v41.md
index ca1c35ce..0a368a50 100644
--- a/docs/deepseek-v41.md
+++ b/docs/deepseek-v41.md
@@ -353,6 +353,7 @@ and costs the contention. Anything that tries again has to start from that.
| `COLI_MODEL_DIRS` | unset | `;`/`,`-separated directories holding **distinct** shards of the same container, so it can be split across drives with no second copy (see above). |
| `COLI_DISK_WEIGHTS` | unset (startup probe) | the split ratio, one positive weight per drive (`1,1` for an even pair). Unset measures each drive with the engine's own access pattern. |
| `V41_DIRECT` | 1 | read experts with `O_DIRECT` instead of through the page cache. `0` is the buffered arm and the escape hatch; the two paths return identical bytes. |
+| `COLI_VULKAN` | off | `VK=1` build: the trunk on the Vulkan device and the backbone's routed experts on the shared expert tier (see "Vulkan" below; `COLI_VK_DENSE`, `COLI_VK_TIER*` in [ENVIRONMENT.md](ENVIRONMENT.md#vulkan-any-gpu-with-a-vulkan-12-driver)). With the tier on, the expert history `COLI_USAGE` is kept. |
| `V41_ENGRAM_ROWS` | 65536 | rows of engram cache per table. The traffic is Zipfian: common 2-grams repeat constantly, so a small cache absorbs most of it. 65536 rows is 64 MB per table on the released head_dim. |
| `V41_INDEX_OWNER` | unset | each layer scores against its own owner's index keys (see above). Changes the model's behaviour. |
| `V41_MAX_IMAGE_TOKENS` | the checkpoint's `max_image_tokens` | a ceiling on what one image costs in prompt tokens. |
@@ -362,6 +363,34 @@ and costs the contention. Anything that tries again has to start from that.
| `V41_DSPARK_MINACC` | 60 | percent of drafts that must be accepted over a window of ten for drafting to continue; below it, drafts pause for 64 tokens. 60 is the measured break-even, not a guess. |
| `V41_SPEC_FORCE` | unset | oracle mode only: draft the reference's tokens (`1`), corrupt the last one (`2`), use the head's own (`3`), corrupt the first one (`4`) or a different one each round (`5`), to exercise the verification path on a fixture whose draft head is random. |
+## Vulkan (`VK=1`)
+
+`make deepseek_v41 VK=1` links the shared Vulkan backend and its routed-expert tier;
+`COLI_VULKAN=1` opens the device after the weights load (no usable device: one line,
+and the run stays on the CPU). The trunk goes up in the checkpoint's own formats, fp8
+in 32x32 ue8m0 tiles and bf16, vision tower included. The backbone's routed experts go
+to the shared tier ([vulkan.md](vulkan.md#the-routed-expert-tier-vk_tierc)) as the
+container stores them, fp4 with a ue8m0 scale per 32 (MXFP4, fmt 7), with the clamped
+SwiGLU: a cache on the device that fills from the history and adapts while you chat,
+computed while the CPU computes the experts it does not hold. `moe_run_at` hands each
+block of positions to the device first, computes the other draws expert-major as
+before and the shared expert beside them, then adds every rank in rank order, the
+device's rows and the CPU's alike, and the shared expert last: the CPU path's order,
+whatever was resident. The DSpark stages keep their own experts and caches on the
+CPU; a verify's rows take the device like any others.
+
+On a device that shares the CPU's RAM (an integrated GPU, Lavapipe) the trunk stays on
+the CPU while the tier is on (`COLI_VK_DENSE=1` puts it on the device anyway). The
+engine keeps an expert history only while the tier is on (`COLI_USAGE`, default
+`<snap>/.coli_usage`, saved at every run and serve turn end): the next run's warm
+start reads its hottest experts from the container in parallel. EMAP shows a
+device-resident expert as tier 2, and each run and serve turn ends with a
+`[VK] tier deepseek_v41` line. On Lavapipe every tiny oracle, the 40-token prompt,
+DSpark at every forced acceptance and a budget that evicts give the CPU's tokens
+(`tests/vulkan_engines.sh deepseek`; `deepseek-sanitize` under ASan and UBSan), and so
+do they on an Intel Iris Xe through Mesa's Dozen, the one GPU it has run on (for
+correctness; no speed has been measured).
+
## Reusing a turn, and why it is asked for rather than assumed
A chat client resends the whole conversation every turn. Every other engine in
diff --git a/docs/vulkan.md b/docs/vulkan.md
index 50cce46d..33f69298 100644
--- a/docs/vulkan.md
+++ b/docs/vulkan.md
@@ -101,14 +101,14 @@ runs the routed-expert tier ([below](#the-routed-expert-tier-vk_tierc)): there t
stay 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, deepseek_v41 and deepseek_v4; an engine that moves to the tier inherits it. A discrete
GPU keeps the dense matrices on the device by default. The GLM engine above reads
the 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
+startup). Routed experts arrive from disk on every miss; qwen36, qwen38, deepseek_v41
+and deepseek_v4 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.
@@ -118,8 +118,8 @@ others none yet.
| qwen38 (Qwen3.8 Flash Next) | the trunk; routed experts on the expert tier | int8 trunk rows, bf16, f32 (`Q38_NATIVE_BF16=0`); experts int4-g64 (sidecar), FP8 128x128 blocks, bf16 | the MTP head's experts, the experts the tier does not hold |
| inkling | dense and shared-expert matrices | int8 and int4-g64 (dense-int4g64 container), f32, bf16 | routed experts, embedding and audio lookups, CUDA residents; bf16 on CPUs with the AVX512-BF16 dot (see below) |
| 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 |
+| deepseek_v41 | the trunk, vision included; routed experts on the expert tier | fp8 in 32x32 ue8m0 tiles, bf16; experts MXFP4 (fp4, a ue8m0 scale per 32) | the DSpark stages and their experts, the experts the tier does not hold |
+| deepseek_v4 | resident dense layers, head, router, compressors; routed experts on the expert tier | fp8 in 128x128 blocks, bf16; experts MXFP4 (fp4, a ue8m0 scale per 32) with [an activation of its own](#deepseek-v4s-activation) | the indexer's `weights_proj`, DSpark stages, the `--oracle` path's dense layers, the experts the tier does not hold |
| 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 |
| qwenimage | the DiT's matrices | int8, bf16, f32 (`COLI_IMG_BITS`) | text encoder, VAE, attention |
@@ -141,7 +141,8 @@ them by f32 activations.
- qwenimage's `COLI_IMG_ACT8`.
- Two engines keep the CPU's exact arithmetic instead:
- deepseek_v4 rounds activations to E4M3 on the host before the call, as its CPU
- kernel does.
+ kernel does; its routed experts on the expert tier make every rounding its CPU
+ expert makes ([DeepSeek V4's activation](#deepseek-v4s-activation)).
- inkling leaves its bf16 matrices on the CPU when the build has the AVX512-BF16
dot (Zen 4/5, Sapphire Rapids), because that dot rounds activations to bf16.
@@ -303,12 +304,20 @@ 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 the
tier (110 configurations: bf16, FP8, int4-g64, int8, the MTP head, every prefill
mode, both qwen36 expert kernels, the mixed container, four model geometries).
+ The same holds for deepseek_v41 and deepseek_v4 (40 comparisons per build: every
+ tiny oracle, the 40-token prompt, DSpark at every forced acceptance, the three V4
+ cases' oracle records on the 4- and the 8-expert fixture, served logprob echoes, and
+ the engines' C tests).
Engines on the tier today: **qwen36** (Qwen3.6, Qwen3-Coder, the 2.4T geometry: int8
per row or gs64, int4 per row or gs64 from either expert kernel, the mixed int4/int8
container) and **qwen38** (Qwen3.8 Flash Next: the int4-g64 sidecar, the release's
FP8 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
+(its experts are FP8 beside an int4 sidecar). **deepseek_v41** (DeepSeek V4.1 Flash) and
+**deepseek_v4** (DeepSeek V4 Flash) put their fp4 experts (MXFP4 with ue8m0 scales) on
+it as the checkpoint stores them; their DSpark stages keep their own experts on the
+CPU, and deepseek_v4's experts take [an activation of their own](#deepseek-v4s-activation).
+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).
@@ -329,7 +338,7 @@ the device, since no Vulkan tier runs.
| `COLI_VK_TIER_GEMM_ROWS` | `16` | Rows from which an expert of a step takes the tiled GEMM instead of the per-row GEMV; `0` never. |
| `COLI_VK_TIER_QUEUE` | a second queue | `0`: the tier shares the main queue (its batches and the dense matmuls then serialize). |
| `COLI_VK_DENSE` | on, but off on a device sharing the CPU's RAM while the tier is on | `0`: the dense trunk stays on the CPU and the device takes the routed experts only; `1`: the trunk on the device whatever the device. Unset: on a discrete GPU, or with the tier off, on the device; on an integrated GPU or Lavapipe with the tier on, on the CPU. The startup line says which and why. (The GLM engine reads it through the same rule with its own default, off.) |
-| `COLI_USAGE` | `<snap>/.coli_usage` | The history the warm start reads. qwen38 always keeps it; qwen36 keeps it only while the tier is on, and saves it at the end of every run and serve turn. |
+| `COLI_USAGE` | `<snap>/.coli_usage` | The history the warm start reads. qwen38 always keeps it; qwen36 and deepseek_v41 keep it only while the tier is on, and save it at the end of every run and serve turn. deepseek_v4 reads its expert store's own (`<model>/.coli_usage`, always kept), not this variable. |
**The budget.** On a discrete GPU: what `VK_EXT_memory_budget` says is free in
device-local memory, less the reserve and the dense weights the engine is about to
@@ -382,6 +391,43 @@ The dashboard's expert map (`EMAP`) shows a device-resident expert as tier 2 (VR
the experts a device step served still light up in `HITS`, and qwen36's
`CACHE_ROUTE` ranks them like CUDA-resident ones.
+### DeepSeek V4's activation
+
+DeepSeek V4's CPU expert rounds more than the others do: gate and up to bf16 before
+the SwiGLU, the activation times the route weight to bf16, then down's input to E4M3
+with one power-of-two scale per 128 values (its fp4 kernel rounds every input that
+way), and down's output to bf16. Left to the plain SwiGLU, a device row would differ
+from the CPU's by those roundings, not by a summation order. So the tier has a third
+activation for it, `VKT_ACT_SWIGLU_V4` (the backend's `COLI_VK_ACT_SWIGLU_V4`):
+
+- the engine rounds x to E4M3 per 128 before `vkt_issue_w`, as its kernel rounds it,
+ and hands the route weights with the routing;
+- the activation shaders (both routes) round gate and up to bf16 and compute the
+ clamped SwiGLU in the CPU's form;
+- `expert_act_v4.comp`, one pass between the activation and down, multiplies each row
+ by its weight, rounds to bf16, and rounds each block of 128 to E4M3 with the CPU's
+ scale (the smallest power of two that brings the block's maximum under 448);
+- the engine rounds each returned row to bf16 and adds it with no weight of its own,
+ in its CPU path's order (ascending expert id, then rank).
+
+What is left between the two sides is the projections' summation order and the
+device's `exp`; on everything measured the roundings absorbed both, though a value
+that lands on a rounding boundary can still go the other way on another driver.
+Measured on Lavapipe: the harness's
+exact-input case gives the CPU's values bit for bit through every rounding (0 of 3840
+differ, and three mutants of the pass each fail it); `vk-tier-check` gives 264 of 264
+device rows bit-identical to the CPU arithmetic on random MXFP4 experts; a served
+71-token prompt with every routed expert on the device gives the CPU's per-position
+logprob echoes byte for byte. On an Intel Iris Xe through Mesa's Dozen the harness
+case is bit for bit too, and every deepseek_v4 and deepseek_v41 tier configuration
+gives the CPU's tokens.
+
+Two things of the engine's own: the store keeps its pinned hot experts in a 16-row
+interleaved layout (rows16), which the tier unpacks to rows only when it will take
+the expert (`vkt_wants`); and a routing the device served is counted as a store
+lookup counts one (pins, HITS and heat, `.coli_usage`), so the history stays the
+routing's whichever side computed it.
+
### Measured on a Radeon 780M
Same box as above (Ryzen 7 PRO 8700GE, 16 threads, 61 GiB DDR5, NVMe, RADV), one
@@ -520,7 +566,7 @@ The integration steps are in [`c/vk_tier.h`](../c/vk_tier.h); in short:
(`VktSrc`: int8 per row or grouped, the int8 copy of an int4 container, int4
pairs signed or `v+8`, `expert_ffn.h`'s planar int4-g64, int3-g64, MXFP4 with f32
or ue8m0 scales, fp8 per group or in square blocks, bf16, f32), the activation
- (`VKT_ACT_SWIGLU` with an optional clamp, `VKT_ACT_SITU`), the most assignments a
+ (`VKT_ACT_SWIGLU` with an optional clamp, `VKT_ACT_SITU`, `VKT_ACT_SWIGLU_V4`), the most assignments a
step carries, the RAM the expert cache may still take and the dense bytes still to
come to the device. `vkt_init(&cfg, rt_counts_all())` after the device and the
history; then `atexit(coli_vk_shutdown)` and `atexit(vkt_shutdown)`, in that
@@ -533,6 +579,9 @@ The integration steps are in [`c/vk_tier.h`](../c/vk_tier.h); in short:
are in RAM; the shared expert; `vkt_join` (when the issue took any); then add
every rank of every row in order, the device's row where `taken`. A failed join
(device lost) leaves the taken pairs to the CPU and turns the tier off.
+ `vkt_issue_w` also hands the route weights (for an activation that applies them on
+ the device); `vkt_wants(l, e)` says whether `vkt_note` would take an expert, for an
+ engine that must convert its RAM form first.
4. **Report**: `vkt_report("run"|"turn", ram_hits, disk_loads)` beside the engine's
`[VK]` line; `vkt_resident(l, e)` gives EMAP its tier 2.
@@ -544,8 +593,8 @@ What each remaining engine needs, from reading its code:
| 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 |
+| deepseek_v41 | MXFP4 `MXFP4_E8M0` 32 | SwiGLU with limit | `moe_run_at` (already sums per (row, rank) in rank order) | **on the tier**: backbone layers only, the DSpark stages keep their caches |
+| deepseek_v4 | FP4 + ue8m0/32 = `MXFP4_E8M0` 32; pinned experts are repacked rows16 | `VKT_ACT_SWIGLU_V4` ([its activation](#deepseek-v4s-activation)) | `moe_token_pipeline` (ascending expert id), `v4_moe_batch_union` | **on the tier**: x rounded to E4M3 on the host, rows16 unpacked when the tier takes one, hash-routed layers as any other |
| 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` |
@@ -571,6 +620,12 @@ What each remaining engine needs, from reading its code:
in flight. `tests/vulkan_engines.sh qwen` gives the CPU's tokens with the tier on
in 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.
+ `tests/vulkan_engines.sh deepseek` does it for deepseek_v41 (every tiny oracle, the
+ 40-token prompt, DSpark, eviction) and deepseek_v4 (the three oracle cases on a 4-
+ and an 8-expert fixture with pinned rows16 experts, eviction, the warm start, the
+ served logprobs), and `deepseek-sanitize` under ASan and UBSan. DeepSeek V4's
+ activation has a case of its own in the harness, checked bit for bit, and in
+ `vk-tier-check`.
- int4 weights decode as offset-binary (nibbleβˆ’8), byte-identical layout to
the CPU path β€” no repacking.
- Khronos validation layers: the backend never enables them, so the loader