Evaluation scripts for the Open TTS Leaderboard: https://huggingface.co/spaces/hf-audio/open_tts_leaderboard
Python
add woof eval scripts (#47)
Eric Bezzam2ca2de19d64f
diff --git a/scripts/open_results_pr.py b/scripts/open_results_pr.pyindex 4294b9d..0940349 100644--- a/scripts/open_results_pr.py+++ b/scripts/open_results_pr.py@@ -409,8 +409,9 @@ def line_terminator(line):return ""-def fetch_csv(filename, hf_token):- path = hf_hub_download(RESULTS_REPO, filename, repo_type="dataset", token=hf_token)+def fetch_csv(filename, hf_token, revision=None):+ """`filename` as published on `revision` (default: main; e.g. "refs/pr/126" for an open PR)."""+ path = hf_hub_download(RESULTS_REPO, filename, repo_type="dataset", token=hf_token, revision=revision)with open(path, newline="", encoding="utf-8") as handle:return Published(handle.read())@@ -657,6 +658,13 @@ def main():parser.add_argument("--hf_token", default=os.environ.get("HF_TOKEN"), help="Defaults to $HF_TOKEN.")parser.add_argument("--open_pr", action="store_true", help="Actually open the PR (default: dry run).")parser.add_argument("--commit_message", default=None, help="PR title.")+ parser.add_argument(+ "--pr",+ type=int,+ default=None,+ help="Add to this open PR (its number) instead of opening a new one: the CSVs are read from "+ "refs/pr/<N>, so rows already in the PR are kept, and the commit is pushed to it.",+ )parser.add_argument("--out_dir",default=None,@@ -692,6 +700,8 @@ def main():if variant and not variant.startswith("_"):variant = f"_{variant}"local_dir = args.local_dir or os.path.join(REPO_ROOT, "results")+ # Files are read from (and, with --open_pr, committed to) an open PR's branch when --pr is given.+ base_revision = f"refs/pr/{args.pr}" if args.pr is not None else Nonemodel_dir = os.path.join(local_dir, model_folder)if not args.skip_sync:@@ -775,7 +785,7 @@ def main():updated = {} # filename -> new contentfor key in [k for k in TARGETS if k in selection]:target = TARGETS[key]- published = fetch_csv(target.filename, args.hf_token)+ published = fetch_csv(target.filename, args.hf_token, base_revision)header = published.headerlanguages = header_languages(header)values, unknown = collect_values(@@ -808,7 +818,7 @@ def main():updated[target.filename] = render(published, index, new_row, args.sort)if sidecars:- published = fetch_csv(STREAMING_FILE, args.hf_token)+ published = fetch_csv(STREAMING_FILE, args.hf_token, base_revision)values, notes = collect_streaming_values(published.header, sidecars)# Row-level columns shared with other flags: --model_size_b also fills 'Size (B)' here.extra = {}@@ -829,7 +839,7 @@ def main():# model_info.csv: written when metadata was passed, or to give a model its first row.if not args.skip_model_info:- published = fetch_csv(MODEL_INFO_FILE, args.hf_token)+ published = fetch_csv(MODEL_INFO_FILE, args.hf_token, base_revision)exists = published.index_of(row_name) is not None# A row published to a *_voice_clone file is a model that clones voices; fill that in# rather than leaving the column blank, unless the flag says otherwise.@@ -873,9 +883,13 @@ def main():f"Scored from `{args.bucket}` with `scripts/open_results_pr.py`.\n\n"f"Files: {', '.join(sorted(updated))}"),- create_pr=True,+ create_pr=base_revision is None,+ revision=base_revision,)- print(f"\nPR opened: {commit.pr_url}")+ if base_revision:+ print(f"\nPushed to PR #{args.pr}: {commit.commit_url}")+ else:+ print(f"\nPR opened: {commit.pr_url}")def updated_keys(updated):diff --git a/submit_ttfa_jobs.sh b/submit_ttfa_jobs.shindex 2dc26f2..fd7d3ac 100755--- a/submit_ttfa_jobs.sh+++ b/submit_ttfa_jobs.sh@@ -208,6 +208,12 @@ TTFA_TARGETS=("seamless-m4t-v2|transformers|bezzam/evals|facebook/seamless-m4t-v2-large|--language=${TTFA_LANG}""vibevoice_realtime|vibevoice_realtime|bezzam/evals-vibevoice|microsoft/VibeVoice-Realtime-0.5B|""voxcpm2|voxcpm2|bezzam/evals-voxcpm|openbmb/VoxCPM2|"+ # numpy CPU only (run_eval.py refuses a GPU device): TTFA_DEVICE=cpu bash submit_ttfa_jobs.sh woof+ # --threads=0 keeps the CPU preamble's OMP/OPENBLAS cap (the cgroup quota) instead of 1 thread.+ # Timestamps the first sentence/clause piece of Woof's own split-and-generate loop.+ "woof|woof|bezzam/evals-woof|ConwayResearch/Underdog-Woof|--voice=juno --threads=0"+ # Second voice: sidecar suffixed _mira (publish with --variant _mira).+ "woof-mira|woof|bezzam/evals-woof|ConwayResearch/Underdog-Woof|--voice=mira --threads=0"# HTTP CLIENTS of an inference server the job starts itself (see the preamble in submit_one);# --server_pid makes a dead server fail the wait immediately."voxtral-tts|voxtral-tts|bezzam/evals-voxtral|mistralai/Voxtral-4B-TTS-2603|--base_url=http://localhost:${VLLM_PORT} --server_pid=\${SERVER_PID}"@@ -221,7 +227,7 @@ if ${PHONON_SELECTED}; thenfi# Backends whose run_eval.py has no --voice_clone flag at all; passing one would be an error.-NO_CLONE_FLAG="inflect-nano inflect-v2 kokoro lfm2-audio lfm3-audio magpie-tts paradee phonon photon qwen3tts qwen3tts-fast supertonic vibevoice_realtime voxtral-tts"+NO_CLONE_FLAG="inflect-nano inflect-v2 kokoro lfm2-audio lfm3-audio magpie-tts paradee phonon photon qwen3tts qwen3tts-fast supertonic vibevoice_realtime voxtral-tts woof"# run_eval.py writes to its own output roots (outside Git, mode 0700) and names the sidecar itself,# so Phonon skips the generic run/rename/copy below; `preamble` is submit_one's CPU thread cap.diff --git a/woof/run_eval.py b/woof/run_eval.pynew file mode 100644index 0000000..420c94e--- /dev/null+++ b/woof/run_eval.py@@ -0,0 +1,195 @@+"""+TTS synthesis for the Open TTS Leaderboard (Underdog Woof backend, stage 1).++Underdog Woof (ConwayResearch/Underdog-Woof) is a 38M-parameter English TTS (22.95M speech model ++15.3M Mimi-derived audio decoder) with two built-in voices, Juno (default) and Mira. It runs on CPU+with numpy only, from one int8 weights file. The model repo is not a pip package: the Docker image+bakes it at a pinned revision and puts it on PYTHONPATH (see the Space's Dockerfile).++`Woof.__call__` normalizes the text (its own rule-based normalizer), splits it into sentences (and+long sentences into clauses), and generates each piece in turn, redrawing a piece up to 3 times if+it runs too long or stalls. The speech model keeps one KV cache for a single sequence, so there is+no batched API: rows are processed serially, as in the Kokoro and Paradee backends.++Device: numpy CPU only. `--device` must be `cpu`; on the h200 flavor the model uses that host's CPU.+`--threads` caps the BLAS thread pool (threadpoolctl); the model card benchmarks one thread.++Seeding: Woof draws its sampling noise from its own torch-compatible RNG (not np.random), seeded per+call. Every row is synthesized with `seed=args.seed`, so a row's audio depends only on its text,+and a resumed run reproduces the same audio.++Stage 2 (`transformers/transcribe.py`) fills `pred_text` with Qwen3-ASR, and stage 4+(`normalizer.eval_utils.score_results`) computes WER + RTFx (no stage 3 SIM: fixed voice).+"""++import argparse+import os+import time++import numpy as np+import soundfile as sf+from threadpoolctl import threadpool_info, threadpool_limits+from tqdm import tqdm++from underdog_woof import SR, VOICES, Woof+from underdog_woof.textsplit import split_text++from run_eval_utils import (+ add_common_args, load_done_entries, load_tts_dataset, manifest_entry, open_manifest, output_paths,+ pending_batches, print_next_steps, set_seed, warm_up, wav_rel_path, write_entry,+)++DEFAULT_VOICE = "juno" # the package default++# Model card: 22.95M speech model + 15.3M audio decoder.+MODEL_PARAMS = 38.24e6+++def _print_model_size(tts):+ """Count the weights the runtime actually holds (speech model fp32 after dequant + decoder)."""+ try:+ n = 0+ sp = tts.model.speech+ groups = [sp.layers, [sp.ce, sp.ada, sp.lat_in, sp.h_inp, sp.h_out], sp.hblocks]+ for group in groups:+ for item in group:+ for w, b in (item if isinstance(item, list) else [item]):+ n += w.size + (0 if b is None else b.size)+ n += sp.text_emb.size + sp.bos.size+ print(f"Speech model: {n / 1e6:.2f}M parameters (model card: 22.95M); "+ f"TTS model size: {MODEL_PARAMS / 1e9:.3f}B parameters (model card total incl. 15.3M decoder)")+ except Exception as e:+ print(f"Could not count parameters ({e}); model card reports {MODEL_PARAMS / 1e6:.2f}M parameters.")+++def main(args):+ if args.device != "cpu":+ # Woof has no GPU path. Refuse rather than label a CPU measurement with a GPU device.+ raise ValueError(f"Underdog Woof is numpy CPU inference only; got --device={args.device} (use cpu).")+ set_seed(args.seed)++ tts = Woof(voice=args.voice, temp=args.temp)+ print(f"Loaded Underdog Woof ({args.model_id}@{os.environ.get('WOOF_REVISION', '?')}, voice={args.voice}, "+ f"temp={args.temp}, threads={args.threads or 'unlimited'})")+ print(f"BLAS: {[(p.get('internal_api'), p.get('num_threads')) for p in threadpool_info()]}")+ _print_model_size(tts)++ def synth_one(text):+ """Synthesize one text with the package's own pipeline. Return (audio_1d_numpy, elapsed_s)."""+ start = time.perf_counter()+ audio = tts(text, seed=args.seed)+ elapsed = time.perf_counter() - start+ if audio.size == 0:+ audio = np.zeros(1, dtype=np.float32)+ return audio, elapsed++ def synth_one_streaming(text, early_stop=False):+ """TTFA probe only: Woof.__call__'s own loop (seed, normalize, split, one piece at a time),+ timestamping the first piece's audio. Returns (audio_1d_numpy, first_piece_ts, n_pieces).++ A one-sentence prompt has nothing to stream (n_pieces == 1): first audio is last audio.+ Woof's retry check needs the whole piece, so a piece is the finest unit it can hand back.+ """+ from underdog_woof.runtime import RNG++ RNG.seed(args.seed)+ if tts.norm is not None:+ text = tts.norm(text)+ pieces = split_text(text) or [text]+ first, wavs = None, []+ for piece in pieces:+ wavs.append(tts._piece(piece))+ if first is None:+ first = time.perf_counter()+ if early_stop:+ break+ return np.concatenate(wavs).astype(np.float32), first, len(pieces)++ # Layout: results/<model_safe>/{MODEL_<safe>_DATASET_<dsid>.jsonl, <dsid>/output_<id>.wav}.+ # Manifest paths are relative to model_dir so later stages resolve them wherever it is copied.+ # Both voices share one model id, so a non-default voice gets its own manifest/sidecar suffix+ # (`_mira`; publish with `open_results_pr.py --variant _mira`). Juno, the default, has none.+ mode_suffix = "" if args.voice == DEFAULT_VOICE else f"_{args.voice}"+ paths = output_paths(args, mode_suffix)+ model_dir, dataset_dir_name, manifest_path = paths.model_dir, paths.dataset_dir_name, paths.manifest_path++ dataset = load_tts_dataset(args)++ # ── TTFA probe: latency only, writing nothing but a JSON sidecar ─────────+ # Timestamps the first sentence/clause piece (see synth_one_streaming).+ # 0 = off; N > 0 = N evenly spaced samples; N < 0 = the whole split (see scripts/ttfa_probe.py).+ if args.ttfa_probe != 0:+ # Imported here: ttfa_probe.py is injected only by submit_ttfa_jobs.sh.+ from ttfa_probe import run_probe, sample_indices+ piece_counts = []++ def _ttfa_gen(job, early_stop):+ audio, first, n_pieces = synth_one_streaming(job["text"], early_stop)+ piece_counts.append(n_pieces)+ return audio, SR, first++ run_probe(+ _ttfa_gen,+ [{"text": dataset[i][args.text_column]} for i in sample_indices(args.ttfa_probe, len(dataset))],+ model_id=args.model_id, dataset_path=args.dataset_path,+ dataset_config=args.dataset, split=args.split,+ out_dir=model_dir, mode_suffix=mode_suffix, n=args.ttfa_probe,+ # segments_per_utterance == 1 means one sentence in, nothing to stream.+ extra={"device": "cpu", "runtime": "numpy", "threads": args.threads, "voice": args.voice,+ "temp": args.temp, "seed": args.seed, "revision": os.environ.get("WOOF_REVISION"),+ "segments_per_utterance": piece_counts},+ )+ return++ done_entries = load_done_entries(manifest_path, args.resume)+ manifest_file = open_manifest(manifest_path, done_entries)++ # Serial synthesis: one sample per "batch"; warm-up runs untimed on the first pending samples.+ starts = pending_batches(dataset, 1, done_entries, dataset_dir_name)+ warm_up(lambda batch: [synth_one(t) for t in batch[args.text_column]], dataset, starts, 1, args.warmup_steps)++ # ── Main loop: synthesize one sample at a time → write JSONL ─────────────+ for i in tqdm(starts, desc="Generating"):+ sample_id = dataset[i]["id"]+ text = dataset[i][args.text_column]++ # Store the path relative to model_dir (the manifest's dir); write to the full path.+ rel_path = wav_rel_path(dataset_dir_name, sample_id)+ path = os.path.join(model_dir, rel_path)++ audio, elapsed = synth_one(text)+ sf.write(path, audio, SR)++ write_entry(manifest_file, manifest_entry(rel_path, len(audio) / SR, elapsed, text))+ manifest_file.flush()++ manifest_file.close()+ print("Results saved at path:", os.path.abspath(manifest_path))+ print_next_steps(voice_clone=False)+++if __name__ == "__main__":+ parser = argparse.ArgumentParser()++ parser.add_argument("--model_id", type=str, default="ConwayResearch/Underdog-Woof",+ help="HF model id (manifest/output naming; the image pins the repo revision).")+ parser.add_argument("--voice", type=str, default=DEFAULT_VOICE, choices=VOICES,+ help="Built-in voice: juno (the package default) or mira (outputs suffixed _mira).")+ parser.add_argument("--temp", type=float, default=0.5, help="Sampling temperature (package default 0.5).")+ parser.add_argument("--threads", type=int, default=1,+ help="BLAS thread cap via threadpoolctl. Default 1, as on the model card (submit_jobs.sh passes 8); "+ "0 = leave the environment's setting (e.g. OMP_NUM_THREADS).")+ add_common_args(parser)+ parser.set_defaults(device="cpu")++ args = parser.parse_args()++ print("*" * 100)+ print(f"Generating TTS with {args.model_id} on {args.dataset_path} / {args.dataset} / {args.split}")+ print("*" * 100)++ if args.threads > 0:+ with threadpool_limits(limits=args.threads):+ main(args)+ else:+ main(args)diff --git a/woof/submit_jobs.sh b/woof/submit_jobs.shnew file mode 100755index 0000000..0fe3bd9--- /dev/null+++ b/woof/submit_jobs.sh@@ -0,0 +1,68 @@+#!/bin/bash+# HF Jobs TTS eval — Underdog Woof backend (fixed voice → generate → transcribe → utmos → score; no SIM).+# Runs locally; submits HF Jobs. Usage: HF_TOKEN=hf_... bash submit_jobs.sh ["ConwayResearch/Underdog-Woof juno" ...]+# Shared orchestration (stages 2/3, injection, logging, scoring) lives in scripts/tts_jobs_common.sh.+source "$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)/scripts/tts_jobs_common.sh"++# ── Backend config ───────────────────────────────────────────────────────────+TTS_SPACE="${TTS_SPACE:-bezzam/evals-woof}" # stage-1 image (Dockerfile in the Space: https://huggingface.co/spaces/bezzam/evals-woof/blob/main/Dockerfile)+# gen FLAVOR (h200) is set centrally in tts_jobs_common.sh for RTFx comparability — don't override.+DEFAULT_STAGES="generate transcribe utmos" # no SIM (fixed voice)+RUN_EVAL_INJECT="$(inject_run_eval)"++# ── Threads ──────────────────────────────────────────────────────────────────+# Woof is numpy-only CPU inference, so on h200 it runs on the host CPU. BLAS threads cap: RTFx+# saturates at ~8 (AMD EPYC 7742, Seed-TTS en: 1 → 3.5x, 4 → 6.1x, 8 → 6.7x, 16 → 7.3x), and 8 matches+# the cpu-upgrade flavor the CPU TTFA runs on. The model card benchmarks 1 thread (WOOF_THREADS=1).+WOOF_THREADS="${WOOF_THREADS:-8}"++# ── Voice → output suffix ────────────────────────────────────────────────────+# Both voices share the model id, so a non-default voice is a variant: MODE_SUFFIX must match the+# `_<voice>` suffix run_eval.py writes (publish with `open_results_pr.py --variant _mira`).+resolve_mode() {+ local _ VOICE+ read -r _ VOICE <<< "${MODEL_CFG}"+ CLONE="false"; VOICE_CLONE_FLAG=""+ MODE_SUFFIX=""; [[ -n "${VOICE}" && "${VOICE}" != juno ]] && MODE_SUFFIX="_${VOICE}"+ true+}++# English only (two English voices, English text normalizer).+supports_language() { [[ "$1" == "en" ]]; }++# ── Stage 1: TTS generation. MODEL_CFG = "model_id voice" (no batched API — one sample at a time) ──+generate_stage() {+ local _ VOICE+ read -r _ VOICE <<< "${MODEL_CFG}"+ hf jobs run \+ --flavor "${FLAVOR}" --timeout 8h --secrets HF_TOKEN ${NAMESPACE_ARG} \+ --volume "hf://buckets/${RESULTS_BUCKET}:/results" "${TTS_IMAGE}" \+ bash -c "+ ${RUN_EVAL_INJECT}+ cd /app/woof && python run_eval.py \+ --model_id=${MODEL_ID} \+ --voice=${VOICE:-juno} \+ --dataset_path=${DATASET_PATH} \+ --dataset=${DATASET} \+ --split=${SPLIT} \+ --device=cpu \+ --threads=${WOOF_THREADS} \+ --max_eval_samples=${MAX_EVAL_SAMPLES} &&+ mkdir -p /results &&+ cp -r results/${MODEL_SAFE} /results/+ "+}++# ── Datasets: "config split asr_language [dataset_path]" (comment/uncomment) ──+DATASET_CONFIGS=(+ "tts en en"+ "zero_shot en en ${CV3_EVAL_PATH:-hf-audio/cv3_eval}"+ "tts en en ${MINIMAX_EVAL_PATH}"+)++# ── Models: "model_id voice" (CLI args override) ─────────────────────────────+# Juno is the package default (and the faster voice); Mira is the model card's best-WER voice.+MODEL_CONFIGS=("ConwayResearch/Underdog-Woof juno")+[[ $# -gt 0 ]] && MODEL_CONFIGS=("$@")++run_pipeline