Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
173 lines
12 KiB
Bash
173 lines
12 KiB
Bash
#!/usr/bin/env bash
|
|
# Codex + runtime + model comparison, vanilla Strata against Leleka, on the owner's two tasks (docs/experiments/codex-compare-5090.md). Test tooling, never in serving.
|
|
#
|
|
# ONE BLOCK = one stack start of one arm, then the warm-up cell and the requested cells of ONE repetition. A queue stub sets CMP_ARM / CMP_REPS / CMP_TASKS:
|
|
# CMP_ARM=ours HOLDER JOB (inherits the sealed KAR memfd): the release package, `leleka up --foreground --kar-fd`, shipped configuration (KAR PLE, prefix cache auto / tail reply).
|
|
# CMP_ARM=vanilla holder-free window payload (started by cmp_window.sh): vanilla Strata 0.2.6 launcher, shipped defaults (route tail skip and CPU prefill share ON).
|
|
# CMP_VANILLA_LOSSY=0 turns both lossy defaults off (variant VANL instead of VAN).
|
|
# CMP_TASKS ("ttt nestng-crm") CMP_OPTIONAL (tasks dropped, with a note, when not ready) CMP_REPS ("1") CMP_WALL (cell wall limit s, default 3000) CMP_ROUNDS (round cap, default 150) CMP_RUN (default $CMP/runs/main)
|
|
# CMP_TARBALL (ours; default the final release package)
|
|
# Cells: cell.py of the codex-lossy-delta study (logging proxy, temperature 0 injected for BOTH arms, real Codex CLI, task acceptance); no AGENTS.md pad: the sessions are what a
|
|
# user gets. Output: $RUN/<VARIANT>/<task>-r<rep>/ (cell.json, proxy/, acceptance.log ...), $RUN/<VARIANT>/stack-r<rep>/. Variants: LEL = Leleka, VAN = vanilla shipped, VANL = vanilla lossless.
|
|
set -uo pipefail
|
|
ARM=${CMP_ARM:?CMP_ARM ours|vanilla}
|
|
CMP=/data/leleka-e2e/codex-compare
|
|
TASKS_ROOT=$CMP/tasks
|
|
CELLPY=$CMP/delta/cell.py
|
|
CODEX=/home/para/work/codex-e2e/bin/codex
|
|
LOCK=/data/leleka-e2e/gpu.lock
|
|
G=$HOME/work/gpu-runs
|
|
A=/home/para/work/leleka/models/leleka-gates/assets
|
|
CUBLAS=$HOME/cuda-toolkits/cublas-12.9.1.4/lib
|
|
TASKS=${CMP_TASKS:-"ttt"}
|
|
REPS=${CMP_REPS:-"1"}
|
|
RUN=${CMP_RUN:-$CMP/runs/main}
|
|
WALL=${CMP_WALL:-3000}; ROUNDS=${CMP_ROUNDS:-150}
|
|
NODE_BIN=$(ls -d "$CMP"/toolchain/node-v*-linux-x64/bin 2>/dev/null | tail -1)
|
|
NM=$CMP/nm
|
|
case $ARM in ours) VAR=LEL;; vanilla) if [ "${CMP_VANILLA_LOSSY:-1}" = 1 ]; then VAR=VAN; else VAR=VANL; fi;; *) echo "bad CMP_ARM"; exit 2;; esac
|
|
BLK=$(echo "$REPS" | tr ' ' '+')
|
|
mkdir -p "$RUN" "$RUN/$VAR"
|
|
exec > >(tee -a "$RUN/job-$VAR-r$BLK.log") 2>&1
|
|
log() { echo "[cmp $VAR $(date -u +%T)] $*"; }
|
|
note() { echo "[$(date -u +%FT%TZ)] [DEV codex-compare] $*" >>/data/leleka-e2e/decode/notes.md; }
|
|
|
|
# ---- guards ---------------------------------------------------------------------------------------------------------------------------------
|
|
( cd "$CMP" && sha256sum --quiet -c INSTALL.sha256 ) || { echo "installed tools differ from INSTALL.sha256"; exit 3; }
|
|
python3 -I "$CMP/delta/taskfile.py" check "$TASKS_ROOT" >"$RUN/tasks-check-$VAR-r$BLK.txt" 2>&1 || { echo "task files differ from their manifest"; cat "$RUN/tasks-check-$VAR-r$BLK.txt"; exit 3; }
|
|
# a task listed in CMP_OPTIONAL that is not ready (not installed, or the Node toolchain not proven in the Codex sandbox) is DROPPED with a loud note instead of refusing the block
|
|
nestng_ready() { [ -f "$TASKS_ROOT/nestng-crm/task.md" ] && [ -f "$CMP/toolchain/NESTNG_OK" ] && [ -d "$NM/backend/node_modules" ] && [ -d "$NM/frontend/node_modules" ]; }
|
|
KEEP=""
|
|
for t in $TASKS; do
|
|
if [ "$t" = nestng-crm ] && ! nestng_ready; then
|
|
case " ${CMP_OPTIONAL:-} " in *" $t "*) log "TASK DROPPED: $t is not ready (toolchain/NESTNG_OK missing)"; note "codex-compare block $VAR reps [$REPS]: task $t DROPPED (not ready); queue it again later"; continue;; esac
|
|
echo "task $t is not ready (toolchain/NESTNG_OK, shared node_modules)"; exit 3
|
|
fi
|
|
[ -f "$TASKS_ROOT/$t/task.md" ] || { echo "task $t is not installed in $TASKS_ROOT"; exit 3; }
|
|
KEEP="$KEEP $t"
|
|
done
|
|
TASKS=${KEEP# }
|
|
[ -f "$TASKS_ROOT/smoke-mini/task.md" ] || { echo "task smoke-mini is not installed"; exit 3; }
|
|
[ -x "$CODEX" ] || { echo "no codex binary"; exit 3; }
|
|
[ -n "$NODE_BIN" ] && [ -x "$NODE_BIN/node" ] || { echo "no node toolchain under $CMP/toolchain"; exit 3; }
|
|
STANDALONE=0; FD=${LELEKA_STRA169_KAR_FD:-}
|
|
if [ "$ARM" = ours ]; then
|
|
readlink "/proc/self/fd/$FD" 2>/dev/null | grep -q '^/memfd:' || { echo "ours needs the holder's sealed memfd"; exit 3; }
|
|
[ -d "$G/MODEL.lock" ] || { echo "MODEL.lock is not held"; exit 3; }
|
|
else
|
|
mkdir "$G/MODEL.lock" 2>/dev/null || { echo "MODEL.lock is held (holder still up?)"; exit 3; }; STANDALONE=1
|
|
fi
|
|
got=0
|
|
for _ in $(seq 1 4320); do
|
|
if mkdir "$LOCK" 2>/dev/null; then echo "codex-compare $VAR $(date -u +%FT%TZ) $RUN" >"$LOCK/owner"; got=1; break; fi
|
|
sleep 5
|
|
done
|
|
[ $got = 1 ] || { echo "GPU lock held by: $(cat $LOCK/owner 2>/dev/null)"; [ $STANDALONE = 1 ] && rmdir "$G/MODEL.lock"; exit 3; }
|
|
SUP_PID=; MON_PID=
|
|
stop_stack() {
|
|
if [ -n "$SUP_PID" ] && kill -0 "$SUP_PID" 2>/dev/null; then kill -TERM "$SUP_PID" 2>/dev/null; for _ in $(seq 1 120); do kill -0 "$SUP_PID" 2>/dev/null || break; sleep 2; done; fi
|
|
SUP_PID=
|
|
}
|
|
cleanup() {
|
|
stop_stack
|
|
[ -n "$MON_PID" ] && kill "$MON_PID" 2>/dev/null
|
|
pkill -KILL -f "$CMP/ours-prefix/bin/" 2>/dev/null
|
|
if [ "$ARM" = vanilla ]; then ( cd "$HOME/work/vanilla-strata/control" && ./bin/strata launch --stop >/dev/null 2>&1 ); fi
|
|
sleep 3
|
|
rm -f "$LOCK/owner"; rmdir "$LOCK" 2>/dev/null
|
|
[ $STANDALONE = 1 ] && rmdir "$G/MODEL.lock" 2>/dev/null
|
|
note "codex-compare block $VAR reps [$REPS] ended: $RUN"
|
|
}
|
|
trap cleanup EXIT
|
|
note "codex-compare block $VAR started: $RUN tasks=[$TASKS] reps=[$REPS] wall=$WALL cap=$ROUNDS; holds gpu.lock"
|
|
if [ -n "$(nvidia-smi --query-compute-apps=pid --format=csv,noheader 2>/dev/null)" ]; then echo "something uses the GPU"; exit 3; fi
|
|
if pgrep -u "$USER" -x 'leleka-inference|strata-next|leleka-daemon' >/dev/null; then echo "a stack process exists"; exit 3; fi
|
|
for p in 18766 18080 8081 8090; do ss -ltn "sport = :$p" 2>/dev/null | grep -q LISTEN && { echo "port $p in use"; exit 3; }; done
|
|
export LD_LIBRARY_PATH=$CUBLAS:$HOME/cuda-toolkits/13.2.2/lib64:${LD_LIBRARY_PATH:-}
|
|
# what the agent's shell sees, identical for both arms: Node on PATH, no analytics, caches in /tmp (the sandbox writes the workspace and /tmp only)
|
|
export PATH=$NODE_BIN:$PATH NG_CLI_ANALYTICS=false npm_config_cache=/tmp/cmp-npm-cache npm_config_update_notifier=false npm_config_fund=false npm_config_audit=false CI=1
|
|
{ date -u +%FT%TZ; uname -r; nvidia-smi --query-gpu=name,driver_version,power.limit --format=csv,noheader; free -g | sed -n 2p; uptime; $CODEX --version; node --version; sha256sum "$CODEX"; } | tee "$RUN/$VAR/host-r$BLK.txt"
|
|
STK=$RUN/$VAR/stack-r$BLK; mkdir -p "$STK"
|
|
nvidia-smi --query-gpu=timestamp,temperature.gpu,clocks.sm,clocks.mem,power.draw,utilization.gpu --format=csv -l 10 >"$STK/mon.csv" 2>/dev/null & MON_PID=$!
|
|
|
|
run_cells() { # $1 upstream url, $2 upstream model, $3 engine log, $4 api key ('' = none)
|
|
local url=$1 model=$2 elog=$3 key=$4 rep task t1 rc list link
|
|
for rep in $REPS; do
|
|
list="smoke-mini $TASKS"
|
|
[ $((rep % 2)) = 0 ] && list="smoke-mini $(echo $TASKS | tr ' ' '\n' | tac | tr '\n' ' ')" # task order alternates with the repetition
|
|
for task in $list; do
|
|
CELL=$RUN/$VAR/$task-r$rep; [ "$task" = smoke-mini ] && CELL=$RUN/$VAR/smoke-mini-r$((100 + rep))
|
|
[ -f "$CELL/cell.json" ] && { log "cell $CELL already done: skipped"; continue; }
|
|
link=""; [ "$task" = nestng-crm ] && link="--link-tree backend/node_modules=$NM/backend/node_modules --link-tree frontend/node_modules=$NM/frontend/node_modules"
|
|
t1=$(date +%s)
|
|
E2E_API_KEY=${key:-none} CLD_CODEX=$CODEX timeout $((WALL + 900)) python3 -I "$CELLPY" --cell-dir "$CELL" --variant "$VAR" --task "$task" --rep "$([ "$task" = smoke-mini ] && echo $((100 + rep)) || echo $rep)" \
|
|
--tasks-root "$TASKS_ROOT" --upstream "$url" --upstream-model "$model" --codex-bin "$CODEX" --wall-limit "$WALL" --max-rounds "$ROUNDS" \
|
|
--engine-log "$elog" --active-dir "$RUN/active-$VAR" --config-extra 'model_auto_compact_token_limit = 100000000' $link >"$CELL.out" 2>&1; rc=$?
|
|
log "cell $VAR $task r$rep rc=$rc $(( $(date +%s) - t1 )) s: $(tail -1 "$CELL.out" | cut -c1-200)"
|
|
done
|
|
done
|
|
}
|
|
|
|
if [ "$ARM" = ours ]; then
|
|
# ---- the release package, prepared ONCE into $CMP/ours-* (state, assets, prefix) and reused by every block ---------------------------------------
|
|
TARBALL=${CMP_TARBALL:-/data/leleka-e2e/release-5090/leleka-0.1.0-17e372944279-5090-linux-x86_64.tar.xz}
|
|
P=$CMP/ours-pkg; AS=$CMP/ours-assets; ST=$CMP/ours-state; PFX=$CMP/ours-prefix
|
|
if [ ! -x "$P/bin/leleka" ]; then mkdir -p "$P" && tar -xJf "$TARBALL" -C "$P" --strip-components=1 || { echo "unpack failed"; exit 5; }; fi
|
|
BIN=$P/bin
|
|
( cd "$P" && sha256sum --quiet -c SHA256SUMS && echo "SHA256SUMS ok" ); "$BIN/leleka" version | tee "$STK/version.txt"; sha256sum "$TARBALL" | tee -a "$STK/version.txt"
|
|
if [ ! -e "$AS/model" ]; then
|
|
mkdir -p "$AS/data"
|
|
ln -s "$A/model" "$AS/model"; ln -s "$A/tokenizer-assets" "$AS/tokenizer-assets"; ln -s "$A/qwen-iq3-s-l2-v4.kar" "$AS/qwen-iq3-s-l2-v4.kar"
|
|
cp "$A/qwen-iq3-s-l2-v4.kar.provenance.json" "$AS/qwen-iq3-s-l2-v4.kar.provenance.json"
|
|
cp -al "$A/data/iq3_s" "$AS/data/iq3_s"; cp -al "$A/data/mtp-rt" "$AS/data/mtp-rt"
|
|
fi
|
|
COMMON="--assets $AS --state-dir $ST --prefix $PFX --bin-src $BIN --cublas-dir $CUBLAS --trust-archive --kar-fd $FD"
|
|
if [ ! -f "$ST/leleka.json" ]; then timeout 3000 "$BIN/leleka" up --mode none $COMMON >"$STK/up-prepare.txt" 2>&1; log "up --mode none rc=$?"; fi
|
|
[ -f "$ST/leleka.json" ] || { echo "up did not prepare the state"; tail -20 "$STK/up-prepare.txt"; exit 6; }
|
|
log "leleka up --foreground (shipped configuration)"
|
|
t0=$(date +%s)
|
|
setsid "$BIN/leleka" up --foreground $COMMON --timeout-s 1800 >"$STK/up-foreground.txt" 2>&1 &
|
|
SUP_PID=$!
|
|
ready=0
|
|
for _ in $(seq 1 700); do
|
|
if "$PFX/bin/leleka" status --state-dir "$ST" >/dev/null 2>&1; then ready=1; break; fi
|
|
kill -0 "$SUP_PID" 2>/dev/null || break
|
|
sleep 3
|
|
done
|
|
if [ $ready != 1 ]; then log "NOT READY after $(( $(date +%s) - t0 )) s"; tail -20 "$STK/up-foreground.txt" | cut -c1-240; exit 7; fi
|
|
log "ready after $(( $(date +%s) - t0 )) s"
|
|
echo "$(( $(date +%s) - t0 ))" >"$STK/ready_s.txt"
|
|
"$PFX/bin/leleka" status --state-dir "$ST" >"$STK/status.txt" 2>&1; "$PFX/bin/leleka" status --state-dir "$ST" --json >"$STK/status.json" 2>&1
|
|
"$PFX/bin/leleka" verify --quick --state-dir "$ST" --assets "$AS" >"$STK/verify-quick.txt" 2>&1
|
|
KEY=$(cat "$ST/api-key")
|
|
run_cells http://127.0.0.1:8081 qwen-iq3 "$ST/logs/engine.log" "$KEY"
|
|
cp "$ST/logs/engine.log" "$STK/engine.log" 2>/dev/null; cp "$ST/logs/requests.log" "$STK/requests.log" 2>/dev/null
|
|
"$PFX/bin/leleka" verify --quick --state-dir "$ST" --assets "$AS" >"$STK/verify-quick-end.txt" 2>&1
|
|
stop_stack
|
|
else
|
|
# ---- vanilla Strata 0.2.6 (launcher + engine 0.1.50), shipped defaults unless CMP_VANILLA_LOSSY=0; state redirected into the run directory ----------
|
|
export XDG_CONFIG_HOME=$STK/xdg-config XDG_STATE_HOME=$STK/xdg-state
|
|
mkdir -p "$XDG_CONFIG_HOME/strata" "$XDG_STATE_HOME"; cp ~/.config/strata/settings.json "$XDG_CONFIG_HOME/strata/"
|
|
if [ "${CMP_VANILLA_LOSSY:-1}" = 1 ]; then unset STRATA_ROUTE_TAIL_SKIP STRATA_PREFILL_CPU_SHARE; else export STRATA_ROUTE_TAIL_SKIP=0 STRATA_PREFILL_CPU_SHARE=0; fi
|
|
unset STRATA_DECODE_TIMING STRATA_VERIFY_PROFILE
|
|
S=$HOME/work/vanilla-strata/control/bin/strata
|
|
{ sha256sum "$HOME/.local/share/strata/components/engine/0.1.50-linux-x86_64-cuda-cuda13/strata"; cat "$HOME/work/vanilla-strata/control/VERSION" "$HOME/work/vanilla-strata/control/COMMIT" 2>/dev/null; env | grep -E '^STRATA_' | sort; } >"$STK/env.txt"
|
|
cd "$HOME/work/vanilla-strata/control"
|
|
t0=$(date +%s)
|
|
timeout 2400 "$S" launch --model iq3_s --family qwen --model-path "$A/model" --context 256k --kv int8 --vision off --parallel 1 --tune skip --access local --port 8090 --no-api-key --no-tui --yes >"$STK/launch.out" 2>&1
|
|
log "vanilla launch rc=$? ready after $(( $(date +%s) - t0 )) s"
|
|
echo "$(( $(date +%s) - t0 ))" >"$STK/ready_s.txt"
|
|
if curl -fs http://127.0.0.1:8090/v1/models >"$STK/models.json"; then
|
|
MODEL=$(python3 -c "import json;print(json.load(open('$STK/models.json'))['data'][0]['id'])")
|
|
EL=$XDG_STATE_HOME/strata/launch/iq3_s-256k.engine.log
|
|
run_cells http://127.0.0.1:8090 "$MODEL" "$EL" ""
|
|
cp "$EL" "$STK/engine.log" 2>/dev/null
|
|
grep -iE "route tail skip|CPU share" "$STK/engine.log" | head -4 >"$STK/lossy-lines.txt"
|
|
else
|
|
log "vanilla did not become ready"
|
|
fi
|
|
"$S" launch --stop >>"$STK/launch.out" 2>&1
|
|
sleep 8
|
|
fi
|
|
log "done"
|