Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
212 lines
14 KiB
Bash
212 lines
14 KiB
Bash
#!/usr/bin/env bash
|
|
# Start the whole production stack on the GPU server and run the e2e client against it, then stop it and check for leaks.
|
|
#
|
|
# leleka-inference (Original serve backend, sealed KAR memfd inherited from the holder)
|
|
# leleka-daemon + leleka-cli load-mtp (explicit load; strata-next only attaches)
|
|
# strata-next serve (runtime block) <- scripts/e2e/e2e_client.py
|
|
#
|
|
# MUST run inside a holder job (it needs LELEKA_STRA169_KAR_FD, a sealed memfd). It refuses to start otherwise: the model process
|
|
# is never started outside the holder (MODEL.lock rules). Never builds anything.
|
|
#
|
|
# Environment (all optional except where noted):
|
|
# E2E_BIN directory with leleka-inference leleka-daemon leleka-cli strata-next (default ~/work/leleka-e2e/bin-sm120)
|
|
# E2E_OUT output directory for logs and results.json (default ~/work/leleka-e2e/runs/<utc>)
|
|
# E2E_CLIENT scripts/e2e/e2e_client.py (default next to this script)
|
|
# E2E_CONTEXT directory whose .rs/.md files make the long prompt (default ~/work/leleka-e2e/context)
|
|
# E2E_SCENARIOS client scenarios, comma separated or all (default all)
|
|
# E2E_CLIENT_ARGS extra client arguments (e.g. "--soak-n 40 --burst 20")
|
|
# E2E_ENGINE_ARGS extra leleka-inference arguments (e.g. "--original-prefill-capacity 4096")
|
|
set -uo pipefail
|
|
HERE=$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)
|
|
W=$HOME/work/leleka-e2e
|
|
G=$HOME/work/gpu-runs
|
|
A=/home/para/work/leleka/models/leleka-gates/assets
|
|
BIN=${E2E_BIN:-$W/bin-sm120}
|
|
OUT=${E2E_OUT:-$W/runs/$(date -u +%Y%m%dT%H%M%SZ)}
|
|
CLIENT=${E2E_CLIENT:-$HERE/e2e_client.py}
|
|
CONTEXT=${E2E_CONTEXT:-$W/context}
|
|
STATE=$W/state
|
|
mkdir -p "$OUT"
|
|
log() { echo "[run-e2e $(date -u +%T)] $*"; }
|
|
|
|
# ---- guards -------------------------------------------------------------------------------------------------------
|
|
FD=${LELEKA_STRA169_KAR_FD:-}
|
|
if [ -z "$FD" ] || ! readlink "/proc/self/fd/$FD" 2>/dev/null | grep -q '^/memfd:'; then
|
|
echo "refusing to start: LELEKA_STRA169_KAR_FD is not a sealed memfd inherited from the holder; run this as a holder job" >&2
|
|
exit 3
|
|
fi
|
|
[ -d "$G/MODEL.lock" ] || { echo "refusing to start: $G/MODEL.lock is not held" >&2; exit 3; }
|
|
for b in leleka-inference leleka-daemon leleka-cli strata-next; do [ -x "$BIN/$b" ] || { echo "missing $BIN/$b" >&2; exit 3; }; done
|
|
if pgrep -u "$USER" -x 'leleka-inference|strata-next|leleka-daemon' >/dev/null; then
|
|
echo "refusing to start: a stack process of this user is already running" >&2; pgrep -a -u "$USER" -x 'leleka-inference|strata-next|leleka-daemon' >&2; exit 3
|
|
fi
|
|
if [ -n "$(nvidia-smi --query-compute-apps=pid --format=csv,noheader 2>/dev/null)" ]; then
|
|
echo "refusing to start: something else already uses the GPU" >&2; nvidia-smi --query-compute-apps=pid,used_memory --format=csv,noheader >&2; exit 3
|
|
fi
|
|
for p in 18766 18080 8081; do
|
|
if ss -ltn "sport = :$p" 2>/dev/null | grep -q LISTEN; then echo "port $p is in use" >&2; exit 3; fi
|
|
done
|
|
|
|
# ---- environment --------------------------------------------------------------------------------------------------
|
|
export LD_LIBRARY_PATH=$HOME/cuda-toolkits/cublas-12.9.1.4/lib:$HOME/cuda-toolkits/13.2.2/lib64:${LD_LIBRARY_PATH:-}
|
|
install -d -m 0700 "$STATE" "$G/mtp-staging-own"
|
|
chmod 700 "$G/mtp-staging-own"
|
|
umask 077
|
|
# two independent secrets and an API key; written to mode 0600 files and the environment, never printed
|
|
mkrand() { head -c 36 /dev/urandom | base64 | tr -d '\n'; }
|
|
export LELEKA_RUNTIME_TOKEN=$(mkrand) LELEKA_GATEWAY_TOKEN=$(mkrand)
|
|
KEYFILE=$STATE/api-key
|
|
rm -f "$KEYFILE"
|
|
"$BIN/strata-next" api-key init --file "$KEYFILE" >/dev/null 2>"$OUT/api-key-init.err" || { log "api-key init failed"; cat "$OUT/api-key-init.err"; exit 4; }
|
|
chmod 600 "$KEYFILE"
|
|
|
|
# engine tuning exactly as the 98x bring-up jobs (VRAM expert tier, placeholder profile); serve profile prints one line per request
|
|
export LELEKA_ORIGINAL_SERVE_EXPERT_SLOTS=${LELEKA_ORIGINAL_SERVE_EXPERT_SLOTS:-2048}
|
|
export LELEKA_ORIGINAL_SERVE_EXPERT_PER_LAYER=${LELEKA_ORIGINAL_SERVE_EXPERT_PER_LAYER:-yes}
|
|
export LELEKA_ORIGINAL_SERVE_PCIE_FRAC=${LELEKA_ORIGINAL_SERVE_PCIE_FRAC:-0.45}
|
|
# The ranked upstream profile (data/expert-profile.bin, the file crates/deploy pins as EXPERT_PROFILE_SHA256 and vanilla Strata runs) is the default.
|
|
# The old default, $G/baseline/profile.bin, is a PLACEHOLDER in expert-id order (47 % overlap with the ranked set at 11,280 slots): every e2e run
|
|
# that used it started from an unranked VRAM set, which showed up as a burst of CPU/PCIe experts in the first 20 windows of each request and an
|
|
# 81 % instead of 97 % VRAM share (STRA-245 decode gap). The digest of the profile actually used is recorded in $OUT/expert-profile.sha256, and a digest
|
|
# other than the pinned one is refused unless E2E_ALLOW_PROFILE_OVERRIDE=1 (then the record says so, and a paired comparison must not mix digests).
|
|
PINNED_PROFILE_SHA256=8f59b4aa8873209dff11c11e37bcda9529a1335b724a1afeea37bf6388975baf
|
|
export LELEKA_ORIGINAL_SERVE_EXPERT_PROFILE=${LELEKA_ORIGINAL_SERVE_EXPERT_PROFILE:-$A/data/expert-profile.bin}
|
|
PROFILE_SHA256=$(sha256sum "$LELEKA_ORIGINAL_SERVE_EXPERT_PROFILE" 2>/dev/null | cut -d' ' -f1)
|
|
if [ "$PROFILE_SHA256" = "$PINNED_PROFILE_SHA256" ]; then
|
|
PROFILE_NOTE=pinned
|
|
elif [ "${E2E_ALLOW_PROFILE_OVERRIDE:-}" = 1 ]; then
|
|
PROFILE_NOTE=override
|
|
log "WARNING: expert profile $LELEKA_ORIGINAL_SERVE_EXPERT_PROFILE has digest ${PROFILE_SHA256:-unreadable}, not the pinned $PINNED_PROFILE_SHA256 (E2E_ALLOW_PROFILE_OVERRIDE=1)"
|
|
else
|
|
echo "refusing to start: expert profile $LELEKA_ORIGINAL_SERVE_EXPERT_PROFILE has digest ${PROFILE_SHA256:-unreadable}, not the pinned $PINNED_PROFILE_SHA256; set E2E_ALLOW_PROFILE_OVERRIDE=1 to run on purpose (never in a paired comparison with the upstream profile)" >&2
|
|
exit 3
|
|
fi
|
|
echo "profile=$LELEKA_ORIGINAL_SERVE_EXPERT_PROFILE sha256=$PROFILE_SHA256 pinned=$PINNED_PROFILE_SHA256 state=$PROFILE_NOTE" >"$OUT/expert-profile.sha256"
|
|
export LELEKA_SERVE_PROFILE=1 LELEKA_GRAPH_EXEC_REUSE=off RUST_BACKTRACE=1
|
|
# synthetic prompts only: log the generated text when a streamed tool turn fails (operator debugging switch)
|
|
export STRATA_DEBUG_FAILED_OUTPUT=1
|
|
|
|
cat >"$STATE/daemon.json" <<EOF
|
|
{"schema_version":1,"listen":"127.0.0.1:18080","token_env":"LELEKA_GATEWAY_TOKEN",
|
|
"runtimes":[{"id":"qwen-iq3","address":"127.0.0.1:18766","token_env":"LELEKA_RUNTIME_TOKEN",
|
|
"artifact_digest":"sha256:80d5e3333801cedbca81a5c19c24ed6bb48fd56977acd190318f66b23a1766a3"}]}
|
|
EOF
|
|
TOK=$STATE/tokenizer-assets
|
|
cat >"$STATE/strata.json" <<EOF
|
|
{"bind":"127.0.0.1:8081","api_key_file":"$KEYFILE","model":"qwen-iq3","shutdown_grace_s":10,
|
|
"runtime":{"address":"127.0.0.1:18766","token_env":"LELEKA_RUNTIME_TOKEN","tokenizer_dir":"$TOK/tokenizer",
|
|
"model":{"family":"qwen4exp","architecture":"qwen4exp","weight_format":"gguf:iq3_s",
|
|
"artifact_digest":"sha256:80d5e3333801cedbca81a5c19c24ed6bb48fd56977acd190318f66b23a1766a3"},
|
|
"mode":{"type":"mtp","profile_id":"qwen4exp-kar-ple-mtp-v1"},"max_context":262144,"max_output_tokens":32768}}
|
|
EOF
|
|
|
|
# The Original drafts over the 106k-row draft vocabulary of the MTP pack (draft_vocab.bin); without --mtp-rt-dir the engine drafts over the
|
|
# full 248k-row head (found by the ledger agent; jobs 943b / 945 ran without it). E2E_NO_RT_DIR=1 reproduces the old behaviour.
|
|
RT_ARG="--mtp-rt-dir $A/data/mtp-rt"; [ "${E2E_NO_RT_DIR:-}" = 1 ] && RT_ARG=""
|
|
PID_INF= PID_DAE= PID_STR=
|
|
alive() { [ -n "$1" ] && kill -0 "$1" 2>/dev/null; }
|
|
stop_one() { # name pid grace
|
|
local name=$1 pid=$2 grace=$3
|
|
alive "$pid" || { log "$name already gone"; return; }
|
|
kill -INT "$pid" 2>/dev/null
|
|
for _ in $(seq 1 "$grace"); do alive "$pid" || break; sleep 1; done
|
|
if alive "$pid"; then log "LEAK: $name ($pid) ignored SIGINT for ${grace}s, killing"; kill -KILL "$pid" 2>/dev/null; echo "$name ignored SIGINT" >>"$OUT/defects.txt"; fi
|
|
}
|
|
cleanup() {
|
|
log "shutting down"
|
|
stop_one strata-next "$PID_STR" 30
|
|
stop_one leleka-daemon "$PID_DAE" 30
|
|
stop_one leleka-inference "$PID_INF" 120
|
|
sleep 2
|
|
log "left over processes of this stack (expect none):"
|
|
pgrep -a -u "$USER" -x 'leleka-inference|strata-next|leleka-daemon' || echo " none"
|
|
log "GPU compute apps (expect none):"
|
|
nvidia-smi --query-compute-apps=pid,used_memory --format=csv,noheader || true
|
|
nvidia-smi --query-gpu=memory.used --format=csv,noheader || true
|
|
log "free -m: $(free -m | awk '/Mem:/{print "avail="$7" shared="$5}')"
|
|
}
|
|
trap cleanup EXIT
|
|
|
|
# ---- tokenizer assets (offline, CPU) ------------------------------------------------------------------------------
|
|
if [ ! -d "$TOK/tokenizer" ]; then
|
|
log "extracting tokenizer assets"
|
|
"$BIN/strata-next" model extract-tokenizer "$A/model/Qwen3.8-Flash-Next-GSQ-RCO-IQ3_S-00001-of-00002.gguf" --output "$TOK" >"$OUT/extract-tokenizer.log" 2>&1 || { log "extract-tokenizer failed"; tail -5 "$OUT/extract-tokenizer.log"; exit 4; }
|
|
fi
|
|
ls "$TOK" "$TOK/tokenizer" 2>&1 | head -5
|
|
|
|
# ---- engine ------------------------------------------------------------------------------------------------------
|
|
log "starting leleka-inference (sm: $(sha256sum "$BIN/leleka-inference" | cut -c1-16))"
|
|
# The sealed KAR descriptor is inherited by the engine only: close it for the other processes started below.
|
|
# Optional on-demand kernel tracing of the live engine (tools/cupti-trace of claude/ledger): the library is injected at process
|
|
# start, idle until a trigger file appears (docs/e2e-run.md, "CUPTI hook"). Not set -> nothing changes.
|
|
if [ -n "${LELEKA_CUPTI_LIB:-}" ]; then
|
|
[ -r "$LELEKA_CUPTI_LIB" ] || { echo "LELEKA_CUPTI_LIB not readable"; exit 3; }
|
|
export CUDA_INJECTION64_PATH=$LELEKA_CUPTI_LIB LELEKA_CUPTI_TRIGGER=${LELEKA_CUPTI_TRIGGER:-$OUT/cupti.trigger}
|
|
fi
|
|
eval "\"$BIN/leleka-inference\" --listen 127.0.0.1:18766 --token-env LELEKA_RUNTIME_TOKEN \
|
|
--shard0 \"$A/model/Qwen3.8-Flash-Next-GSQ-RCO-IQ3_S-00001-of-00002.gguf\" \
|
|
--shard1 \"$A/model/Qwen3.8-Flash-Next-GSQ-RCO-IQ3_S-00002-of-00002.gguf\" \
|
|
--gpu 0 --gpu-budget ${E2E_GPU_BUDGET:-25769803776} --context-tokens 262144 \
|
|
--kar-archive-fd $FD --kar-provenance \"$A/qwen-iq3-s-l2-v4.kar.provenance.json\" \
|
|
--mtp-pack \"$A/data/mtp-rt\" --mtp-staging \"$G/mtp-staging-own\" \
|
|
--backend-mode original $RT_ARG ${E2E_ENGINE_ARGS:-} >\"$OUT/inference.log\" 2>&1 &"
|
|
PID_INF=$!
|
|
unset CUDA_INJECTION64_PATH
|
|
sleep 3
|
|
alive "$PID_INF" || { log "leleka-inference died at startup"; tail -20 "$OUT/inference.log"; exit 5; }
|
|
eval "\"$BIN/leleka-daemon\" --config \"$STATE/daemon.json\" $FD>&- >\"$OUT/daemon.log\" 2>&1 &"
|
|
PID_DAE=$!
|
|
sleep 2
|
|
alive "$PID_DAE" || { log "leleka-daemon died at startup"; tail -20 "$OUT/daemon.log"; exit 5; }
|
|
CLI() { "$BIN/leleka-cli" --config "$STATE/daemon.json" "$@"; }
|
|
T_LOAD=$(date +%s)
|
|
log "load-mtp: $(CLI load-mtp qwen-iq3 qwen4exp-kar-ple-mtp-v1 2>&1 | tr '\n' ' ' | sed 's/"operation_id":"[^"]*",//')"
|
|
ready=0
|
|
for i in $(seq 1 480); do
|
|
st=$(CLI status 2>&1)
|
|
if echo "$st" | grep -Eq '"model_ready" *: *true'; then ready=1; break; fi
|
|
alive "$PID_INF" || { log "leleka-inference died during load"; tail -30 "$OUT/inference.log"; exit 5; }
|
|
if grep -q '^leleka-load phase=' "$OUT/inference.log" 2>/dev/null; then
|
|
log "load failed:"; grep -E '^leleka-(load|serve)' "$OUT/inference.log" | head -10; echo "$st" | head -12; exit 5
|
|
fi
|
|
sleep 5
|
|
done
|
|
LOAD_S=$(( $(date +%s) - T_LOAD ))
|
|
[ "$ready" = 1 ] || { log "model did not become ready in 2400 s"; echo "$st" | head -20; tail -30 "$OUT/inference.log"; exit 5; }
|
|
log "model ready after ${LOAD_S}s"
|
|
echo "load_seconds=$LOAD_S" >"$OUT/load.txt"
|
|
|
|
# ---- API ---------------------------------------------------------------------------------------------------------
|
|
eval "\"$BIN/strata-next\" serve --config \"$STATE/strata.json\" $FD>&- >\"$OUT/strata-next.log\" 2>&1 &"
|
|
PID_STR=$!
|
|
if ! "$BIN/strata-next" wait-ready --url http://127.0.0.1:8081 --model qwen-iq3 --key-file "$KEYFILE" --timeout-s 180 >"$OUT/wait-ready.log" 2>&1; then
|
|
log "strata-next never became ready"; tail -20 "$OUT/wait-ready.log"; tail -30 "$OUT/strata-next.log"; exit 6
|
|
fi
|
|
log "strata-next ready"
|
|
echo "pids inference=$PID_INF daemon=$PID_DAE strata=$PID_STR"
|
|
rss() { awk '/VmRSS/{print int($2/1024)" MiB"}' /proc/$1/status; }
|
|
log "rss after load: inference $(rss "$PID_INF"), strata-next $(rss "$PID_STR"), gpu $(nvidia-smi --query-gpu=memory.used --format=csv,noheader)"
|
|
|
|
# ---- client ------------------------------------------------------------------------------------------------------
|
|
if [ -n "${E2E_STATUS_FILE:-}" ]; then bash "$HERE/status_writer.sh" "$OUT" "$E2E_STATUS_FILE" "${E2E_STATUS_S:-60}" >/dev/null 2>&1 & PID_STATUS=$!; fi
|
|
bash "$HERE/sample_env.sh" "$OUT/env.tsv" "${E2E_SAMPLE_S:-30}" "inference=$PID_INF" "strata=$PID_STR" "daemon=$PID_DAE" >/dev/null 2>&1 &
|
|
PID_SAMPLER=$!
|
|
if [ -n "${E2E_RUN_CMD:-}" ]; then
|
|
# an external client (the Codex CLI jobs): it gets the base URL and a key variable; the key file stays private
|
|
export E2E_BASE_URL=http://127.0.0.1:8081 E2E_MODEL=qwen-iq3 E2E_OUT_DIR="$OUT"
|
|
E2E_API_KEY=$(cat "$KEYFILE") bash -c "$E2E_RUN_CMD" 2>&1 | tee "$OUT/client.log"
|
|
RC=${PIPESTATUS[0]}
|
|
else
|
|
python3 -I "$CLIENT" --base http://127.0.0.1:8081 --key-file "$KEYFILE" --model qwen-iq3 --out "$OUT/results.json" \
|
|
--scenarios "${E2E_SCENARIOS:-all}" --context-dir "$CONTEXT" --pids "inference=$PID_INF,strata=$PID_STR,daemon=$PID_DAE" ${E2E_CLIENT_ARGS:-} 2>&1 | tee "$OUT/client.log"
|
|
RC=${PIPESTATUS[0]}
|
|
fi
|
|
kill "$PID_SAMPLER" ${PID_STATUS:-} 2>/dev/null
|
|
log "client exit status $RC"
|
|
log "engine stderr tail (request outcome lines):"
|
|
grep -E 'leleka-serve request|panicked|ERROR|error' "$OUT/inference.log" | tail -n 15 | cut -c1-300
|
|
log "strata-next stderr (non-empty lines, head):"
|
|
grep -v '^$' "$OUT/strata-next.log" | head -n 15 | cut -c1-300
|
|
echo "$RC" >"$OUT/client.rc"
|
|
exit "$RC"
|