This repository has been archived on 2026-11-24. You can view files and clone it. You cannot open issues or pull requests or push a commit.
Files
radiance-sycl/scripts/tiercross.sh
T
Deadcode b93b531f63 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
2026-10-13 19:35:16 +02:00

206 lines
11 KiB
Bash
Executable File

#!/bin/sh
# tiercross.sh -- two conversations through the tiers at once. Does either get the other's state?
#
# WHY THIS IS NOT tierident.sh WITH A SECOND PROMPT. That script asks ONE prompt four times and
# compares the four answers, which proves a session survives the round trip. It cannot, by
# construction, see the failure this one is for: with a single conversation in the server there is
# no other conversation's bytes for it to be served. The cross-contamination failures a tiered
# 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.
#
# A HOST TIER THE FILLER OVERFLOWS, so the arena's drops run as well as its restores:
#
# --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
# state does not produce babble, it produces B's train of thought under A's question.
set -e
P=${P:-8100}
H=${H:-127.0.0.1}
TO_HOST=${TO_HOST:-10}
FILL=${FILL:-1200}
N=${N:-48}
work=$(mktemp -d "${TMPDIR:-/tmp}/tiercross.XXXXXX")
trap 'rm -rf "$work"' EXIT INT TERM
command -v jq >/dev/null || { echo "tiercross: jq is required" >&2; exit 2; }
# TWO PROMPTS THAT SHARE NO PREFIX. A shared opening would put both sessions on the same chain for
# its length, and the blocks they then share are legitimately one another's -- which is the whole
# point of a prefix cache and would make a difference here unreadable. They diverge at token one.
#
# EACH HAS TO PRODUCE AN ANSWER. A wall of repeated sentences is a passage an instruction-tuned
# model can reasonably answer with a single EOS, and every arm of that session would then compare
# an empty string to an empty string. Both lengths are checked below, because a vacuous green here
# is worse than a red.
mk() { # mk <file> <subject> <opening> <question>
: > "$1"
i=0
while [ $i -lt 300 ]; do
printf '%s %d. %s ' "$2" "$i" "$3" >> "$1"
i=$((i + 1))
done
printf '\n%s\n\nAnswer: ' "$4" >> "$1"
}
mk "$work/a.txt" "Chapter" "The paged pool is layer-major, so one logical block is many small fragments rather than one extent." \
"Using only the passage above, write three sentences about it."
mk "$work/b.txt" "Entry" "The linear layer keeps one state per sequence and updates it token by token." \
"Using only the passage above, write three sentences about it."
# THE FILES ARE THE PROMPTS, READ VERBATIM, through jq's --rawfile. Flattening them into shell
# variables deletes the line breaks the prompts' SHAPE depends on, and a passage whose question
# ends up welded to the last sentence is one this model answers with an immediate EOS (the same
# reasoning is in tierident.sh).
ask() { # ask <who> <label> -> sha of the answer
f="$work/$(printf '%s' "$1" | tr 'AB' 'ab').txt"
jq -n --rawfile p "$f" --argjson n "$N" \
'{model:"m", prompt:$p, max_tokens:$n, temperature:0, seed:1234, stream:false}' \
> "$work/req.json"
curl -sS --fail -X POST "http://$H:$P/v1/completions" \
-H 'Content-Type: application/json' --data @"$work/req.json" > "$work/$2.json"
jq -r '.choices[0].text' < "$work/$2.json" > "$work/$2.txt"
sha1sum < "$work/$2.txt" | cut -d' ' -f1
}
# THE HIT LENGTH, which is what decides how the prefill is chunked and therefore the shape every
# GEMM in it runs at. Two restores that recovered different amounts of prefix are not the same
# computation, and comparing their output hashes would be comparing two different runs -- so this
# is printed beside every arm and checked before a mismatch is called corruption.
hit() { jq -r '.usage.prompt_tokens_details.cached_tokens' < "$work/$1.json"; }
fail=0
# WHAT A DIFFERING HASH MEANS, AND THE ONE THING THAT HAS TO BE RULED OUT FIRST.
#
# A hybrid session's reuse is clamped by the scheduler to the last LINEAR CHECKPOINT it can reach,
# not to the attention hit (core/sched/scheduler.cpp, admit_one: RadBatch carries one query length
# for every KV group, so the linear layers cannot be replayed over a longer range than the
# attention ones). So reuse is always a multiple of the checkpoint interval, and which multiple
# depends on which snapshots survived -- 0 on a cold run, 4096 or 6144 on a restored one.
#
# Reuse does not change the answer on Qwen3.8-Flash-Next: with no tiers running at all, the same
# prompt at reuse 0, 4096 and 6144 gives the same bytes. So a differing hash is a real difference
# and not an artefact of a shorter hit -- but it is the first thing to re-check if this fails on
# another model, because a near-tie that flips with the chunk boundary would look exactly like
# corruption and is not.
#
# THE COMPARISON IS AGAINST THE DEVICE-HIT ARM, not the cold one. A cold run reuses nothing by
# definition, so comparing a restore to it would always be comparing two different hit lengths;
# the device hit is the same query the restored arms run, served out of VRAM.
cmp_arm() { # cmp_arm <label> <sha> <ref sha> <reuse> <ref reuse>
if [ "$2" = "$3" ]; then
echo " ok $1 (reuse $4)"
return
fi
fail=$((fail + 1))
if [ "$4" = "$5" ]; then
echo " FAIL $1: SAME reuse ($4), different answer. This is corrupt state."
else
echo " FAIL $1: different answer, and it reused $4 where the reference reused $5."
echo " Almost certainly corruption -- reuse does not change the answer on the model"
echo " this was written against -- but confirm that on THIS model with the tiers"
echo " off before reporting it as one."
fi
}
# ---- pushing a session out of host memory --------------------------------------------------------
# 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-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
while [ $i -lt "$FILL" ]; do
printf 'Ledger line %d: warehouse north, shelf eleven, a part number and a count that nobody will ask about. ' "$i" >> "$work/fill.txt"
i=$((i + 1))
done
printf '\nName the warehouse.\n\nAnswer: ' >> "$work/fill.txt"
jq -n --rawfile p "$work/fill.txt" '{model:"m", prompt:$p, max_tokens:4, temperature:0, stream:false}' \
> "$work/fill.json"
curl -sS --fail -X POST "http://$H:$P/v1/completions" -H 'Content-Type: application/json' \
--data @"$work/fill.json" > /dev/null
}
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 .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)
echo " first A $A0 reuse $(hit a0)"
echo " B $B0 reuse $(hit b0)"
# AND THEY MUST DIFFER. Two prompts that produce the same answer would make every comparison
# below pass whatever the tiers did with them.
if [ "$A0" = "$B0" ]; then
echo "tiercross: both prompts produced the same answer, so no comparison here can tell the" >&2
echo " two sessions apart. Change the prompts." >&2
exit 1
fi
for f in a0 b0; do
CN=$(wc -c < "$work/$f.txt")
[ "$CN" -lt 32 ] && { echo "tiercross: $f answered $CN bytes; every sha for it would match for that" >&2
echo " reason alone. Give that prompt something to answer." >&2; exit 1; }
done
# ---- the control: both sessions again, straight out of VRAM -------------------------------------
# THE SAME QUERY THE RESTORED ARMS WILL RUN. Without it a differing hash below proves nothing: this
# engine could be irreproducible across requests for reasons that have nothing to do with tiering,
# and the two sessions could be contaminating each other while both are still resident.
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"
echo " comparison below is against the DEVICE HIT from here on, which is the like-for-like one."
fi
echo " waiting $((TO_HOST + 8))s..."
sleep $((TO_HOST + 8))
A1=$(ask A a1); B1=$(ask B b1)
echo " from RAM A $A1 reuse $(hit a1)"
echo " B $B1 reuse $(hit b1)"
cmp_arm "A restored from RAM is still A" "$A1" "$AH" "$(hit a1)" "$(hit ah)"
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
sleep $((TO_HOST + 8))
A2=$(ask A a2); B2=$(ask B b2)
echo " after a full host tier"
echo " A $A2 reuse $(hit a2)"
echo " B $B2 reuse $(hit b2)"
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") 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
echo "A session answering with the OTHER session's train of thought is what corruption looks"
echo "like. A reuse mismatch above is a different finding and the diffs below do not speak to it."
for pair in "ah a1" "ah a2" "bh b1" "bh b2"; do
set -- $pair
cmp -s "$work/$1.txt" "$work/$2.txt" || { echo "--- $1 vs $2"; diff "$work/$1.txt" "$work/$2.txt" | head -4; }
done
fi
echo
[ "$fail" -eq 0 ] && echo "tiercross: PASS -- neither session was served the other's context or state"
[ "$fail" -ne 0 ] && { echo "tiercross: $fail FAILURE(S)"; exit 1; }
exit 0