Redhanuman's picture
Pocket Storyteller: 4.6 MB story model, browser demo, weights and training code
ebf8f81 verified
Raw History Blame Contribute Delete
1.92 kB
#!/bin/bash
# Extra rounds of training, one per line of rounds.conf: name minutes learning-rate
# Each round warms up and cools down on its own, and its result is kept in rounds/<name>.pt.
# The last 16 saves of the round stay in snaps/, for avg_snaps.py.
# Safe to run again at any time: it carries on where it stopped. Run with: bash more.sh
cd "$(dirname "$0")"
exec 9> more.lock; flock -n 9 || { echo "already running"; exit 0; }
mkdir -p rounds
# Optional: KEEP=/some/folder bash more.sh also copies each result there, for example to a disk
# that outlives this machine.
# Optional: USE_JEMALLOC=1 bash more.sh keeps freed memory ready for the next step. It made no
# difference to this model (143 steps a minute either way), so it is off unless asked for.
JE=/usr/lib/x86_64-linux-gnu/libjemalloc.so.2
[ -f "$JE" ] && [ -n "$USE_JEMALLOC" ] && FASTMEM="env LD_PRELOAD=$JE MALLOC_CONF=dirty_decay_ms:-1,muzzy_decay_ms:-1,thp:always"
i=0
while [ "$i" -lt "$(grep -c '' rounds.conf)" ]; do # the file is read again each time, so a round can be added while another runs
i=$((i + 1))
read -r NAME MINUTES LR _ <<< "$(sed -n "${i}p" rounds.conf)"
case "$NAME" in ""|\#*) continue;; esac # empty lines and lines that start with # are skipped
[ -f "rounds/$NAME.pt" ] && continue
echo "=== $NAME: $MINUTES minutes at $LR, started $(date -u +%H:%M) UTC ${FASTMEM:+(jemalloc)}" >> train_more.out
$FASTMEM python3 train.py --resume --tag "$NAME" --minutes "$MINUTES" --lr "$LR" --fast --keep 16 >> train_more.out 2>&1 || { echo "=== $NAME stopped with an error" >> train_more.out; exit 1; }
cp ckpt.pt "rounds/$NAME.tmp" && mv "rounds/$NAME.tmp" "rounds/$NAME.pt"
echo "=== $NAME finished $(date -u +%H:%M) UTC" >> train_more.out
[ -n "$KEEP" ] && [ -d "$KEEP" ] && ( cp "rounds/$NAME.pt" "$KEEP/ckpt_$NAME.pt" & )
done
echo "=== all rounds done $(date -u +%H:%M) UTC" >> train_more.out