Something went wrong. Try again.
This repository has no description
Something went wrong. Try again.
Shell
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110# Sourced, not run: the part every model-batch script shares (bench/absolute-mixed-batch.sh,# bench/overflow-mixed-run.sh). A batch compiles and scores its candidates on the rig's# CPUs, never on the development box, so a batch script started anywhere but on a lane# re-runs itself on one.## BENCH_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"# source "$BENCH_DIR/batch-lane.sh"# batch_on_lane <script path in the repository> --pull <path>... -- "$@"# batch_load_env## batch_on_lane returns when already on a lane (bench/lane-apply.sh exports NEV_ON_LANE).# Otherwise it replaces the calling script with bench/on-lane.sh --lane-only, which runs# the same script, with the same arguments, in this worktree's copy on the lane and copies# each --pull path back afterwards. With no lane configured or none answering it fails# (exit 3) rather than run the batch here.## The batch's settings travel with it: every NEV_*/GENERA_* variable in the environment is# passed to the lane's run, except the lane's own settings (*_LANE_*), the model address# (the lane has its own, bench/lane-apply.sh) and anything named like a credential# (*KEY*, *TOKEN*, *SECRET*, *PASSWORD*) -- those stay in .env, which reaches the lane by# its own route. Values are never printed; only the names go to stderr.
batch_on_lane() { local script="$1"; shift local pull=() while [ $# -gt 0 ]; do case "$1" in --pull) pull+=(--pull "$2"); shift 2 ;; --) shift; break ;; *) echo "batch_on_lane: expected --pull <path> or --, got $1" >&2; exit 2 ;; esac done if [ -n "${NEV_ON_LANE:-${GENERA_ON_LANE:-}}" ]; then return 0 fi local bench_dir worktree name forward=() names=() bench_dir="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" worktree="$(cd "$bench_dir/.." && pwd)" while IFS= read -r name; do case "$name" in *_LANE_*|*MODEL_URL|*KEY*|*TOKEN*|*SECRET*|*PASSWORD*|NEV_ON_LANE|GENERA_ON_LANE) continue ;; esac forward+=("$name=${!name}") names+=("$name") done < <(compgen -e | grep -E '^(NEV|GENERA)_' | sort) echo "batch: running $script on a build lane with ${names[*]:-no NEV_ settings}" >&2 exec "$bench_dir/on-lane.sh" --lane-only "${pull[@]+"${pull[@]}"}" "$worktree" \ env "${forward[@]+"${forward[@]}"}" bash "$script" "$@"}
# Exports .env into the batch's environment without overriding what the environment# already holds: a setting given on the command line (NEV_MODEL, say) wins over the same# key in .env. The binaries read the model endpoint from the environment, so this is how# they find it; nothing from the file is printed.batch_load_env() { [ -f .env ] || return 0 local name keep=() while IFS= read -r name; do if [ -n "${!name+x}" ]; then keep+=("$name=${!name}"); fi done < <(grep -oE '^[A-Za-z_][A-Za-z0-9_]*=' .env | tr -d '=') set -a # shellcheck disable=SC1091 source .env set +a local kv for kv in "${keep[@]+"${keep[@]}"}"; do export "${kv?}"; done}
# Phase and CPU recording, so a run leaves the numbers docs/rig-capacity.md records: how# long each phase took and how many of the lane's CPUs it kept busy.# batch_measure_start <dir> starts bench/cpu-sample.sh into <dir>/cpu.tsv# batch_phase <name> marks the start of a phase in <dir>/phases.tsv# batch_stamp a filter: copies stdin to stdout unchanged, and to# <dir>/run.stamped.log with the time before each line# (bench/cpu-phases.py splits the model run by it)# batch_measure_stop ends the last phase, stops the sampler, writes# <dir>/cpu-phases.txt (also printed) and appends the# batch to the track's ledger on the NAS (bench/ledger.py)batch_measure_start() { BATCH_MEASURE_DIR="$1" mkdir -p "$BATCH_MEASURE_DIR" : > "$BATCH_MEASURE_DIR/phases.tsv" : > "$BATCH_MEASURE_DIR/run.stamped.log" bash "$(dirname "${BASH_SOURCE[0]}")/cpu-sample.sh" "$BATCH_MEASURE_DIR/cpu.tsv" 2 & BATCH_SAMPLER_PID=$!}batch_phase() { printf '%s %s\n' "$EPOCHREALTIME" "$1" >> "$BATCH_MEASURE_DIR/phases.tsv"}batch_stamp() { local line while IFS= read -r line; do printf '%s\n' "$line" printf '%s %s\n' "$EPOCHREALTIME" "$line" >> "$BATCH_MEASURE_DIR/run.stamped.log" done}batch_measure_stop() { batch_phase end # One more sample interval, so the last phase's tail is counted. sleep 3 kill "$BATCH_SAMPLER_PID" 2>/dev/null || true wait "$BATCH_SAMPLER_PID" 2>/dev/null || true python3 "$(dirname "${BASH_SOURCE[0]}")/cpu-phases.py" "$BATCH_MEASURE_DIR/cpu.tsv" \ "$BATCH_MEASURE_DIR/phases.tsv" "$BATCH_MEASURE_DIR/run.stamped.log" \ | tee "$BATCH_MEASURE_DIR/cpu-phases.txt" # One line for the track's ledger on the NAS, which a landing's announcement reads # (bench/ledger.py; never fails the batch). python3 "$(dirname "${BASH_SOURCE[0]}")/ledger.py" "$BATCH_MEASURE_DIR" || true}