radiance 1.5.0

- Gemma 4 31B (PRs #74, #75, #81, #86; sfjes, keptn42): sliding and global attention with their
  own kernels, the assistant head as a drafter that reads the trunk's cache, the vision tower, a
  fused w4a8 decode step, bf16 and compressed-tensors int4 checkpoints, and window snapshots so a
  prefix hit on a sliding-window model resumes instead of prefilling again.
  deploy/compose/gemma4-31b-w4a8.yaml serves keptn42's container on two cards
- ParoQuant (PRs #65, #66, #67; malic): Qwen3.8-27B checkpoints with learned Givens rotations,
  as int4, int5 and MXFP4, imported without re-quantising, the prefill's rotations on the matrix
  cores. deploy/compose/qwen3.8-27b-paro.yaml serves them on one card. A ParoQuant container made
  with the PR builds is refused: convert it again with --reuse <old container>
- Gemma 4 26B-A4B with z-lab's DFlash drafter (PR #88; Perire): arch/gemma4 serves Google's bf16
  checkpoint with the routed experts in block fp8 or bf16 (data/recipes/gemma4-26b-a4b-df*.recipe),
  and libr4d gains its windowed paged attention, the fused sandwich-norm joins, expert_scale and
  the sharded draft head's pair_argmax. A prefill chunk runs as two slices with its all-reduces
  beside the compute, bit-exact with the whole step. The 31B's global layers take the windowed
  attention too: an 11.5K-token prefill on two R9700s in 3.1 s instead of 4.9
- a startup that logs nothing for two minutes says where it waits (#89): the system call (a KFD
  request by name), the library that made it, and its stack, which addr2line resolves against the
  binary
- the prefix cache is kept in VRAM and host memory only (#70): the disk tier wrote every block and
  snapshot a prompt produced, and its copies never outlived the process. --prefix-cache-host-mib
  is renamed --prefix-cache-mib; --prefix-cache-dir and --prefix-cache-disk-mib are removed, and
  startup refuses all three with what replaced them. The compose files no longer mount /data, and
  .env no longer needs RADIANCE_STATE
- --prefix-cache-ttl S (default 3600, 0 never): a conversation no request has used for that long
  leaves the cache, whichever tier holds it; radiance:prefix_cache_expired_total counts them. A
  full host tier now drops its least recently used conversations
- --vision-tower-placement vram|ram (#84): ram keeps an encoder tower in pinned host memory and
  gives its VRAM to the KV cache, read over the link once an image
- timings carry ttft_ms and total_ms (#85): the server's own time from the request body's arrival
  to the first and the last token, queueing and tokenisation included
- a KV-cache recall that found a moved expert with nowhere to go stopped halfway and leaked the
  slots it had already freed: after it every recall failed, the cache stayed short until a
  restart, and requests failed with HTTP 500. A recall now waits for the slots it is owed and
  always finishes
- a tool result or tool-call arguments that are not JSON are no longer refused as nesting past
  1024 levels for their unmatched brackets (#90): only text that parses as JSON is held to the
  bound, since nothing else is parsed into a tree
- the host-pool refusal names the limit that applies to pinned memory (RAM less 1/64 and
  1.5 GiB), not ttm.pages_limit
- --embedding-placement auto, removed in 1.3.0, is refused with what replaced it
- for out-of-tree kernel libraries: gemm_nt_q gains two operands (pb1, pb2, the part bounds), and
  the loader requires identical op schemas, so a library built against 1.4.0 must be rebuilt. For
  architecture plugins, rad_op_declared(b, op) asks whether an op is in the loaded vocabulary
  without declaring it
This commit is contained in:
Deadcode committed 2026-10-13 19:35:16 +02:00
commit b93b531f63
127 files changed
+9609 -4796

No files matched your search

-1
View File
@@ -34,7 +34,6 @@ header lists its own). The ones that only attach to a live server need nothing b
| `fntrace.sh` | A Flash-Next prefill under `rocprofv3`, with the link counters from `/stats` across the same request, so the streamed-read rate of the MoE GEMM can be computed. |
| `mctrace.sh` | A MiniCPM5-2B decode trace under `rocprofv3`, formatted for `libr4d/isa/tsum.sh`. The `blocks` column is what the trace is for. |
| `ident.sh` | Run-to-run reproducibility at a fixed configuration: one hash per (temperature, question), to compare against another run of the same configuration. A speculative run is not expected to match a non-speculative one byte for byte — the split-K count is chosen from M, so the two take different reduction orders and can flip a near-tie late in a long answer — but a divergence within the first sentence or two is a defect. |
| `diskstall.py` | What restoring a conversation from the disk tier costs: the returning request's time to first token, and the longest stall it puts on a stream decoding beside it. |
| `cardclock.py` | What holds each card's clock under a sustained load, and which card a tensor-parallel step waits for. The step ends when its slowest rank finishes, and under a sustained load the firmware picks that rank's clock: the power limit, a temperature or current limit, or the top of its voltage/frequency curve. Reads every AMD card's `gpu_metrics` table ten times a second and counts a throttler bit only when the clock is lower while it is set (some firmware keeps a bit on at idle). The engine's own step counters sit beside it per window, so a slow window is told apart first: slower steps, fewer tokens per step (the text), or host time between steps. Drives its own greedy load, or with `--watch` only samples a server that real traffic is driving. `--compare` puts two saved runs side by side. Read-only on the cards. |
| `oracle.sh` | Every op compared against libref on the operands the model actually issued, which is the gap rad-kbench cannot close: its operands are its own, dense and rank-2, and an engine's are slices of arenas and weights off a file. Reads for two things — a MISMATCH, and the NOT CHECKED lines that name the rows whose weight layout has no published inverse and therefore cannot be compared at all. |
-114
View File
@@ -1,114 +0,0 @@
#!/usr/bin/env python3
# diskstall.py -- what bringing a conversation back from DISK costs: the returning request's time to
# first token, and the stall it puts on a conversation decoding beside it.
#
# A restore out of disk is the one tier move that reads files, and where it reads them decides who
# waits. So this measures both halves: the request that asked (TTFT, and how much of its prompt the
# cache served) and a bystander that asked for nothing (the longest gap between its streamed chunks
# while the restore ran, against its median gap outside that window).
#
# scripts/diskstall.py [--port 8100] [--session 20000] [--fill 30000]
#
# THE SERVER MUST HAVE A HOST TIER THE FILLER OVERFLOWS, or the session is restored out of host
# memory and nothing here touches the disk -- the run then says so and exits non-zero:
# --prefix-cache-host-mib 512 --prefix-cache-disk-mib 8192 --prefix-cache-dir <dir>
# holds about 27K tokens on Qwen3.8-Flash-Next, so --session 20000 --fill 30000 puts the session
# on disk. The session must still FIT the host tier: a restore reads through it.
import argparse, json, random, statistics, sys, threading, time, urllib.request
ap = argparse.ArgumentParser()
ap.add_argument("--port", type=int, default=8100)
ap.add_argument("--host", default="127.0.0.1")
ap.add_argument("--session", type=int, default=20000, help="tokens in the returning conversation")
ap.add_argument("--fill", type=int, default=30000, help="tokens of filler that push it out of RAM")
ap.add_argument("--wait", type=int, default=240, help="seconds to wait for it to reach disk")
ap.add_argument("--seed", type=int, default=7)
a = ap.parse_args()
base = f"http://{a.host}:{a.port}"
WORDS = ["ledger", "valve", "crate", "harbor", "signal", "copper", "lantern", "orchard", "gravel",
"tunnel", "beacon", "anchor", "quarry", "saddle", "furnace", "meadow", "cobalt", "pylon"]
def text(seed, ntok):
r = random.Random(seed)
return " ".join(r.choice(WORDS) for _ in range(int(ntok / 1.25)))
def post(path, body, timeout=1800):
req = urllib.request.Request(base + path, data=json.dumps(body).encode(),
headers={"Content-Type": "application/json"})
with urllib.request.urlopen(req, timeout=timeout) as r:
return json.loads(r.read())
def get(path):
with urllib.request.urlopen(base + path, timeout=30) as r:
return json.loads(r.read())
def complete(prompt, n=1):
t0 = time.time()
d = post("/v1/completions", {"model": "m", "prompt": prompt, "max_tokens": n,
"temperature": 0, "stream": False})
u = d.get("usage") or {}
cached = (u.get("prompt_tokens_details") or {}).get("cached_tokens")
return time.time() - t0, u.get("prompt_tokens"), cached
def row_for(tokens):
for s in get("/sessions")["sessions"]:
if tokens <= s["tokens"] <= tokens + 8:
return s
return None
session = text(a.seed, a.session) + "\nName one word above.\nAnswer:"
t, n_prompt, _ = complete(session)
print(f"session {n_prompt} tokens prefilled in {t:.1f}s")
t, n_fill, _ = complete(text(a.seed + 1, a.fill) + "\nName one word above.\nAnswer:")
print(f"filler {n_fill} tokens prefilled in {t:.1f}s")
# ON DISK AND NOWHERE ELSE: not in VRAM (the loan takes a clean entry's blocks), not in RAM (the
# filler's copies took the slots, which the disk copy made free to give up).
t0 = time.time()
while True:
s = row_for(n_prompt)
if s and s["on_device"] == 0 and s["on_host"] == 0 and s["on_disk"] > 0 and not s["moving"]:
break
if time.time() - t0 > a.wait:
print(f"diskstall: the session never left RAM and VRAM for disk: {s}", file=sys.stderr)
sys.exit(1)
time.sleep(1)
print(f"on disk {s['on_disk']} blocks, snapshots host/disk "
f"{s['snap_host']}/{s['snap_disk']}, after {time.time()-t0:.0f}s")
# ---- the bystander: a stream that only decodes ----------------------------------------------------
stamps = []
def bystander():
req = urllib.request.Request(base + "/v1/completions", data=json.dumps({
"model": "m", "prompt": "Write a long story about a lighthouse keeper.\n\n",
"max_tokens": 1500, "temperature": 0.7, "seed": 1, "ignore_eos": True,
"stream": True}).encode(), headers={"Content-Type": "application/json"})
with urllib.request.urlopen(req, timeout=1800) as r:
for line in r:
if line.startswith(b"data:") and not line.startswith(b"data: [DONE]"):
stamps.append(time.time())
th = threading.Thread(target=bystander)
th.start()
while len(stamps) < 40:
time.sleep(0.05)
time.sleep(2.0)
moved0 = get("/sessions")["moved"]
t_ask = time.time()
ttft, n2, cached = complete(session + " the")
t_done = time.time()
moved1 = get("/sessions")["moved"]
time.sleep(2.0)
th.join()
gaps_in, gaps_out = [], []
for x, y in zip(stamps, stamps[1:]):
(gaps_in if y >= t_ask and x <= t_done else gaps_out).append(y - x)
promoted = moved1["promoted"] - moved0["promoted"]
print(f"restore {promoted} entries promoted; prompt {n2} cached {cached}; TTFT {ttft*1000:.0f} ms")
print(f"bystander median gap {statistics.median(gaps_out)*1000:.1f} ms outside the restore, "
f"longest {max(gaps_in)*1000:.1f} ms during it ({len(gaps_in)} chunks)")
if not cached or cached < n_prompt // 2:
print("diskstall: the returning request was not served from the cache", file=sys.stderr)
sys.exit(1)
+11 -19
View File
@@ -45,33 +45,26 @@
# different order and a tie can land on a different token; each chunk size is stable on its
# own. Pin the chunk before recording anything to compare against later.
#
# THE PREFIX CACHE IS TIERED, AND THE ENGINE LEAVES THE TIERS OFF BY DEFAULT. Both
# --prefix-cache-host-mib and --prefix-cache-disk-mib are zero unless asked for, so a server started
# without them drops a conversation's context the moment the pool needs the blocks. This deployment
# keeps finished turns in host memory and then on disk, where they cost the card nothing.
# THE PREFIX CACHE IS TIERED, AND THE ENGINE LEAVES THE HOST TIER OFF BY DEFAULT.
# --prefix-cache-mib is zero unless asked for, so a server started without it drops a conversation's
# context the moment the pool needs the blocks. This deployment keeps finished turns in host memory,
# where they cost the card nothing, for an hour of disuse (--prefix-cache-ttl's default).
#
# The ELASTIC half needs no flag and cannot be turned off: the pool holds the blocks it is using
# plus a buffer derived from the chunk, and the expert slab takes the VRAM it releases. That leans
# on --gpu-headroom-mib, which is why the 96 above matters -- startup names any shortfall and holds
# it back on top of the reserve.
#
# --prefix-cache-host-mib finished conversations are copied here at once and their VRAM goes
# to the expert slab; a return restores instead of re-prefilling. Part
# of it is the linear-state snapshot store, sized in proportion to what
# a session holds in snapshots against blocks; startup says how many
# snapshots it holds. On this model a snapshot is 113 MiB and
# --checkpoint-slots counts snapshots for the whole server, not per
# sequence, so the snapshot store is the binding resource: without it
# only the conversations whose snapshots are still in a device slot
# resume without re-prefilling their whole transcript.
# --prefix-cache-disk-mib every host copy is also written to disk under --prefix-cache-dir, so
# a full host tier gives its oldest slots up for nothing. Costs no RAM
# and no VRAM. It holds conversation content UNENCRYPTED.
# --prefix-cache-mib finished conversations are copied here at once and their VRAM goes to the
# expert slab; a return restores instead of re-prefilling, and a full tier
# drops its least recently used. It holds attention blocks only: the
# linear-state snapshots are in the --checkpoint-slots store, 113 MiB each on
# this model and counted for the whole server, not per sequence.
#
# THE HOST NUMBER IS DELIBERATELY SMALL BECAUSE OF THE N-GRAM TABLE. The tier's arena is PINNED,
# and the 47.68 GiB n-gram (PLE) table is read through the container's own mmap, so it lives in
# the page cache -- and pinned bytes come out of the same host RAM. Taking too much here turns a
# decode step's minor faults into major ones, a far worse trade than a smaller snapshot store.
# decode step's minor faults into major ones, a far worse trade than a smaller host tier.
# Watch /proc/<pid>/stat majflt across a prefill before raising it.
#
# THE CROSS-RANK WIRE IS THE ROTATED 6-BIT ONE (--tp-wire wht6). An all-reduce at or above
@@ -98,8 +91,7 @@ nohup ./bin/radiance --model "$M" \
--max-num-seqs ${SEQS:-8} --max-model-len ${MLEN:-200000} \
--tp ${TP:-2} --placement expert_tiered --host-pool-mib ${HOSTPOOL:-12288} \
--gpu-headroom-mib ${HR:-96} --kv-cache-dtype ${KVD:-fp8} \
--prefix-cache-host-mib ${KVHOST:-4096} \
--prefix-cache-dir ${KVDIR:-$HOME/kvcache} --prefix-cache-disk-mib ${KVDISK:-131072} \
--prefix-cache-mib ${KVHOST:-4096} \
--num-speculative-tokens ${NS:-3} \
--max-num-batched-tokens ${MNBT:-2048} \
--tp-wire ${WIRE:-wht6} \
+24 -36
View File
@@ -8,12 +8,14 @@
# cache can have -- an entry holding reassigned block ids, a checkpoint slot freed by one session
# and still named by another -- need two sessions in flight to show up at all.
#
# THE SCARCE RESOURCE IS THE CHECKPOINT SLOT, so run this with --checkpoint-slots low enough that
# the two sessions fight over it. That is what makes the retention policy and the victim scan run,
# which is what makes a snapshot get retired underneath a record that still names its slot:
# A HOST TIER THE FILLER OVERFLOWS, so the arena's drops run as well as its restores:
#
# --checkpoint-slots 2 --prefix-cache-host-mib 512 --prefix-cache-disk-mib 16384 \
# --prefix-cache-dir <dir>
# --prefix-cache-mib 512
#
# AND ENOUGH SNAPSHOT SLOTS FOR BOTH SESSIONS. On a hybrid model a hit is clamped to the deepest
# snapshot it reaches, and a store too small for both makes each session retire the other's: every
# arm then re-prefills from zero and restores nothing, so the device arm's reuse is checked below.
# The default --checkpoint-slots holds both.
#
# EACH SESSION IS COMPARED ONLY TO ITSELF. A and B are different prompts and their answers differ
# for ordinary reasons; what must hold is that A's restored answer is A's cold answer. Corrupt
@@ -23,7 +25,6 @@ set -e
P=${P:-8100}
H=${H:-127.0.0.1}
TO_HOST=${TO_HOST:-10}
TO_DISK=${TO_DISK:-180}
FILL=${FILL:-1200}
N=${N:-48}
work=$(mktemp -d "${TMPDIR:-/tmp}/tiercross.XXXXXX")
@@ -108,12 +109,11 @@ cmp_arm() { # cmp_arm <label> <sha> <ref sha> <reuse> <ref reu
fi
}
# ---- pushing a session out of host memory --------------------------------------------------------
# NOTHING LEAVES HOST MEMORY ON A CLOCK. Every host copy is written on to disk as soon as it lands
# and keeps its host slot until another entry needs one, so the way to put a session on disk is to
# A FULL HOST TIER DROPS ITS LEAST RECENTLY USED ENTRIES, so the way to push the sessions out is to
# give the arena something else to hold: a prompt that shares no prefix with anything here and is
# bigger than the room the arena has left. The server must be started with a host tier FILL
# sections of it overflow; --prefix-cache-host-mib 512 holds about 27K tokens on
# Qwen3.8-Flash-Next, and the default FILL is about 30K.
# sections of it overflow; --prefix-cache-mib 512 holds about 27K tokens on Qwen3.8-Flash-Next, and
# the default FILL is about 30K.
fill_arena() {
: > "$work/fill.txt"
i=0
@@ -127,19 +127,8 @@ fill_arena() {
curl -sS --fail -X POST "http://$H:$P/v1/completions" -H 'Content-Type: application/json' \
--data @"$work/fill.json" > /dev/null
}
# Until some blocks are on the disk tier, or TO_DISK seconds. The filler's copies are what take the
# slots, and they land after its request finishes.
wait_disk() {
t=0
while [ $t -lt "$TO_DISK" ]; do
curl -sS --fail "http://$H:$P/sessions" > "$work/w.json"
case "$(jq -r .blocks_sum_overlapping.disk < "$work/w.json")" in 0|null|"") ;; *) return 0 ;; esac
sleep 2; t=$((t + 2))
done
return 1
}
echo "tiercross: $H:$P, two sessions, ${TO_HOST}s for VRAM to go, $FILL filler sections"
CKS=$(curl -sS --fail "http://$H:$P/sessions" | jq -r .snapshots_moved.bytes_each)
CKS=$(curl -sS --fail "http://$H:$P/sessions" | jq -r .snapshot_store.bytes_each)
[ "$CKS" = "0" ] && echo " (no recurrent state in this model; the attention half is still tested)"
A0=$(ask A a0); B0=$(ask B b0)
@@ -165,6 +154,11 @@ done
AH=$(ask A ah); BH=$(ask B bh)
echo " device A $AH reuse $(hit ah)"
echo " B $BH reuse $(hit bh)"
# A DEVICE HIT THAT REUSED NOTHING TESTS NOTHING: every arm below would be a fresh prefill.
for f in ah bh; do
case "$(hit $f)" in 0|null|"") echo " FAIL the $f arm reused nothing -- no hit, so no restore below can be tested
(a snapshot store too small for both sessions? --checkpoint-slots)"; fail=$((fail + 1)) ;; esac
done
if [ "$AH" != "$A0" ] || [ "$BH" != "$B0" ]; then
echo " note: a device hit does not reproduce the cold answer. That is not necessarily wrong --"
echo " the hit reuses $(hit ah)/$(hit bh) tokens where the cold run reused nothing -- but every"
@@ -181,25 +175,19 @@ cmp_arm "B restored from RAM is still B" "$B1" "$BH" "$(hit b1)" "$(hit bh)"
echo " filling host memory with $FILL sections of something else..."
fill_arena
wait_disk || echo " note: nothing reached the disk tier within ${TO_DISK}s; the arm below may be a RAM restore"
sleep $((TO_HOST + 8))
A2=$(ask A a2); B2=$(ask B b2)
echo " from disk A $A2 reuse $(hit a2)"
echo " after a full host tier"
echo " A $A2 reuse $(hit a2)"
echo " B $B2 reuse $(hit b2)"
cmp_arm "A restored from disk is still A" "$A2" "$AH" "$(hit a2)" "$(hit ah)"
cmp_arm "B restored from disk is still B" "$B2" "$BH" "$(hit b2)" "$(hit bh)"
cmp_arm "A after the arena's drops is still A" "$A2" "$AH" "$(hit a2)" "$(hit ah)"
cmp_arm "B after the arena's drops is still B" "$B2" "$BH" "$(hit b2)" "$(hit bh)"
curl -sS --fail "http://$H:$P/sessions" > "$work/s.json"
echo " moved: blocks to_host=$(jq -r .moved.to_host < "$work/s.json") to_disk=$(jq -r .moved.to_disk < "$work/s.json") promoted=$(jq -r .moved.promoted < "$work/s.json")"
if [ "$CKS" != "0" ]; then
echo " state: to_disk=$(jq -r .snapshots_moved.to_disk < "$work/s.json") fetched=$(jq -r .snapshots_moved.fetched < "$work/s.json") dropped=$(jq -r .snapshots_moved.drops < "$work/s.json")"
# A RUN WITH NO CONTENTION TESTED THE EASY CASE. Two stores have to run out for the paths this
# script exists for to execute, and they are sized by different flags: --checkpoint-slots is
# the DEVICE pool the retention policy spends, and a share of --prefix-cache-host-mib (startup
# says how many snapshots) is the snapshot store the tiers spend. `drops` counts the second.
[ "$(jq -r .snapshots_moved.drops < "$work/s.json")" = "0" ] && \
echo " note: the snapshot store never overflowed -- lower --prefix-cache-host-mib to make the two sessions contend for it"
fi
echo " moved: blocks to_host=$(jq -r .moved.to_host < "$work/s.json") promoted=$(jq -r .moved.promoted < "$work/s.json") host_drops=$(jq -r .moved.host_drops < "$work/s.json")"
# A RUN WITH NO CONTENTION TESTED THE EASY CASE: the arena has to run out for its drop path to run.
[ "$(jq -r .moved.host_drops < "$work/s.json")" = "0" ] && \
echo " note: the host tier never overflowed -- lower --prefix-cache-mib or raise FILL"
if [ "$fail" -ne 0 ]; then
echo
+55 -82
View File
@@ -28,19 +28,19 @@
#
# scripts/tierident.sh # against a server already up on $P (default 8100)
#
# The server must be started with the tiers on, with a host tier small enough for the filler below
# to overflow it (see fill_arena), and with few enough checkpoint slots that the filler's snapshots
# push the session's out of the device pool -- a snapshot still in its device slot needs no
# promotion, and the path that brings one back from disk then never runs:
# --prefix-cache-host-mib 512 --prefix-cache-disk-mib 8192 --prefix-cache-dir <dir> \
# --checkpoint-slots 2
# The server must be started with the host tier on, small enough for the filler below to overflow
# it (see fill_arena):
# --prefix-cache-mib 512
# With TTL=<the server's --prefix-cache-ttl> set here as well, a last arm waits it out and checks
# that the session is gone from every tier and that asking again recomputes the same answer; start
# the server with a TTL long enough for the arms before it (a few minutes).
set -e
P=${P:-8100}
H=${H:-127.0.0.1}
TO_HOST=${TO_HOST:-10}
TO_DISK=${TO_DISK:-180}
FILL=${FILL:-1200}
TTL=${TTL:-0}
N=${N:-48}
work=$(mktemp -d "${TMPDIR:-/tmp}/tierident.XXXXXX")
trap 'rm -rf "$work"' EXIT INT TERM
@@ -64,7 +64,7 @@ while [ $i -lt 300 ]; do
printf 'Section %d. The cache stores conversation prefixes as content-hashed blocks, and the identity of a block includes every token before it. ' "$i" >> "$work/p.txt"
i=$((i + 1))
done
printf '\nUsing only the passage above, write three sentences about what a block identity includes and why it matters.\n\nAnswer: ' >> "$work/p.txt"
printf '\nUsing only the passage above, write three sentences about it.\n\nAnswer: ' >> "$work/p.txt"
# THE FILE IS THE PROMPT, READ VERBATIM, through jq's --rawfile. Escaping it by hand into a shell
# variable doubles the backslash jq adds before every quote, and flattening its newlines welds the
# question onto the passage ("...why it matters.Answer:" on one line), which this model answers
@@ -80,12 +80,11 @@ ask() { # ask <label> -> writes $work/<label>.txt, echoes
sha1sum < "$work/$1.txt" | cut -d' ' -f1
}
# ---- pushing a session out of host memory --------------------------------------------------------
# NOTHING LEAVES HOST MEMORY ON A CLOCK. Every host copy is written on to disk as soon as it lands
# and keeps its host slot until another entry needs one, so the way to put a session on disk is to
# give the arena something else to hold: a prompt that shares no prefix with anything here and is
# bigger than the room the arena has left. The server must be started with a host tier FILL
# sections of it overflow; --prefix-cache-host-mib 512 holds about 27K tokens on
# Qwen3.8-Flash-Next, and the default FILL is about 30K.
# A FULL HOST TIER DROPS ITS LEAST RECENTLY USED ENTRIES, so the way to push a session out is to give
# the arena something else to hold: a prompt that shares no prefix with anything here and is bigger
# than the room the arena has left. The server must be started with a host tier FILL sections of it
# overflow; --prefix-cache-mib 512 holds about 27K tokens on Qwen3.8-Flash-Next, and the default
# FILL is about 30K.
fill_arena() {
: > "$work/fill.txt"
i=0
@@ -99,17 +98,6 @@ fill_arena() {
curl -sS --fail -X POST "http://$H:$P/v1/completions" -H 'Content-Type: application/json' \
--data @"$work/fill.json" > /dev/null
}
# Until some blocks are on the disk tier, or TO_DISK seconds. The filler's copies are what take the
# slots, and they land after its request finishes.
wait_disk() {
t=0
while [ $t -lt "$TO_DISK" ]; do
curl -sS --fail "http://$H:$P/sessions" > "$work/w.json"
case "$(jq -r .blocks_sum_overlapping.disk < "$work/w.json")" in 0|null|"") ;; *) return 0 ;; esac
sleep 2; t=$((t + 2))
done
return 1
}
snap() { curl -sS --fail "http://$H:$P/sessions" > "$work/s.json"; }
q() { jq -r "$1" < "$work/s.json"; }
# PROMPT TOKENS A LOOKUP COVERED WITH RECURRENT STATE. Moving a snapshot and moving it back proves
@@ -118,11 +106,11 @@ q() { jq -r "$1" < "$work/s.json"; }
# scores perfectly on the first and zero on this.
lin() { jq -r ".linear.cached_tokens" < "$work/s.json"; }
where() { # where -> "vram=N ram=N disk=N [+ snapshots]" for the whole server
where() { # where -> "vram=N ram=N [+ snapshots]" for the whole server
snap
w="vram=$(q .blocks_sum_overlapping.device) ram=$(q .blocks_sum_overlapping.host) disk=$(q .blocks_sum_overlapping.disk)"
if [ "$(q .snapshots_moved.bytes_each)" != "0" ]; then
w="$w state: ram=$(q .snapshots.host) disk=$(q .snapshots.disk)"
w="vram=$(q .blocks_sum_overlapping.device) ram=$(q .blocks_sum_overlapping.host)"
if [ "$(q .snapshot_store.bytes_each)" != "0" ]; then
w="$w snapshots=$(q .snapshots_sum_overlapping)"
fi
echo "$w"
}
@@ -141,11 +129,11 @@ echo "tierident: $H:$P, ${TO_HOST}s for VRAM to go, $FILL filler sections to pus
# is named as one rather than skipped.
snap
HYBRID=0
[ "$(q .snapshots_moved.bytes_each)" != "0" ] && HYBRID=1
[ "$(q .snapshot_store.bytes_each)" != "0" ] && HYBRID=1
if [ "$HYBRID" = 1 ]; then
echo " hybrid: snapshots are $(q .snapshots_moved.bytes_each) bytes, $(q .snapshots_moved.host_slots) ram slot(s), $(q .snapshots_moved.disk_slots) disk slot(s)"
[ "$(q .snapshots_moved.host_slots)" = "0" ] && \
note "the snapshot store has no room; an idle session's linear state cannot leave VRAM"
echo " hybrid: snapshots are $(q .snapshot_store.bytes_each) bytes, $(q .snapshot_store.slots) slot(s)"
[ "$(q .snapshot_store.slots)" = "0" ] && \
note "the snapshot store has no room; a session's linear state has nowhere to be kept"
else
echo " this model has no recurrent state; the linear-state arms are not applicable"
fi
@@ -185,35 +173,23 @@ snap
# A MISSING FIELD IS THE SAME FAILURE AS A ZERO: if the /sessions layout changes, this guard reads
# `null`, and treating that as a pass would pass vacuously.
case "$(q .blocks_sum_overlapping.host)" in 0|null|"") false ;; *) true ;; esac || note "the session never left VRAM -- nothing below would test anything
(--prefix-cache-host-mib set? is the maintenance pass running?)"
(--prefix-cache-mib set? is the maintenance pass running?)"
if [ "$HYBRID" = 1 ]; then
snap
# A SNAPSHOT IS IN HOST MEMORY FROM THE MOMENT IT IS SAVED (the checkpoint store), so the
# session's state must be there or on disk -- nowhere else is a place it can be.
case "$(q .snapshots.host)/$(q .snapshots.disk)" in 0/0|null/*|*/null) false ;; *) true ;; esac || \
note "the session holds no linear-state snapshot, so the restore below tests the blocks only
(dropped: $(q .snapshots_moved.drops))"
# session's state must be there -- nowhere else is a place it can be.
case "$(q .snapshots_sum_overlapping)" in 0|null|"") false ;; *) true ;; esac || \
note "the session holds no linear-state snapshot, so the restore below tests the blocks only"
fi
snap
FET0=$([ "$HYBRID" = 1 ] && q .snapshots_moved.fetched || echo 0)
LIN0=$([ "$HYBRID" = 1 ] && lin || echo 0)
RAM0=$([ "$HYBRID" = 1 ] && q .snapshots.host || echo 0)
FROMHOST=$(ask fromhost)
echo " restored from RAM $FROMHOST [$(where)]"
check "a session restored from RAM reproduces the cold answer" "$FROMHOST" "$COLD"
if [ "$HYBRID" = 1 ]; then
snap
# A SNAPSHOT IN THE STORE NEEDS NO READ: it is restored straight out of its slot, and only
# the store's own pressure sends it to disk. Whether it was SERVED is the check below either
# way; this one only says which path served it.
if [ "$(q .snapshots_moved.fetched)" -gt "$FET0" ]; then
echo " ok its linear state was read back off disk ($(( $(q .snapshots_moved.fetched) - FET0 )) snapshot(s))"
elif [ "$RAM0" -gt 0 ]; then
echo " -- its linear state stayed in the snapshot store ($RAM0 there), so nothing was read"
else
note "the blocks came back and the linear state did not -- the answer is right and the
session will replay every recurrent layer from an older checkpoint to produce it"
fi
# A SNAPSHOT NEEDS NO READ: it is restored straight out of its slot in the store. Whether it was
# SERVED is the check.
if [ "$(lin)" -gt "$LIN0" ]; then
echo " ok and the restored state was SERVED ($(( $(lin) - LIN0 )) prompt tokens covered by it)"
else
@@ -222,50 +198,47 @@ if [ "$HYBRID" = 1 ]; then
fi
fi
# ---- disk --------------------------------------------------------------------------------------
# ---- a full host tier ---------------------------------------------------------------------------
# THE FILLER OVERFLOWS THE ARENA, and the arena drops its least recently used entries -- this
# session's -- to make room. What comes back then is a recompute, or a restore of what survived; the
# answer is the cold one either way, and an entry the arena dropped that the cache went on serving
# would show here as another conversation's context.
echo " filling host memory with $FILL sections of something else..."
snap
DROP0=$(q .moved.host_drops)
fill_arena
wait_disk || true
echo " and waiting $((TO_HOST + 8))s for VRAM to go..."
sleep $((TO_HOST + 8))
W=$(where)
echo " after the filler [$W]"
snap
case "$(q .blocks_sum_overlapping.disk)" in 0|null|"") false ;; *) true ;; esac || note "the session never reached disk -- the arm below tests nothing
(--prefix-cache-disk-mib and --prefix-cache-dir set? a host tier FILL=$FILL sections overflow?)"
if [ "$HYBRID" = 1 ]; then
[ "$(q .moved.host_drops)" -gt "$DROP0" ] || note "the host tier dropped nothing -- the arm below tests nothing
(a host tier FILL=$FILL sections overflow?)"
AFTER=$(ask afterfill)
echo " after a full host tier $AFTER [$(where)]"
check "a session the full host tier dropped from reproduces the cold answer" "$AFTER" "$COLD"
# ---- expiry ------------------------------------------------------------------------------------
if [ "$TTL" -gt 0 ]; then
echo " waiting $((TTL + 5))s for --prefix-cache-ttl to take everything..."
sleep $((TTL + 5))
snap
[ "$(q .snapshots_moved.to_disk)" = "0" ] && \
note "no linear-state snapshot reached disk
(disk snapshot slots: $(q .snapshots_moved.disk_slots))"
fi
snap
FET1=$([ "$HYBRID" = 1 ] && q .snapshots_moved.fetched || echo 0)
LIN1=$([ "$HYBRID" = 1 ] && lin || echo 0)
FROMDISK=$(ask fromdisk)
echo " restored from disk $FROMDISK [$(where)]"
check "a session restored from disk reproduces the cold answer" "$FROMDISK" "$COLD"
if [ "$HYBRID" = 1 ]; then
snap
if [ "$(q .snapshots_moved.fetched)" -gt "$FET1" ]; then
echo " ok its linear state came back from disk too"
else
note "no snapshot was read off disk -- the filler's snapshots did not push the session's
out of the snapshot store (--checkpoint-slots 2?), so the disk path never ran"
fi
if [ "$(lin)" -gt "$LIN1" ]; then
echo " ok and the state restored from disk was SERVED ($(( $(lin) - LIN1 )) prompt tokens)"
else
note "a snapshot came back from disk and no lookup used it"
fi
echo " snapshots: to_disk=$(q .snapshots_moved.to_disk) fetched=$(q .snapshots_moved.fetched) dropped=$(q .snapshots_moved.drops)"
echo " after the ttl [$(where)] expired: $(q .expired.entries) entries, $(q .expired.snapshots) snapshots"
case "$(q '.sessions | length')/$(q .blocks_sum_overlapping.host)/$(q .occupancy.host_bytes)" in
0/0/0) echo " ok nothing is left in any tier" ;;
*) note "the ttl left something behind: $(q '.sessions | length') sessions, host bytes $(q .occupancy.host_bytes)" ;;
esac
[ "$(q .expired.entries)" -gt 0 ] || note "no entry was counted as expired"
EXPIRED=$(ask expired)
echo " after expiry $EXPIRED [$(where)]"
check "a session asked again after it expired reproduces the cold answer" "$EXPIRED" "$COLD"
fi
# ---- and the text itself, so a failure says WHERE ----------------------------------------------
if [ "$fail" -ne 0 ]; then
echo
echo "The first differing line, cold vs the failing arm:"
for arm in fromhost fromdisk; do
for arm in fromhost afterfill expired; do
[ -f "$work/$arm.txt" ] || continue
if ! cmp -s "$work/cold.txt" "$work/$arm.txt"; then
echo "--- $arm"
@@ -280,6 +253,6 @@ if [ "$fail" -ne 0 ]; then
fi
echo
[ "$fail" -eq 0 ] && echo "tierident: PASS -- a session survives VRAM -> RAM -> disk byte for byte, state included"
[ "$fail" -eq 0 ] && echo "tierident: PASS -- a session survives VRAM -> RAM byte for byte, state included"
[ "$fail" -ne 0 ] && { echo "tierident: $fail FAILURE(S)"; exit 1; }
exit 0