91 lines
7.5 KiB
Bash
91 lines
7.5 KiB
Bash
#!/usr/bin/env bash
|
|
# Prefill fixed-latency program: one full Codex session block (smoke-mini warm-up, then the requested tasks) of OUR stack from the prefill-latency
|
|
# package (pkg/bin, own state and prefix, never the codex-compare release state). A copy of the `ours` arm of compare/cmp_codex_job.sh.
|
|
# HOLDER JOB (inherits the sealed KAR memfd). Test tooling, never in serving.
|
|
# PF_VAR result variant name, one directory under $PF_RUN (default LEL-A)
|
|
# PF_ENV engine environment of the `leleka up` process, space separated NAME=VALUE (default none = shipped)
|
|
# LEL-A: none (shipped, the prompt loan is the full 8192-row loan) LEL-L: LELEKA_PREFILL_LOAN_TIERS=1
|
|
# PF_TASKS tasks (default "nestng-crm") PF_REPS repetitions (default "1") PF_WALL cell wall limit s (3000) PF_ROUNDS round cap (150)
|
|
# PF_RUN result directory (default $PL/runs/codex) PF_ROOT task directory (default /data/leleka-e2e/prefill-latency)
|
|
# Cells: cell.py of the codex-compare study (logging proxy, temperature 0 injected, real Codex CLI, task acceptance), identical to the LEL/VAN/VANL cells.
|
|
set -uo pipefail
|
|
PL=${PF_ROOT:-/data/leleka-e2e/prefill-latency}
|
|
CMP=/data/leleka-e2e/codex-compare
|
|
VAR=${PF_VAR:-LEL-A}
|
|
TASKS=${PF_TASKS:-nestng-crm}; REPS=${PF_REPS:-1}
|
|
RUN=${PF_RUN:-$PL/runs/codex}
|
|
WALL=${PF_WALL:-3000}; ROUNDS=${PF_ROUNDS:-150}
|
|
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
|
|
CUBLAS=$HOME/cuda-toolkits/cublas-12.9.1.4/lib
|
|
NODE_BIN=$(ls -d "$CMP"/toolchain/node-v*-linux-x64/bin 2>/dev/null | tail -1)
|
|
NM=$CMP/nm
|
|
BLK=$(echo "$REPS" | tr ' ' '+')
|
|
mkdir -p "$RUN/$VAR"
|
|
exec > >(tee -a "$RUN/job-$VAR-r$BLK.log") 2>&1
|
|
log() { echo "[pfc $VAR $(date -u +%T)] $*"; }
|
|
note() { echo "[$(date -u +%FT%TZ)] [DEV prefill-latency] $*" >>/data/leleka-e2e/decode/notes.md; }
|
|
|
|
AS=$CMP/ours-assets; ST=$PL/state; PFX=$PL/prefix; BIN=$PL/pkg/bin
|
|
FD=${LELEKA_STRA169_KAR_FD:-}
|
|
( 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.txt" 2>&1 || { echo "task files differ from their manifest"; exit 3; }
|
|
[ -f "$CMP/toolchain/NESTNG_OK" ] && [ -d "$NM/backend/node_modules" ] || { echo "nestng-crm toolchain is not ready"; exit 3; }
|
|
[ -x "$CODEX" ] && [ -n "$NODE_BIN" ] && [ -x "$NODE_BIN/node" ] || { echo "no codex or node toolchain"; exit 3; }
|
|
[ -x "$BIN/leleka" ] && [ -f "$ST/leleka.json" ] || { echo "the prefill-latency package or state is not prepared"; exit 3; }
|
|
(cd "$PL/pkg/bin" && sha256sum -c ../SHA256SUMS >/dev/null 2>&1) || { echo "the package binaries do not match $PL/pkg/SHA256SUMS"; exit 3; }
|
|
readlink "/proc/self/fd/$FD" 2>/dev/null | grep -q '^/memfd:' || { echo "needs the holder's sealed memfd"; exit 3; }
|
|
[ -d "$G/MODEL.lock" ] || { echo "MODEL.lock is not held"; exit 3; }
|
|
got=0; for _ in $(seq 1 4320); do if mkdir "$LOCK" 2>/dev/null; then echo "prefill-codex $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)"; exit 3; }
|
|
SUP_PID=; MON_PID=; PSI_PID=; TAIL_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; [ -n "$PSI_PID" ] && kill "$PSI_PID" 2>/dev/null; [ -n "$TAIL_PID" ] && pkill -P "$TAIL_PID" 2>/dev/null; pkill -KILL -f "$PFX/bin/" 2>/dev/null; sleep 3; rm -f "$LOCK/owner"; rmdir "$LOCK" 2>/dev/null; note "prefill codex block $VAR ended: $RUN"; }
|
|
trap cleanup EXIT
|
|
note "prefill codex block $VAR started: $RUN tasks=[$TASKS] reps=[$REPS] env=[${PF_ENV:-}]"
|
|
[ -z "$(nvidia-smi --query-compute-apps=pid --format=csv,noheader 2>/dev/null)" ] || { echo "something uses the GPU"; exit 3; }
|
|
if pgrep -u "$USER" -x 'leleka-inference|leleka-api|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:-}
|
|
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
|
|
unset LELEKA_PREFILL_LOAN_TIERS LELEKA_TRACE_PREFILL_R LELEKA_SERVE_PROFILE LELEKA_REFILL_DEFER LELEKA_BRINGUP_TRACE
|
|
for kv in ${PF_ENV:-}; do export "$kv"; done
|
|
export LELEKA_SPEC_STATS=1
|
|
STK=$RUN/$VAR/stack-r$BLK; mkdir -p "$STK"
|
|
{ date -u +%FT%TZ; uname -r; nvidia-smi --query-gpu=name,driver_version,power.limit --format=csv,noheader; free -g | sed -n 2p; cat "$PL/pkg/COMMIT.txt"; env | grep -E '^(LELEKA_|STRATA_)' | grep -v KEY | sort; } | tee "$STK/host.txt"
|
|
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=$!
|
|
# Host memory counters (pf_memstat.sh: memstat.csv every 0.25 s, memstat.mem.csv every 15 s): a stall of the host-only spans (`input`, `other`) is matched against them by the request timestamps.
|
|
bash "$PL/tools/pf_memstat.sh" "$STK/memstat" & PSI_PID=$!
|
|
# The engine log rotates at 16 MiB and the rotated files are overwritten by the next run: keep the profile lines of the whole session (epoch ms first).
|
|
( tail -n 0 -F "$ST/logs/engine.log" 2>/dev/null | grep --line-buffered -a -E 'PREFILL-PROFILE|DBG profile request|"ev":"request"' | while IFS= read -r l; do echo "$(date +%s%3N) $l"; done ) >"$STK/prof.log" 2>/dev/null & TAIL_PID=$!
|
|
COMMON="--assets $AS --state-dir $ST --prefix $PFX --bin-src $BIN --cublas-dir $CUBLAS --trust-archive --kar-fd $FD"
|
|
: >"$ST/logs/engine.log" 2>/dev/null
|
|
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 "$PFX/bin/leleka" status --state-dir "$ST" >/dev/null 2>&1 && { ready=1; break; }; kill -0 "$SUP_PID" 2>/dev/null || break; sleep 3; done
|
|
[ $ready = 1 ] || { log "NOT READY"; tail -20 "$STK/up-foreground.txt" | cut -c1-240; exit 7; }
|
|
log "ready after $(( $(date +%s) - t0 )) s"
|
|
"$PFX/bin/leleka" status --state-dir "$ST" --json >"$STK/status.json" 2>&1
|
|
KEY=$(cat "$ST/api-key")
|
|
for rep in $REPS; do
|
|
list="smoke-mini $TASKS"
|
|
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 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 http://127.0.0.1:8081 --upstream-model qwen-iq3 \
|
|
--codex-bin "$CODEX" --wall-limit "$WALL" --max-rounds "$ROUNDS" --engine-log "$ST/logs/engine.log" --active-dir "$RUN/active-$VAR" \
|
|
--config-extra 'model_auto_compact_token_limit = 100000000' $link >"$CELL.out" 2>&1
|
|
log "cell $VAR $task r$rep rc=$? $(( $(date +%s) - t1 )) s: $(tail -1 "$CELL.out" | cut -c1-200)"
|
|
done
|
|
done
|
|
cp "$ST/logs/engine.log" "$STK/engine.log" 2>/dev/null; cp "$ST/logs/requests.log" "$STK/requests.log" 2>/dev/null
|
|
stop_stack
|
|
log "done"
|