File size: 3,647 Bytes
6494f15
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
b37bda4
 
6494f15
 
 
 
 
 
 
 
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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
#!/usr/bin/env bash
# Score a set of Whisper checkpoints on one held-out split, the way
# arXiv:2510.23319 scored eight variants on Levantine child speech.
#
# The point is the comparison, so every checkpoint must see the same
# utterances: the sample is drawn once, by seed, and reused for all of them.
#
# Usage: ./scripts/benchmark_whisper.sh [OPTIONS] [MODEL ...]
set -Eeuo pipefail

script_dir="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
project_root="$(cd "$script_dir/.." && pwd)"
cd "$project_root"

# The multilingual family only. The .en checkpoints cannot emit Arabic, so
# including them would report a floor for the tokenizer, not for the model.
default_models=(
  openai/whisper-tiny
  openai/whisper-base
  openai/whisper-small
  openai/whisper-medium
  openai/whisper-large-v3-turbo
  openai/whisper-large-v3
)

manifest="data/manifests/splits/test.jsonl"
output_root="reports/benchmark"
limit=600
seed=42
batch_size=16
device="auto"

usage() {
  cat <<'EOF'
Usage: ./scripts/benchmark_whisper.sh [OPTIONS] [MODEL ...]

Options:
  --manifest PATH     Split to score (default: data/manifests/splits/test.jsonl)
  --output-dir PATH   Where per-model reports land (default: reports/benchmark)
  --limit N           Speaker-stratified sample size; 0 scores everything (default: 600)
  --seed N            Sampling seed, shared by every model (default: 42)
  --batch-size N      Utterances per forward pass (default: 16)
  --device NAME       auto|cpu|cuda|mps (default: auto)
  -h, --help          Show this help

Any trailing arguments replace the default model list. A local path works
wherever a Hub id does, so a fine-tuned adapter can be compared against the
stock checkpoints in the same table:

  ./scripts/benchmark_whisper.sh artifacts/tiny-lora/final openai/whisper-tiny
EOF
}

while [[ $# -gt 0 ]]; do
  case "$1" in
    --manifest) manifest="${2:?missing value}"; shift 2 ;;
    --output-dir) output_root="${2:?missing value}"; shift 2 ;;
    --limit) limit="${2:?missing value}"; shift 2 ;;
    --seed) seed="${2:?missing value}"; shift 2 ;;
    --batch-size) batch_size="${2:?missing value}"; shift 2 ;;
    --device) device="${2:?missing value}"; shift 2 ;;
    -h|--help) usage; exit 0 ;;
    --*) echo "Unknown option: $1" >&2; usage >&2; exit 2 ;;
    *) break ;;
  esac
done

models=("$@")
[[ ${#models[@]} -eq 0 ]] && models=("${default_models[@]}")

for value in "$limit" "$seed" "$batch_size"; do
  [[ "$value" =~ ^[0-9]+$ ]] || { echo "Numeric options must be integers" >&2; exit 2; }
done
[[ -f "$manifest" ]] || { echo "Missing manifest: $manifest" >&2; exit 2; }

mkdir -p "$output_root"
echo "Manifest: $manifest"
echo "Sample:   ${limit:-all} utterances, seed $seed"
echo "Models:   ${#models[@]}"
echo

for model in "${models[@]}"; do
  # A Hub id contains a slash and a local checkpoint is a path; both need
  # flattening into one directory name.
  slug="${model//\//__}"
  destination="$output_root/$slug"
  if [[ -f "$destination/metrics.json" ]]; then
    echo "== $model -- already scored, skipping"
    continue
  fi
  echo "== $model"
  # One failure should not discard the models that already succeeded: a large
  # checkpoint can exhaust VRAM on a small GPU, and the rest of the sweep is
  # still worth having.
  # Module form, not the console script: see the note in train_gpu.sh.
  if ! python -m buddi_asr.cli evaluate "$model" "$manifest" "$destination" \
      --device "$device" --batch-size "$batch_size" --limit "$limit" --seed "$seed"; then
    echo "   failed; continuing" >&2
    rm -rf "$destination"
  fi
  echo
done

python3 "$script_dir/summarize_benchmark.py" "$output_root"