#!/usr/bin/env bash
# The served boot's own int8 plan (svc02e607a231f: model + drafter exl3 pairs + the pack's Q8_KS sidecar), GPU-free
# sm_89, for arms A then B, on box 201's build slot. One compile job, 14g cap.
set -uo pipefail
N=/mnt/k8scache/agent-snapshots/exl3-vision-fuse-20261112; IMG=local/arbi-serve:main-43d0876
exec 9</run/lock/arbi-build.lock; flock 9
for ARM in A B; do
  echo "arm $ARM avail=$(awk '/MemAvailable/{print int($2/1048576)}' /proc/meminfo)G $(date -Is)"
  docker run --rm --name vfuse-plan-$ARM --runtime runc --memory 14g --cpus 4 --user 0:0 \
    -v $N/tree$ARM/arbi_serve:/opt/venv/lib/python3.12/site-packages/arbi_serve:ro \
    -v /mnt/k8scache/models:/models:ro -v $N/share:/ext-share --tmpfs /ext:exec,size=3g \
    -e TORCH_CUDA_ARCH_LIST=8.9 -e I8_MAX_JOBS=1 -e MAX_JOBS=1 -e ARBI_EXT_SHARE_DIR=/ext-share \
    -e TORCH_EXTENSIONS_DIR=/ext -e PYTHONDONTWRITEBYTECODE=1 -e CUDA_VISIBLE_DEVICES= \
    --entrypoint python $IMG -m arbi_serve.weight_quant.exl3.int8_served_set \
    --exl3-checkpoint /models/Qwen3.8-27B-exl3-4.0bpw-vision6 --exl3-checkpoint /models/Qwen3.8-27B-DFlash2-exl3-6.0bpw \
    --gguf Q8_KS:none --build 2>&1 | grep -v "warning #\|^ *\^\|detected during\|instantiation of\|^$\|float2 wd\|declared but never"
  echo "arm $ARM rc=${PIPESTATUS[0]} $(date -Is)"
done
ls $N/share/arbi_serve_exl3_i8_gemm_v1_svc02e607a231f
