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: Brio on MiMo, and what a snapshot has to hold

JustVuggd92056927801
diff --git a/docs/api.md b/docs/api.md
index e8cd2327..bf3a4ad3 100644
--- a/docs/api.md
+++ b/docs/api.md
@@ -165,8 +165,9 @@ the argmax. Per-token values are printed by the engine to six decimal digits of
Non-finite values (a degenerate all-`-inf` logit row, say) serialize as JSON `null`, never
a clamped number.
-These endpoints request the numeric per-token channel only from a glm engine; on every
-other engine the request returns a named 400 rather than being silently ignored. That is a
+These endpoints request the numeric per-token channel only from a glm or a MiMo engine,
+the two that read out every prompt position `echo` needs; on every other engine the
+request returns a named 400 rather than being silently ignored. That is a
statement about what these endpoints request, and about nothing else.
Known limitations, current build:
diff --git a/docs/brio.md b/docs/brio.md
index d9557cc0..01b7dba4 100644
--- a/docs/brio.md
+++ b/docs/brio.md
@@ -374,6 +374,40 @@ Send `pin=1` wherever you want a return point. The engine matches by token ids,
nothing needs to be declared in advance, and it refuses a snapshot whose attention
rows the state no longer holds.
+## What a snapshot holds
+
+A snapshot is not always just token ids. It must hold everything a layer carries from one
+token to the next, or the option that resumes from it starts from a state that never
+existed, and the numbers stay plausible. What that is depends on the model:
+
+- **Attention rows indexed by position** (every full-attention layer) stay where they
+ are. Nothing written after the snapshot lands below it, so the snapshot holds only
+ the ids, and the engine checks that the state still holds those ids before it trusts
+ the rows. An unrelated prompt in between rewrites them; the snapshot is then
+ released and the option is computed from the start.
+- **Recurrent state** (the DeltaNet layers of Qwen3.6 and Qwen3.8) is copied into the
+ snapshot, because a recurrence cannot be rewound.
+- **Sliding-window rings** (MiMo-V2.6: 39 of its 48 layers attend the last 128
+ positions) are copied too. A windowed layer keeps position p in slot p mod 128, so
+ the first option writes its own tokens over the slots of the snapshot's last
+ positions. Without the copy, the second option would read the first one's keys.
+ On MiMo-V2.6 Flash that is about 50 MB per snapshot.
+
+A prompt with a **picture** never takes a snapshot and never resumes from one. Its ids
+describe where the picture goes, not what it shows.
+
+**The read-out starts where the snapshot ends**, not where the shared text ends. Two
+options share the text before them, and stopping there would leave the first option
+token without the logits that predict it. On MiMo and GLM a prompt read out with no
+snapshot to resume from is read out from position 0, never from a live prefix. That
+is what `echo` on `/v1/completions` needs.
+
+The serve tests hold an engine to both halves on its tiny fixture
+(`tests/test_brio_serve.py`, and `tests/test_mimo_prefix_serve.py` for MiMo's rings and
+pictures). An option read through the snapshot must give the numbers a cold engine gives,
+to the last printed digit. It must also **process only its own tokens**: checking the
+numbers alone would pass on an engine that quietly recomputed everything.
+
## Cost, measured
qwen36 (22 GB, 40 layers) over the gateway, one KV slot:
@@ -398,6 +432,9 @@ Note that these are on a disk-streaming engine, where the prefill costs about
indistinguishable.
- **The snapshot lives in the engine process.** Restart the server and the first
request pays the full prefill again.
+- **Snapshots cost memory where they carry state.** `COLI_PIN_SLOTS` (default 4) bounds
+ how many the engine keeps: about 50 MB each on MiMo-V2.6 Flash, tens of MB on Qwen3.6,
+ only the ids and the final logits on engines with nothing else to keep.
- **One KV slot means one conversation at a time.** With several slots, requests
sharing a `state` are routed to the same slot so they share the snapshot; with one,
interleaved clients evict each other.
diff --git a/docs/mimo.md b/docs/mimo.md
index 741e7f5b..78bd680d 100644
--- a/docs/mimo.md
+++ b/docs/mimo.md
@@ -94,6 +94,43 @@ first. `coli chat` starts with thinking off, because at about 1 tok/s the templa
default reasoning is minutes of tokens before the answer; `coli chat --think` turns it
on (the web has its own reasoning toggle).
+## Brio mode and prompt reuse
+
+[Brio mode](brio.md) works on MiMo as on the other engines. `POST /v1/brio` scores a
+closed set of options instead of generating, and `logprobs` on `/v1/chat/completions` and
+`/v1/completions` (with `echo`) is served too. What is particular to MiMo is what a
+snapshot (`SUBMIT pin=1`) has to hold:
+
+- the **9 full-attention layers** keep their K/V rows by position, and nothing after the
+ snapshot writes below it, so they stay in place. The snapshot holds the token ids, and
+ the engine checks that the state still holds them before resuming. A prompt that
+ diverged in between has rewritten them, and the snapshot is released;
+- the **39 sliding-window layers** keep a ring of 128 slots, position p in slot p mod 128,
+ with the position each slot holds. The first option overwrites the slots of the
+ snapshot's last positions, so the ring is copied into the snapshot and back: about
+ 50 MB per snapshot on Flash (39 x 128 x 8 heads x (192 + 128) floats), bounded by
+ `COLI_PIN_SLOTS` (default 4);
+- the position, which is the snapshot's length. Nothing else carries over from one
+ token to the next: the sinks are weights and the router has no state.
+
+A prompt with a picture takes no snapshot and resumes from nothing, neither a snapshot
+nor the previous turn's state: its ids do not describe the image.
+
+A read-out (`logprobs=k`) resumes only from a snapshot, whose saved logits predict the
+first fresh token. With no snapshot it reads every position from 0, the first one
+carrying `nan`. It never resumes from the live state of the previous turn, because the
+positions before it would have no frame. A chat turn without `logprobs` keeps the
+ordinary prefix reuse.
+
+Resuming is exact to the bit, and that needed one change to the forward. The MoE output
+of a row used to be summed in the order its experts first appeared **in the prefill
+block**, which depends on the other rows of the block. The same position came out with
+different low bits in a 64-row block than in a one-row resume, up to 1.2e-4 on the
+fixture's logits. Each row's experts are now added in the order its own router chose
+them, so a row depends on its own inputs only. A decode step adds in the same order as
+before. A prefill now gives the bits that feeding the prompt one token at a time always
+gave.
+
## Correctness
`make -C c mimo-tiny-check` generates a tiny checkpoint (numpy, deterministic) stored
@@ -102,7 +139,16 @@ Xiaomi's own `modeling_mimo_v2.py` (vendor files pinned by SHA-256,
`tools/make_mimo_ref.py`): greedy and teacher-forced, with and without a picture,
every exact configuration of the engine (native dense, an expert cache that evicts
at every layer, prefill in blocks of 1 and 3), and checks that corrupting an expert
-scale, the qkv scale grid or the picture changes the answer. The gateway's patches
+scale, the qkv scale grid or the picture changes the answer. It also requires the logits
+to be the same **bytes** whatever the prefill blocks and the expert cache, text and
+picture: that is what lets a prompt resumed from a prefix or a snapshot equal the same
+prompt computed cold.
+
+`make -C c mimo-tiny-serve-check` serves the same fixture and compares against a cold
+engine, frame by frame: prefix reuse across turns, Brio options that slide the window
+past the snapshot, nested snapshots and a sibling question, a snapshot made stale by an
+unrelated prompt, prompts with a picture, and `/v1/brio` and chat logprobs through the
+gateway. Every option must process only its own tokens. The gateway's patches
match the official Qwen2-VL processor bit for bit on the fixture's picture.
On the real checkpoint, `tools/mimo_real_check.py` builds Xiaomi's model from the