tiny-voca-da / recipe /scripts /gpu_pipeline.sh
inlanger's picture
tiny-voca-da v0.1: frontend v4 + sm9 vocoder (ONNX fp32/int8, PyTorch, frontend, recipe, samples)
adabee1 verified
Raw History Blame Contribute Delete
6.3 kB
#!/usr/bin/env bash
# Full-corpus Danish pipeline (kit/CPU_WORKFLOW.md, scaled from the 300/45/45 pilot
# to the whole prepared CoRal speaker). Runs inside the kit container:
# docker compose run --rm kit bash scripts/gpu_pipeline.sh <stage>
# Every stage writes to its own new directory; existing outputs are never overwritten
# (the kit scripts refuse to), so a stage that already finished must not be rerun into
# the same path.
set -euo pipefail
cd /opt/kit
SPEAKER="${SPEAKER:-mic}"
# TAG separates frontends: "full" = v2 (eSpeak, service `kit`), "v3" = NST + stød
# (service `kit-v3`). Data, acoustic features and wav2vec2 states are frontend-independent
# and shared; everything from the CTC head onwards is per TAG.
TAG="${TAG:-full}"
CFG=config.da.json
DATA="${DATA:-data/coral_da}" # prepare_coral.py output for $SPEAKER (shared); trimmed: data/coral_da_trim
DATA_REPORT=checks/coral_data.json; [[ "$DATA" != data/coral_da ]] && DATA_REPORT="checks/$TAG-data.json"
FEAT="${FEAT:-data/full-features}" # tiny_voca.prepare acoustic features (v2 shared; v3 needs its own: FEAT=data/v3-features)
CACHE="work/$TAG-head-cache" # wav2vec2 hidden states, train+validation
TEST_CACHE="work/$TAG-head-test-cache" # wav2vec2 hidden states, test only
HEAD_RUN="work/$TAG-head-run" # refitted Danish CTC head
TIMING="checks/$TAG-head-timing.json"
HEAD_VAL="checks/$TAG-head-validation"
HEAD_TEST="checks/$TAG-head-test"
ANN="data/$TAG-annotations" # exported TTS annotations
PACKED="data/$TAG-prepared" # portable accepted features + annotations
WORKERS="${WORKERS:-8}"
THREADS="${THREADS:-8}"
# v3 only: reuse the v2 GPU wav2vec2 states (same preprocessing identity) instead of recomputing.
REUSE=(); [[ -n "${CACHE_REUSE:-}" ]] && REUSE=(--reuse $CACHE_REUSE)
REUSE_TEST=(); [[ -n "${CACHE_REUSE_TEST:-}" ]] && REUSE_TEST=(--reuse $CACHE_REUSE_TEST)
export TINY_VOCA_ALIGN_DEVICE=cuda # read by kit-v3's adapt_head.py
head_cmd() { python alignment_head/adapt_head.py --threads "$THREADS" "$@"; }
# v2's adapt_head.py takes --device on `cache`; v3's reads TINY_VOCA_ALIGN_DEVICE instead.
cache_device() { python alignment_head/adapt_head.py cache --help | grep -q -- --device && echo --device cuda || true; }
stage="${1:?stage: check-data|features|cache|fit|calibrate|evaluate|test|export|pack|train-scratch|train-adapt}"
case "$stage" in
check-data)
python check_data.py --data "$DATA" --config "$CFG" --out "$DATA_REPORT" ;;
features)
# Parallel workers corrupt librosa's on-disk numba cache and the next loader
# segfaults (BrokenProcessPool). run_nocache.py turns numba disk caching off;
# features are byte-identical. The --resume retry is only a safety net.
for SPLIT in train validation test; do
for attempt in 1 2 3; do
RESUME=(); [[ $attempt -gt 1 ]] && RESUME=(--resume)
if python scripts/run_nocache.py -m tiny_voca.prepare --inputs "$DATA/$SPLIT.jsonl" --split "$SPLIT" \
--output "$FEAT" --config "$CFG" --workers "$WORKERS" "${RESUME[@]}"; then
break
fi
echo "features $SPLIT attempt $attempt failed" >&2
[[ $attempt -eq 3 ]] && exit 1
done
done ;;
cache)
head_cmd cache $(cache_device) --manifest "$DATA/train.jsonl" "$DATA/validation.jsonl" \
--config "$CFG" --output "$CACHE" "${REUSE[@]}" ;;
fit)
# Same hyper-parameters as the pilot; selection by validation greedy PER only.
head_cmd fit --cache "$CACHE" --config "$CFG" --output "$HEAD_RUN" \
--epochs 40 --batch-size 8 --learning-rate 0.001 --weight-decay 0.01 --seed 20261124 ;;
calibrate)
head_cmd calibrate --cache "$CACHE" --checkpoint "$HEAD_RUN/best.pt" \
--features "$FEAT" --config "$CFG" --output "$TIMING" ;;
evaluate)
ONSET="$(python read_onset.py "$TIMING")"
head_cmd evaluate --cache "$CACHE" --checkpoint "$HEAD_RUN/best.pt" \
--features "$FEAT" --config "$CFG" --splits train validation --negative-controls 10 \
--onset-offset "$ONSET" --unexplained-voiced-frames 8 --output "$HEAD_VAL" ;;
test)
# Head and onset are frozen before this point; test is never used for selection.
ONSET="$(python read_onset.py "$TIMING")"
head_cmd cache $(cache_device) --manifest "$DATA/test.jsonl" --config "$CFG" --output "$TEST_CACHE" "${REUSE_TEST[@]}"
head_cmd evaluate --cache "$TEST_CACHE" --checkpoint "$HEAD_RUN/best.pt" \
--features "$FEAT" --config "$CFG" --splits test --onset-offset "$ONSET" \
--unexplained-voiced-frames 8 --output "$HEAD_TEST" ;;
export)
head_cmd export-annotations --evaluation "$HEAD_VAL" "$HEAD_TEST" \
--features "$FEAT" --config "$CFG" --output "$ANN"
python check_annotations.py --annotations "$ANN" --config "$CFG" \
--load-features --output "checks/$TAG-annotations.json" ;;
pack)
python pack_prepared.py --annotations "$ANN" --config "$CFG" --output "$PACKED"
python check_annotations.py --annotations "$PACKED/annotations" --config "$CFG" \
--load-features --output "checks/$TAG-prepared-annotations.json" ;;
train-scratch|train-adapt)
# Upstream defaults, as used by tiny-voca-it on real recordings (docs/italian.md):
# batch 9000 frames / 32, GAN from step 8000 at ratio 0.7, no teacher forcing at the end.
# train-scratch: new weights. train-adapt: all weights from the Danish initialisation.
RUN="${RUN:?set RUN=runs/<name> (new directory)}"
STEPS="${STEPS:-100000}"
TRAIN_ANN="${TRAIN_ANN:-$PACKED/annotations}"
EXTRA=()
if [[ -f "$RUN/last.pt" ]]; then
EXTRA=(--resume "$RUN/last.pt")
elif [[ "$stage" == train-adapt ]]; then
EXTRA=(--adapt-from "${INITIALIZATION:-models/da-initialized-gpu.pt}" --adapt-mode full --init-voice DA1)
fi
python -m tiny_voca.train \
--train "$TRAIN_ANN/train.jsonl" --validation "$TRAIN_ANN/validation.jsonl" \
--config "$CFG" --output "$RUN" --device cuda \
--steps "$STEPS" --batch-frames 9000 --max-batch 32 \
--gan-start 8000 --gan-ratio 0.7 --teacher-final 0 \
--save-every 1000 --keep-every 10000 --log-every 50 \
--max-seconds inf --stop-file "$RUN/STOP" "${EXTRA[@]}" ;;
*) echo "unknown stage: $stage" >&2; exit 2 ;;
esac