Skip to content

V.* — the V-store

Token-ID-indexed storage for K and V tensors, one session per <ns>_pk / <ns>_pv pair created by KV.PREFIX.REGISTER. The wire forms of V.STOREBATCH and V.FETCH … RANGE / BATCH are in the externalized-attention table and the KV.PREFIX.* page; this page covers the storage formats and V.EXPORT, the lane a client on the same machine reads a prefix through.

The export lane — V.EXPORT

A Stage 1 hit from another process used to fetch the prefix's K/V over loopback TCP (V.FETCH BATCH) and rebuild MLX arrays from the reply. When the server is on the same machine, PionPromptCache now asks for the prefix as a file instead: V.EXPORT <ns>_pk <ns>_pv <start> <end> <layers> <kv_heads> <head_dim> writes it once as safetensors (fp16, [1, kv_heads, N, head_dim] per layer, the layout mlx-lm's own cache keeps) and replies with the path, and the hit maps it with mx.load and hands the arrays to the cache as they are, the way load_prompt_cache reads mlx-lm's own file. The file is written when the prefix is stored, so the first hit does not pay for it.

  • Only a client on this machine may ask, and the server picks the name: it lives in $PION_EXPORT_DIR (default ./pion-export), the directory 0700 and the files 0600, written under a temporary name and renamed.
  • A file is named by its sessions' generations, so storing into either session makes the next export a new file and deletes the old one; a hit can never map a stale prefix. A restarted server deletes its previous process's files on its first export.
  • PION_PROMPT_CACHE_NO_EXPORT=1 turns the lane off; a remote host, a server that does not know V.EXPORT, and a cache that is not plain KVCache (sliding-window or hybrid models) keep the TCP lane.

The README's TTFT table has the measured row. Tests: tests/test_v_export.py (every tensor against V.FETCH BATCH, staleness, permissions, refusals).

Quantization tiers

Measured on a 20-question / 50-token-greedy BLEU eval against the standalone reference:

Format Storage vs FP16 Mean BLEU First-token Notes
fp16 1.00× 0.979 100% (20/20) Bit-identical on 19/20, late drift on 1/20. Production default.
int8 ~2× 0.499 95% (19/20) First token right on 19 of 20, but greedy decode drifts within the 50 tokens.
turbo4 3.51× 0.378 90% (18/20) Argmax preserved on most first tokens, but compounds badly over greedy decode. Single-step / classification only.

tests/test_kv_prefix_bleu.py --vquant {fp16,int8,turbo4} on an M4 Mac mini, 2026-10-07 (raw output, kv_prefix_bleu*.txt; the test's own gate is a mean BLEU of 0.95, which only fp16 passes). Until 2026-10-07 each question began with a second <bos>, and the table read 0.969 / 0.677 / 0.538: the stray token drew attention away from the stored prefix and hid part of the quantization error (before_fix/ reproduces those figures exactly). Storage is per token at the 1B model's 512-wide K/V rows: int8 is one byte an element against fp16's two, and turbo4 packs 32 elements into 18 bytes plus a 4-byte row header.

Recommendation: ship vquant=fp16. Document int8 and turbo4 as opt-ins for greedy-tolerant single-step workloads (function-calling tool selection, classification, single-token routing) where the storage win matters more than multi-token fidelity.


The mlx4g32 tier

KV.PREFIX.REGISTER <ns> <kv_dim> mlx4g32 (and V.CREATE ... VQUANT mlx4g32) stores K/V in mlx's QuantizedKVCache layout: int4, group 32, affine.

per token, per layer, D = kv_dim
  [packed uint32 x D/8]   4-bit codes, element j of a group at bits 4*(j%8)
  [scales  fp16  x D/32]
  [biases  fp16  x D/32]

640 B/token at D=1024 against fp16's 2048 — 3.2× smaller, which tests/test_gh148_mlx4g32_tier.py asserts. At that ratio, K/V that takes 12 GB in fp16 takes under 4 GB.

Both parameters are measured, not conventional:

  • group 32, not 64. g64 corrupted recalled facts at digit grain in real generations ("2430-04-22" for "2030-04-22"). Knowledge held as KV is bits-fragile the same way weight-held knowledge is.
  • affine, not symmetric. Storing a per-group scale and bias reconstructs more accurately than symmetric int4 (tests/test_gh148_mlx4g32_tier.py asserts it), and K's error dominates the end-to-end result.

The scale is round-tripped through fp16 before the codes are chosen, so the quantizer targets the scale the reader will actually see.

Heterogeneous K/V (per-layer formats)

PionPromptCache(boundary_protect=N) switches the per-prefix register from the legacy uniform KV.PREFIX.REGISTER to two raw V.CREATE … SCHEMA calls (one per K/V side). K stays fp16 across all layers — K drives softmax routing and tolerates quant noise poorly. V uses fp16 for the first N + last N layers ("boundary protection") and the user's vquant for the middle layers.

# Boundary-protect K-V split: middle layers in fp8, boundary layers in fp16
pc = PionPromptCache(model, vquant="fp8", boundary_protect=2)

fp8 V on the middle layers carries less wire data per layer, and the fp16 boundary layers protect routing. No comparison against uniform fp16 is published with raw output yet, so measure it on your own workload (pion-vllm-mlx/tests/test_prompt_cache_workload.py --vquant fp8 --boundary-protect 2).

Trade-off: the SCHEMA path skips KV.PREFIX.REGISTER's cross-worker directory publish (single-worker visibility only). A future KV.PREFIX.REGISTER.SCHEMA server command would lift this.

boundary_protect requires kv_dim divisible by 32 when vquant ∈ {fp8, turbo4, turbo3, turbo2}. Llama-3.2-1B (kv_dim=512) and Llama-3.2-3B (kv_dim=1024) both qualify.