#!/usr/bin/env bash
# DV-5: the stop guard's unit body on benchbox. Reads the one card's UUID into DV_CARD (never printed or written)
# and runs guard_speed.py with the house's phone-home switches. Started as:
#
#   systemd-run --user --unit dv-speed-guard-<dry|timed> --collect -p MemoryMax=1G -p RuntimeMaxSec=7200 \
#     --setenv=DV_DIR=<scratch> bash <wt>/.../speed/guard_unit.sh <dry|timed>
set -euo pipefail
TAG=${1:?dry or timed}
: "${DV_DIR:?set DV_DIR}"
U=$(nvidia-smi --query-gpu=uuid --format=csv,noheader)
[ "$(printf '%s\n' "$U" | grep -c .)" = 1 ] || { echo "REFUSED: not exactly one card on the bus"; exit 3; }
export DV_CARD="$U" ORT_DISABLE_TELEMETRY=1 HF_HUB_DISABLE_TELEMETRY=1 HF_HUB_OFFLINE=1 TRANSFORMERS_OFFLINE=1 \
  VLLM_NO_USAGE_STATS=1 GRADIO_ANALYTICS_ENABLED=False
unset DO_NOT_TRACK
exec /usr/bin/python3 -B "$DV_DIR/wt/bench/deciders-von-laya-2026-10-01/instrument/speed/guard_speed.py" --tag "$TAG"
