Download code/queue.sh from pei2333/Grid_CrossDomain_Compress_Delivery_20261105: direct link, hf CLI and curl.
- Browser
- Download file 14.7 kB
-
https://huggingface.co/datasets/pei2333/Grid_CrossDomain_Compress_Delivery_20261105/resolve/main/code/queue.sh
- Command line
-
hf download hf://datasets/pei2333/Grid_CrossDomain_Compress_Delivery_20261105/code/queue.sh
-
curl -L -o queue.sh https://huggingface.co/datasets/pei2333/Grid_CrossDomain_Compress_Delivery_20261105/resolve/main/code/queue.sh
14.7 kB
| # Full experiment queue: two lanes, each runs its jobs in order and waits for the other lane's results. Run from code/: | |
| # AFTER=<run> GPU=<id> nohup bash queue.sh <1|2> [stage] > ../logs/q<lane>.log 2>&1 < /dev/null & (GPU defaults to lane - 1) | |
| # ../runs/<name>/DONE marks a finished run (skipped on restart); FAILED propagates to dependents. | |
| # ../runs/<A|B>_data/DONE = target-domain data complete (written below when the dataset yaml exists; B also by fetch_insplad.sh). | |
| # Kinds: T teacher(l) | S0 student(n) | S1 +logit KD | S2 +projection alignment | S3 LoRA K=4 + router (multi-domain) | |
| # S3k1 LoRA K=1 | FT full fine-tune of S2 (multi-domain) | J student trained jointly on both domains | E eval table | |
| # P prune S2 (30% channels) + KD recovery = S2p | S3p LoRA K=4 on S2p | Ep eval table of the pruned branch | |
| # P2 S3p2 Ep2 same, recovery as long as S2's own training (P's half-length recovery was still improving) | |
| # Lt LoRA (K=1) on target data only, no teacher (source-free: how much does the source domain forget?) | Elt its eval table | |
| # T2 | Tx source | target-domain teacher (l) at 2x epochs (T at 1x was still improving) | S1t S2t = S1 S2 taught by T2 | |
| # S3x S3 distilled from per-domain experts (source: A T2 / B T, target: Tx) | S3nt S3 without any teacher | Ex Exb Ent eval tables | |
| # Lts S3nts <seed>: Lt / S3nt again with another seed (S2 kept) | Es <seed>: their eval table + density-card routing on that Lt | |
| # Lab <seed>: routing lab (route_lab.py: every routing rule and card setting) on S2 + that seed's Lt | |
| # Ltp S3ntp: Lt / S3nt on the pruned S2p2 | Labp their routing lab | Epsf their eval table | |
| # B only, three sites cn -> cnfog (same scenes, synthetic fog) -> br: Ltf LoRA on cnfog | S3nt3 joint on all three | Lab3 | E3 | |
| # Dpl deployable card routing (deploy_route.py) on the pruned pair S2p2 + Ltp | Dfu Dfup the same with fused cards | |
| # (deploy_route.py --mode fused: early style + layer-10 features along the base model, threshold 0) on S2 + Lt | S2p2 + Ltp | |
| # Ltr <r>: Lt at LoRA rank r | Ltd <pct>: Lt on pct% of the target training images | Eabl Efr their eval tables | |
| lane=$1 g=${GPU:-$(($1 - 1))} PY=${PY:-python} | |
| export OMP_NUM_THREADS=8 MKL_NUM_THREADS=8 CUDA_DEVICE_ORDER=PCI_BUS_ID | |
| mkdir -p ../logs ../runs | |
| [ -f ../datasets/A_weather/multi.yaml ] && mkdir -p ../runs/A_data && touch ../runs/A_data/DONE | |
| [ -f ../datasets/B_region/multi.yaml ] && mkdir -p ../runs/B_data && touch ../runs/B_data/DONE | |
| wait_for() { for d in ${1//,/ }; do until [ -f ../runs/$d/DONE ] || [ -f ../runs/$d ]; do [ -f ../runs/$d/FAILED ] && return 1; sleep 60; done; done; } # run name or a file in ../runs | |
| run() { # run <name> <deps|-> <gridkd train args...> | |
| local n=$1 dep=$2; shift 2; [ -f ../runs/$n/DONE ] && return; mkdir -p ../runs/$n; rm -f ../runs/$n/FAILED | |
| if [ "$dep" != - ] && ! wait_for $dep; then touch ../runs/$n/FAILED; return; fi | |
| $PY gridkd.py train "$@" device=$g project=../runs name=$n > ../logs/$n.log 2>&1 < /dev/null && touch ../runs/$n/DONE || touch ../runs/$n/FAILED | |
| } | |
| A=../datasets/A_weather B=../datasets/B_region | |
| A_src="--data $A/clear.yaml" A_tgt="--data $A/fog.yaml" A_multi="--data $A/multi.yaml --domains /clear/,/fog/" A_ep=100 A_ad=50 A_doms="clear fog" A_ts=T2 | |
| B_src="--data $B/cn.yaml" B_tgt="--data $B/br.yaml" B_multi="--data $B/multi.yaml --domains /cn/,/br/" B_ep=60 B_ad=30 B_doms="cn br" B_ts=T | |
| yn=../weights/pretrained/yolo11n.pt yl=../weights/pretrained/yolo11l.pt hp="imgsz=640 batch=16" | |
| ad="optimizer=AdamW warmup_epochs=1 warmup_bias_lr=0.0 $hp" | |
| evaluate() { # evaluate <csv name> <LoRA run, merged per domain> <runs...>: every model on every domain's test split | |
| local out=$1 s3=$2 P="$PY gridkd.py" w="" r d; shift 2 | |
| [ -f ../runs/$out.csv ] && return | |
| wait_for $(IFS=,; echo "$*") || return | |
| for r in "$@"; do w="$w ../runs/$r/weights/best.pt"; done | |
| for d in $doms; do $P merge --weights ../runs/$s3/weights/best.pt --gates $D/$d.yaml --out ../runs/${s3}_$d.pt --device $g; w="$w ../runs/${s3}_$d.pt"; done | |
| $P eval --weights $w --data $(for d in $doms; do echo $D/$d.yaml; done) --device $g --out ../runs/$out.csv | |
| } > ../logs/$1.log 2>&1 < /dev/null | |
| evalonly() { # evalonly <csv name> <runs...>: every run on every domain's test split, nothing merged | |
| local out=$1 w="" r; shift | |
| [ -f ../runs/$out.csv ] && return | |
| wait_for $(IFS=,; echo "$*") || return | |
| for r in "$@"; do w="$w ../runs/$r/weights/best.pt"; done | |
| $PY gridkd.py eval --weights $w --data $(for d in $doms; do echo $D/$d.yaml; done) --device $g --out ../runs/$out.csv | |
| } > ../logs/$1.log 2>&1 < /dev/null | |
| seedeval() { # seedeval <A|B> <seed>: Lt and S3nt of that seed on both domains, then density-card routing on its Lt | |
| local b=$1 s=$2 P="$PY" D doms; eval "D=\$$b doms=\$${b}_doms"; set -- $doms | |
| [ -f ../runs/${b}_eval_cards_s$s.csv ] && return | |
| wait_for ${b}_Lt_s$s,${b}_S3nt_s$s || return | |
| $P gridkd.py eval --weights ../runs/${b}_Lt_s$s/weights/best.pt ../runs/${b}_S3nt_s$s/weights/best.pt --data $D/$1.yaml $D/$2.yaml --device $g --out ../runs/${b}_eval_seed$s.csv && | |
| CUDA_VISIBLE_DEVICES="" $P gridkd.py bnsw --weights ../runs/${b}_Lt_s$s/weights/best.pt --base ../runs/${b}_S2/weights/best.pt --mode cum --out ../runs/${b}_Lt_s${s}_bncum.pt && | |
| $P route_cards.py --weights ../runs/${b}_Lt_s${s}_bncum.pt --src $D/$1.yaml --tgt $D/$2.yaml --k 8 --device $g --out ../runs/${b}_eval_cards_s$s.csv | |
| } > ../logs/${1}_seedeval$2.log 2>&1 < /dev/null | |
| lab() { # lab <out> <deps> <models...> -- <data.yaml per site>: routing lab | |
| local out=$1 dep=$2 m=(); shift 2 | |
| while [ "$1" != -- ]; do m+=("$1"); shift; done; shift | |
| [ -f ../runs/$out.csv ] && return | |
| wait_for $dep || return | |
| $PY route_lab.py --models "${m[@]}" --data "$@" --device $g --out ../runs/$out.csv | |
| } > ../logs/$1.log 2>&1 < /dev/null | |
| deploy() { # deploy <A|B>: merge Ltp, then deploy_route.py on S2p2 + Ltp | |
| local b=$1 P="$PY" | |
| [ -f ../runs/${b}_eval_deploy_p.csv ] && return | |
| wait_for ${b}_Ltp || return | |
| $P gridkd.py merge --weights ../runs/${b}_Ltp/weights/best.pt --gates 1 --out ../runs/${b}_Ltp_merged.pt && | |
| $P deploy_route.py --base ../runs/${b}_S2p2/weights/best.pt --site ../runs/${b}_Ltp_merged.pt --lora ../runs/${b}_Ltp/weights/best.pt \ | |
| --src $D/${doms% *}.yaml --tgt $D/${doms#* }.yaml --device $g --out ../runs/${b}_eval_deploy_p.csv | |
| } > ../logs/$1_deploy_p.log 2>&1 < /dev/null | |
| dfused() { # dfused <LoRA run> <base weights> <csv>: fused-card deployment | |
| local lt=$1 base=$2 out=$3 P="$PY" | |
| [ -f ../runs/$out.csv ] && return | |
| wait_for $lt || return | |
| [ -f ../runs/${lt}_merged.pt ] || $P gridkd.py merge --weights ../runs/$lt/weights/best.pt --gates 1 --out ../runs/${lt}_merged.pt | |
| $P deploy_route.py --mode fused --q 0 --base $base --site ../runs/${lt}_merged.pt --lora ../runs/$lt/weights/best.pt \ | |
| --src $D/${doms% *}.yaml --tgt $D/${doms#* }.yaml --device $g --out ../runs/$out.csv | |
| } > ../logs/$3.log 2>&1 < /dev/null | |
| dv2() { # dv2 <A|B> <base run> <LoRA run> <tag>: both deployment modes again, one-sync router and median latency | |
| local b=$1 base=$2 lt=$3 t=$4 P="$PY" m | |
| [ -f ../runs/${b}_eval_deploy_fused_$t.csv ] && return | |
| wait_for $lt || return | |
| for m in early fused; do | |
| $P deploy_route.py --mode $m --q $([ $m = fused ] && echo 0 || echo 0.05) --base ../runs/$base/weights/best.pt --site ../runs/${lt}_merged.pt \ | |
| --lora ../runs/$lt/weights/best.pt --src $D/${doms% *}.yaml --tgt $D/${doms#* }.yaml --device $g \ | |
| --out ../runs/${b}_eval_deploy_$([ $m = fused ] && echo fused_)$t.csv || return | |
| done | |
| } > ../logs/$1_deploy_$4.log 2>&1 < /dev/null | |
| prune() { # S2 -> 30% channels removed (DepGraph), recovered below as S2p | |
| [ -f $2 ] || { wait_for ${1}_S2 && $PY gridkd.py prune --weights ../runs/${1}_S2/weights/best.pt --ratio 0.3 --out $2 > ../logs/${1}_prune.log 2>&1; } | |
| } | |
| job() { # job <A|B> <kind> | |
| b=$1; eval "src=\$${b}_src tgt=\$${b}_tgt multi=\$${b}_multi ep=\$${b}_ep adep=\$${b}_ad doms=\$${b}_doms D=\$$b ts=\$${b}_ts" | |
| t="--teacher ../runs/${b}_T/weights/best.pt" t2="--teacher ../runs/${b}_T2/weights/best.pt" s2=../runs/${b}_S2/weights/best.pt | |
| case $2 in | |
| T) run ${b}_T - $src --model $yl epochs=$ep $hp ;; | |
| S0) run ${b}_S0 - $src --model $yn epochs=$ep $hp ;; | |
| S1) run ${b}_S1 ${b}_T $src --model $yn $t --w-pa 0 epochs=$ep $hp ;; | |
| S2) run ${b}_S2 ${b}_T $src --model $yn $t epochs=$ep $hp ;; | |
| S3) run ${b}_S3 ${b}_S2,${b}_data $multi --model $s2 $t --lora-r 4 --lora-k 4 epochs=$adep lr0=1e-3 $ad ;; | |
| S3k1) run ${b}_S3k1 ${b}_S2,${b}_data $multi --model $s2 $t --lora-r 4 --lora-k 1 epochs=$adep lr0=1e-3 $ad ;; | |
| FT) run ${b}_FT ${b}_S2,${b}_data $multi --model $s2 $t epochs=$adep lr0=1e-4 $ad ;; | |
| J) run ${b}_J ${b}_data $multi --model $yn epochs=$ep $hp ;; | |
| E) evaluate ${b}_eval ${b}_S3 ${b}_T ${b}_S0 ${b}_S1 ${b}_S2 ${b}_S3 ${b}_S3k1 ${b}_FT ${b}_J ;; | |
| P) prune $b ../runs/${b}_S2_p30.pt && run ${b}_S2p ${b}_S2 $src --model ../runs/${b}_S2_p30.pt $t epochs=$adep $hp ;; | |
| S3p) run ${b}_S3p ${b}_S2p,${b}_data $multi --model ../runs/${b}_S2p/weights/best.pt $t --lora-r 4 --lora-k 4 epochs=$adep lr0=1e-3 $ad ;; | |
| Ep) evaluate ${b}_eval_prune ${b}_S3p ${b}_S2p ${b}_S3p ;; | |
| P2) run ${b}_S2p2 ${b}_S2 $src --model ../runs/${b}_S2_p30.pt $t epochs=$ep $hp ;; | |
| S3p2) run ${b}_S3p2 ${b}_S2p2,${b}_data $multi --model ../runs/${b}_S2p2/weights/best.pt $t --lora-r 4 --lora-k 4 epochs=$adep lr0=1e-3 $ad ;; | |
| Ep2) evaluate ${b}_eval_prune2 ${b}_S3p2 ${b}_S2p2 ${b}_S3p2 ;; | |
| Lt) run ${b}_Lt ${b}_S2,${b}_data $tgt --model $s2 --lora-r 4 --lora-k 1 epochs=$adep lr0=1e-3 $ad ;; | |
| Elt) evaluate ${b}_eval_lt ${b}_Lt ${b}_Lt ;; | |
| T2) run ${b}_T2 - $src --model $yl epochs=$((ep*2)) $hp ;; | |
| S1t) run ${b}_S1t ${b}_T2 $src --model $yn $t2 --w-pa 0 epochs=$ep $hp ;; | |
| S2t) run ${b}_S2t ${b}_T2 $src --model $yn $t2 epochs=$ep $hp ;; | |
| Tx) run ${b}_Tx - $tgt --model $yl epochs=$((ep*2)) $hp ;; | |
| S3x) run ${b}_S3x ${b}_S2,${b}_$ts,${b}_Tx,${b}_data $multi --model $s2 --teacher ../runs/${b}_$ts/weights/best.pt,../runs/${b}_Tx/weights/best.pt --lora-r 4 --lora-k 4 epochs=$adep lr0=1e-3 $ad ;; | |
| S3nt) run ${b}_S3nt ${b}_S2,${b}_data $multi --model $s2 --lora-r 4 --lora-k 4 epochs=$adep lr0=1e-3 $ad ;; | |
| Ex) evaluate ${b}_eval_experts ${b}_S3x ${b}_T2 ${b}_Tx ${b}_S1t ${b}_S2t ${b}_S3x ${b}_S3nt ;; | |
| Exb) evaluate ${b}_eval_experts ${b}_S3x ${b}_Tx ${b}_S3x ;; # B has no T2 runs | |
| Ent) evaluate ${b}_eval_nt ${b}_S3nt ${b}_S3nt ;; | |
| Lts) run ${b}_Lt_s$3 ${b}_S2,${b}_data $tgt --model $s2 --lora-r 4 --lora-k 1 epochs=$adep lr0=1e-3 $ad seed=$3 ;; | |
| S3nts) run ${b}_S3nt_s$3 ${b}_S2,${b}_data $multi --model $s2 --lora-r 4 --lora-k 4 epochs=$adep lr0=1e-3 $ad seed=$3 ;; | |
| Es) seedeval $b $3 ;; | |
| Relab) f=../runs/${b}_lab_s$3.csv; grep -q "^fused," $f 2>/dev/null || { [ -f $f ] && mv $f ${f%.csv}_v1.csv; job $b Lab $3; } ;; # rerun labs from before the deep / fused rules | |
| Lab) r=${b}_Lt$([ "$3" = 0 ] || echo _s$3); lab ${b}_lab_s$3 $r $s2 ../runs/$r/weights/best.pt -- $D/${doms% *}.yaml $D/${doms#* }.yaml ;; | |
| Ltp) run ${b}_Ltp ${b}_S2p2,${b}_data $tgt --model ../runs/${b}_S2p2/weights/best.pt --lora-r 4 --lora-k 1 epochs=$adep lr0=1e-3 $ad ;; | |
| S3ntp) run ${b}_S3ntp ${b}_S2p2,${b}_data $multi --model ../runs/${b}_S2p2/weights/best.pt --lora-r 4 --lora-k 4 epochs=$adep lr0=1e-3 $ad ;; | |
| Labp) lab ${b}_lab_p ${b}_Ltp ../runs/${b}_S2p2/weights/best.pt ../runs/${b}_Ltp/weights/best.pt -- $D/${doms% *}.yaml $D/${doms#* }.yaml ;; | |
| Epsf) evaluate ${b}_eval_psf ${b}_S3ntp ${b}_Ltp ${b}_S3ntp ;; | |
| Dpl) deploy $b ;; | |
| Dfu) dfused ${b}_Lt $s2 ${b}_eval_deploy_fused ;; | |
| Dv2) dv2 $b ${b}_S2 ${b}_Lt v2 ;; | |
| Dv2p) dv2 $b ${b}_S2p2 ${b}_Ltp v2p ;; | |
| Dfup) dfused ${b}_Ltp ../runs/${b}_S2p2/weights/best.pt ${b}_eval_deploy_fusedp ;; | |
| Ltf) run B_Ltf B_S2,B_data --data $B/cnfog.yaml --model ../runs/B_S2/weights/best.pt --lora-r 4 --lora-k 1 epochs=$B_ad lr0=1e-3 $ad ;; | |
| S3nt3) run B_S3nt3 B_S2,B_data --data $B/multi3.yaml --domains /cn/,/cnfog/,/br/ --model ../runs/B_S2/weights/best.pt --lora-r 4 --lora-k 4 epochs=$B_ad lr0=1e-3 $ad ;; | |
| Lab3) lab B_lab3 B_Ltf,B_Lt ../runs/B_S2/weights/best.pt ../runs/B_Ltf/weights/best.pt ../runs/B_Lt/weights/best.pt -- $B/cn.yaml $B/cnfog.yaml $B/br.yaml ;; | |
| E3) doms="cn cnfog br" evaluate B_eval3 B_S3nt3 B_Ltf B_S3nt3 ;; | |
| Ltr) run ${b}_Lt_r$3 ${b}_S2,${b}_data $tgt --model $s2 --lora-r $3 --lora-k 1 epochs=$adep lr0=1e-3 $ad ;; | |
| Ltd) run ${b}_Lt_d$3 ${b}_S2,${b}_data $tgt --model $s2 --lora-r 4 --lora-k 1 epochs=$adep lr0=1e-3 $ad fraction=0.$3 ;; | |
| Eabl) evalonly ${b}_eval_abl ${b}_Lt_r1 ${b}_Lt_r2 ${b}_Lt_r8 ${b}_Lt_r16 ;; | |
| Efr) evalonly ${b}_eval_frac ${b}_Lt_d10 ${b}_Lt_d25 ${b}_Lt_d50 ;; | |
| esac | |
| } | |
| [ -n "$AFTER" ] && wait_for $AFTER | |
| case $lane:${2:-main} in | |
| 1:main) for j in "A T" "A S1" "A S3" "A S3k1" "A J" "A E" "B S1" "B S3" "B S3k1"; do job $j; done ;; | |
| 2:main) for j in "A S0" "B S0" "A S2" "A FT" "B T" "B S2" "B FT" "B J" "B E"; do job $j; done ;; | |
| 1:prune) for j in "A P" "A S3p" "A Ep"; do job $j; done ;; # start with AFTER=B_S3k1 | |
| 2:prune) for j in "B P" "B S3p" "B Ep"; do job $j; done ;; # start with AFTER=B_eval.csv | |
| 1:experts) for j in "B S3nt" "B Ent" "A T2" "A S3x" "A S1t" "A S2t" "A Ex"; do job $j; done ;; # AFTER=A_eval_prune.csv | |
| 2:experts) for j in "A Tx" "A S3nt" "B Tx" "B S3x" "B Exb"; do job $j; done ;; # AFTER=B_eval_prune.csv | |
| 1:prune2) for j in "A P2" "A S3p2" "A Ep2" "B P2" "B S3p2" "B Ep2"; do job $j; done ;; # AFTER=A_eval_experts.csv | |
| 2:lsl0) for j in "B Lt" "B Elt" "A Lt" "A Elt"; do job $j; done ;; | |
| 1:seeds) for j in "B Lts 1" "B S3nts 1" "B Es 1" "A Lts 2" "A S3nts 2" "A Es 2"; do job $j; done ;; | |
| 2:seeds) for j in "A Lts 1" "A S3nts 1" "A Es 1" "B Lts 2" "B S3nts 2" "B Es 2"; do job $j; done ;; | |
| 1:more) for j in "A Relab 0" "A Relab 1" "A Relab 2" "A Dfu" "A Ltp" "A S3ntp" "A Labp" "A Epsf" "A Dpl" "A Dfup" "B Ltf" "B Ltr 1" "B Ltr 2" "B Ltr 8" "B Ltr 16" "B Eabl"; do job $j; done ;; # after lane 1 seeds | |
| 2:more) for j in "B Relab 0" "B Relab 1" "B Relab 2" "B Dfu" "B S3nt3" "B Ltp" "B S3ntp" "B Labp" "B Epsf" "B Dpl" "B Dfup" "B Lab3" "B E3" \ | |
| "B Ltd 10" "B Ltd 25" "B Ltd 50" "B Efr" "A Ltd 10" "A Ltd 25" "A Ltd 50" "A Efr"; do job $j; done ;; # after lane 2 seeds | |
| 1:tail) for j in "A Dv2" "A Dv2p"; do job $j; done ;; # after lane 1 more | |
| 2:tail) for j in "B Dv2" "B Dv2p"; do job $j; done ;; # after lane 2 more | |
| esac | |
| echo "lane $lane ${2:-main} done" | |