#!/bin/bash # Job queue / supervisor. # # Keeps the experiment pipeline moving without a person watching it, for DEADLINE_H hours: # # 1. keep-alive — if a long job's wrapper has died but its work is unfinished, restart it # (every wrapper is itself resumable, so a restart continues, not repeats) # 2. ablations — runs_ablate: three MTLCC ablations, strictly one at a time # 3. publish — every CYCLE_MIN: regenerate the reports from the result files, rebuild # the manuscript, and push to the Hugging Face repo # # HF_TOKEN must be in the environment when this is started. It is never written to disk. set -u HF=/home/ubuntu/pro/hf_work M=/home/ubuntu/pro/TSRDA_MTLCC P=/home/ubuntu/pro/TSRDA_PLANTEUR LOG=$HF/queue.log DEADLINE_H=${DEADLINE_H:-7.5} CYCLE_MIN=${CYCLE_MIN:-20} END=$(python3 -c "import time;print(int(time.time()+${DEADLINE_H}*3600))") say () { echo "[queue $(date -u +%H:%M:%S)] $*" >> "$LOG"; } alive () { pgrep -f "$1" > /dev/null 2>&1; } say "==============================================================" say "queue started; deadline in ${DEADLINE_H} h, cycle ${CYCLE_MIN} min" cycle=0 while [ "$(date +%s)" -lt "$END" ]; do cycle=$((cycle + 1)) say "--- cycle $cycle ---" # ---------- 1. keep-alive ------------------------------------------------- # PLANTEUR label-efficiency curve (its own wrapper retries and skips finished runs) if ! alive "retry_ft.sh" && ! alive "run_experiments.py finetune"; then n_done=$(ls -d $P/runs/finetune/*/result.json 2>/dev/null | wc -l) if [ "$n_done" -lt 14 ]; then say "PLANTEUR wrapper not running and only $n_done/14 runs done -> restarting" ( cd $P/runs && nohup ./retry_ft.sh >> $P/runs/finetune_retry.log 2>&1 & ) else say "PLANTEUR curve complete ($n_done/14)" fi fi # MTLCC mask-0.4 re-pre-training if ! alive "runs_mask04/run.sh" && ! alive "pretrain.py"; then eps=$(grep -c "^\[ep.* DONE\]" $M/runs_mask04/run.log 2>/dev/null || echo 0) if [ "$eps" -lt 100 ]; then say "mask-0.4 wrapper not running at epoch $eps/100 -> restarting (resumes)" ( cd $M && nohup bash runs_mask04/run.sh >> $M/runs_mask04/run.log 2>&1 & ) else say "mask-0.4 pre-training complete ($eps epochs)" fi fi # ---------- 2. ablation queue -------------------------------------------- if ! alive "ablate.sh"; then if [ -f $M/runs_ablate/.all_done ]; then say "ablations complete" else say "ablation queue not running -> starting (skips any already finished)" mkdir -p $M/runs_ablate nohup bash -c "cd $M && bash runs/ablate.sh >> $M/runs/ablate.log 2>&1; \ touch $M/runs_ablate/.all_done" >/dev/null 2>&1 & fi fi # ---------- 2b. test evaluation of the mask-0.4 fine-tune -------------------- # run.sh trains the fine-tune but does not score it on the test set; do that here, once. FT04=$M/runs_mask04/finetune_mask04 if grep -q "MASK04 PIPELINE DONE" $M/runs_mask04/run.log 2>/dev/null \ && [ -f $FT04/model_best_ema.tar ] && [ ! -f $FT04/eval_test_ema.json ] && ! alive "eval_mtlcc.py"; then say "mask-0.4 fine-tune finished -> scoring raw + EMA on the test set" ( cd $M/code && export EXP_ROOT=$M/runs PYTORCH_CUDA_ALLOC_CONF=expandable_segments:True EVAL_BATCH=4 for W in raw ema; do for i in 1 2 3 4 5; do python3 eval_mtlcc.py --ckpt $FT04/model_best_$W.tar --split test --out $FT04/eval_test_$W.json && break sleep 120 done done ) >> "$LOG" 2>&1 & fi # ---------- 3. reports + manuscript + publish ---------------------------- python3 $HF/make_reports.py >> "$LOG" 2>&1 && say "reports regenerated" \ || say "WARNING make_reports failed" if [ $((cycle % 3)) -eq 1 ]; then ( cd /home/ubuntu/pro/PAPER && timeout 900 ./build.sh ) >> "$LOG" 2>&1 \ && say "manuscript rebuilt" || say "WARNING paper build failed" python3 $HF/build_stage2.py >> "$LOG" 2>&1 && say "stage2 rebuilt" \ || say "WARNING build_stage2 failed" python3 $HF/make_reports.py >> "$LOG" 2>&1 # pick up the rebuilt PDF/figures timeout 3600 python3 $HF/sync_hf.py all >> "$LOG" 2>&1 && say "pushed everything to HF" \ || say "WARNING full sync failed" else timeout 1800 python3 $HF/sync_hf.py reports >> "$LOG" 2>&1 && say "pushed reports to HF" \ || say "WARNING report sync failed" timeout 1800 python3 $HF/sync_hf.py mtlcc >> "$LOG" 2>&1 && say "pushed MTLCC results to HF" \ || say "WARNING mtlcc sync failed" fi # restore kit (code snapshot, chat history, in-progress checkpoints) every 6th cycle if [ $((cycle % 6)) -eq 2 ]; then timeout 2400 python3 $HF/make_restore.py push >> "$LOG" 2>&1 && say "restore kit refreshed on HF" \ || say "WARNING restore kit push failed" fi # ---------- disk guard ---------------------------------------------------- use=$(df --output=pcent / | tail -1 | tr -dc '0-9') say "disk / at ${use}%" if [ "$use" -ge 88 ]; then say "DISK AT ${use}% — over the 88% line; clearing the HF download cache" rm -rf $HF/hfhome/hub 2>/dev/null use=$(df --output=pcent / | tail -1 | tr -dc '0-9'); say "disk now ${use}%" fi sleep $((CYCLE_MIN * 60)) done say "deadline reached; final pass" python3 $HF/make_reports.py >> "$LOG" 2>&1 python3 $HF/build_stage2.py >> "$LOG" 2>&1 timeout 3600 python3 $HF/sync_hf.py all >> "$LOG" 2>&1 say "queue finished. Training jobs that are still running keep running; re-launch this script to resume publishing."