#!/bin/sh # tierident.sh -- checks that a session that left VRAM comes back byte for byte, attention blocks # and recurrent state both. # # Acceptance test for the idle session tiers (core/mem/kvtier.h). Corrupt KV produces fluent, # deterministic, plausible text that is simply not what the model would have produced, so only a # byte comparison against a known-good arm detects it. # # The control is essential: arm 2 asks the same prompt while the session is still in VRAM. If it # does not reproduce arm 1 exactly, the server is not reproducible across requests and every later # comparison is meaningless, so the script stops. # # On a hybrid model a session is attention blocks plus a recurrent-state snapshot, stored and lost # separately. A lost snapshot does not change the text: the engine replays the linear layers from # an older checkpoint or token zero and gives the same answer, slower. Byte identity therefore # proves only the blocks, and every snapshot assertion is a counter. Blocks moving without the # snapshot is a failure here: for a restored 200K session it is the difference between a second # and a minute of linear replay. # # scripts/tierident.sh # against a server already up on $P (default 8100) # # 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= 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} FILL=${FILL:-1200} TTL=${TTL:-0} 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; } # The prompt must span many blocks and exceed a checkpoint interval (2048 tokens by default): # shorter, it produces no snapshot and every snapshot assertion passes vacuously. # # It must also ask a question. An instruction-tuned model may answer a wall of repeated sentences # with a single EOS, and empty answers would pass the control, so the answer length is checked # below. : > "$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 it.\n\nAnswer: ' >> "$work/p.txt" # The file is sent verbatim through jq's --rawfile. Escaping it into a shell variable doubles the # backslash jq adds before every quote, and flattening newlines joins the question to the passage # ("...why it matters.Answer:"), which gets an immediate EOS. ask() { # ask