#!/usr/bin/env bash
# usage: boot.sh NAME -- boot the Flash TP2 engine for build NAME (host side; config in builds/NAME.env).
# builds/NAME.env sets IMAGE, optional SRC (tree bind-mounted at /w), EXTRA_ARGS, EXTRA_ENV (docker -e list).
set -u
NAME=$1; D=$HOME/q5055; M=/mnt/k8scache/models/Qwen3.8-Flash-Next-exl3-2.05bpw_h4_ng4
SRC=; EXTRA_ARGS=; EXTRA_ENV=; source $D/builds/$NAME.env
# The supported overlay (compose.bindmount.yaml): the tree's package over the image's, and a
# per-tree ARBI_PYC_TAG so two trees never share one bytecode cache entry.
SP=/opt/venv/lib/python3.12/site-packages
SRCV=(); [ -n "$SRC" ] && SRCV=(-v $SRC/arbi_serve:$SP/arbi_serve:ro -e ARBI_PYC_TAG=$NAME)
docker rm -f q5055-engine >/dev/null 2>&1
exec docker run --rm --init --name q5055-engine --cgroupns=host --shm-size=8g --ipc=host \
  -e NVIDIA_VISIBLE_DEVICES=0,1 -e ARBI_TP_SIZE=2 -e ARBI_ALLOW_BACKEND_DRIFT=1 $EXTRA_ENV \
  "${SRCV[@]}" -v /mnt/arbi-engine-cache/q5055-4090/cache:/cache -v /mnt/arbi-engine-cache/flat-weights:/cache/arbi-serve/flat-weights \
  -v /mnt/k8scache/ext-cache:/ext-cache -e ARBI_EXT_SHARE_DIR=/ext-cache -v $M:/model:ro \
  -v /mnt/k8scache/calibration-corpus:/mnt/k8scache/calibration-corpus:ro \
  -v $D/admin.tokens:/run/admin.tokens:ro -p 127.0.0.1:18671:8000 $IMAGE --model=/model --served-name model \
  --max-batch=1 --moe-ep-size 2 $EXTRA_ARGS --host 0.0.0.0 --port 8000 --admin-token-file /run/admin.tokens
