#!/usr/bin/env bash
# Prep (light, no GPU work): build the pinned image and pre-split checkpoints into per-layer shards so the
# timed runs in run.sh don't include the one-time split.
set -eu
D=${WORK:-$PWD}; OUT=${OUT_DIR:-$D/prep-out}; mkdir -p $OUT $D/shards; cp $D/bench.py $OUT/
cd $D && docker build -q -t rockytest-airllm:fd3bd7e . | tee $OUT/build.txt
HUB=${HF_HUB:-$HOME/.cache/huggingface/hub}
# one shard dir per model (AirLLM names the dir 'splitted_model', so a shared parent would mix models)
for T in 9b:$(ls -d $HUB/models--Qwen--Qwen3.5-9B/snapshots/*/ | head -1) 27b:$(ls -d $HUB/models--Qwen--Qwen3.6-27B/snapshots/*/ | head -1); do
  K=${T%%:*}; M=${T#*:}; mkdir -p $D/shards/$K
  docker run --rm --user $(id -u):$(id -g) -e HOME=/tmp -e USER=bench -e LOGNAME=bench --network none -e CUDA_VISIBLE_DEVICES= -e HF_HUB_OFFLINE=1 -v $HUB:$HUB:ro -v $D/shards:/shards -v $OUT:/out \
    rockytest-airllm:fd3bd7e python3 /out/bench.py --mode split --model $M --shards /shards/$K --label split-$K --out /out/split.jsonl
done
du -sh $D/shards/*/* | tee -a $OUT/build.txt
