File size: 1,431 Bytes
8c0ce05
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
#!/usr/bin/env bash
# Sequential job runner over an editable queue file: scripts/queue.sh [QUEUE_FILE]
# Each line is "RECIPE SEED" (train + screening evaluation) or "!<shell command>" (e.g. a soup or an evaluation-only run).
# Lines can be appended or reordered while it runs; it waits for any training job already running before starting the next.
set -u
trap 'trap - INT TERM; kill 0; exit 130' INT TERM
cd "$(dirname "$0")/.."
q=${1:-work/queue.txt}
mkdir -p work/logs
touch "$q"
while true; do
  while pgrep -f "guardtune.train|guardtune.evaluate|guardtune.soup" >/dev/null; do sleep 15; done
  line=$(head -n 1 "$q")
  if [ -z "$line" ]; then
    sed -i '1{/^$/d}' "$q"
    sleep 20
    continue
  fi
  sed -i '1d' "$q"
  if [ "${line:0:1}" = "!" ]; then
    echo "=== $(date -u +%H:%M:%S) ${line:1}" | tee -a work/logs/screen.txt
    bash -c "${line:1}" 2>&1 | grep --line-buffered -v -i -E "unauth|Loading weights|Writing model shards" >> work/logs/commands.log
    tail -n 1 work/logs/commands.log | tee -a work/logs/screen.txt
    continue
  fi
  read -r r seed <<< "$line"
  seed=${seed:-0}
  echo "=== $(date -u +%H:%M:%S) $r s$seed" | tee -a work/logs/screen.txt
  python -m guardtune.train --recipe "$r" --seed "$seed" 2>&1 \
    | grep --line-buffered -v -i -E "unauth|Loading weights|Writing model shards" > "work/logs/${r}_s${seed}.log"
  tail -n 1 "work/logs/${r}_s${seed}.log" | tee -a work/logs/screen.txt
done