#!/bin/sh # tierident.sh -- does a session that left VRAM come back BYTE FOR BYTE, both halves of it? # # This is the acceptance test for the idle session tiers (core/mem/kvtier.h). It is a byte # comparison because CORRUPT KV DOES NOT READ AS BABBLE -- it reads as fluent, deterministic, # coherent, plausible text that simply is not the text the model would have produced, and nothing # that looks at the engine from outside notices it. Only a byte comparison against a known-good # arm sees it. # # THE CONTROL IS THE WHOLE TEST. Arm 2 asks the same prompt again while the session is still in # VRAM. If that does not reproduce arm 1 exactly, then this model at this temperature is not # reproducible across requests at all and every later comparison is meaningless -- a differing sha # would prove nothing, because a cache hit COULD have been legitimately tie-divergent. Run the # control or do not run the test. # # ============================== AND ON A HYBRID MODEL, HALF THE TEST IS INVISIBLE =============== # # A session on a hybrid model is attention blocks AND a recurrent-state snapshot. The two are # stored separately and can be lost separately -- and losing the snapshot IS NOT VISIBLE IN THE # TEXT. The engine simply replays the linear layers from an older checkpoint, or from token zero, # and produces exactly the same answer, slower. So byte identity proves the blocks came back and # says nothing whatever about the state. # # That is why every snapshot assertion below is a counter and not a sha. A run where the blocks # moved and the snapshots did not is a PASS by text and a FAILURE here, and it is the failure that # matters: it is the difference between a restored 200K session costing a second and costing a # minute of linear replay. # # 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 \ # --checkpoint-slots 2 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}/tierident.XXXXXX") trap 'rm -rf "$work"' EXIT INT TERM command -v jq >/dev/null || { echo "tierident: jq is required" >&2; exit 2; } # A PROMPT LONG ENOUGH TO BE WORTH TIERING, AND LONGER THAN A CHECKPOINT INTERVAL. The unit of the # attention half is the block, so a prompt of a few tokens occupies one and exercises nothing. The # unit of the linear half is the checkpoint interval -- 2048 tokens by default -- and a prompt # shorter than that produces NO snapshot at all, so every snapshot assertion below would be # vacuously satisfied by a server where snapshot tiering is entirely broken. # # AND IT HAS TO ASK FOR SOMETHING. A wall of repeated sentences with no question at the end is a # passage an instruction-tuned model can answer with a single EOS, and every arm would then compare # an empty string to an empty string and report the control green. That is the same failure this # whole script is built around -- a comparison that passes because neither side has any content -- # so the answer length is checked below as well. : > "$work/p.txt" i=0 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" # 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 # with an immediate EOS -- the empty-completion failure described above. ask() { # ask