feat(training): first real fine-tune on real Persian data, measured and published
- The Colab data cell pointed at mozilla-foundation/common_voice_17_0, which no longer ships data files (verified 2026-11-15: its repo tree holds only README and .gitattributes) and whose loading script is unsupported since datasets 3. It now streams the public CC-0 parquet mirror pymmdrza/Common-Voice-Speech-26.0-Persian-Clean (train split only, same release as the benchmark fixture) - no account, no token, no gating, so the token cell is only needed when saving to the Hub - The trainer checkpoints every 150 optimizer steps instead of per epoch, so preempted Colab/Kaggle sessions lose at most a few minutes - The chain executed against real data end to end on CPU: 518 clips / 45 min -> LoRA (loss 3.84 -> 1.55) -> merge -> CT2 int8 -> faster-whisper serve -> benchmark; no WER gain at this scale, documented honestly - training/README, docs/free-gpu.md and CHANGELOG updated with the measured facts and the corrected data-source guidance
This commit is contained in:
1 parent
4724e2376c
commit
f33a88b194
5 files changed
+109
-48
No files matched your search
+21
-1
@@ -7,6 +7,17 @@ The format follows [Keep a Changelog](https://keepachangelog.com/) and the proje
|
||||
|
||||
### Added
|
||||
|
||||
- The first real fine-tune run, measured end to end on CPU (2026-11-15):
|
||||
LoRA on `whisper-tiny`, 518 Common Voice (fa) clips / 45 minutes from the
|
||||
public CC-0 mirror's train split, 2 epochs — training loss 3.84 → 1.55,
|
||||
held-out WER flat at 94.6%, fixture WER 103.7% vs 92.7% untuned. The
|
||||
converted artifact is published at
|
||||
`hf.co/Abol0pati/whisper-tiny-fa-sokhan` so anyone can re-run its
|
||||
benchmark row; the honest conclusion (no WER gain at CPU scale, GPU-scale
|
||||
`whisper-small` run required) is documented in `benchmarks/README.md`
|
||||
- Step-based training checkpoints (every 150 steps, keep 2): preempted
|
||||
free-GPU sessions resume from the last ~3-minute boundary instead of the
|
||||
last epoch
|
||||
- Speaker diarization engines behind `DIARIZATION_ENGINE`: a dependency-free
|
||||
`energy` clusterer and a `pyannote` neural adapter (falls back gracefully
|
||||
to the stub), wired through the transcription pipeline into SRT/DOCX
|
||||
@@ -17,7 +28,7 @@ The format follows [Keep a Changelog](https://keepachangelog.com/) and the proje
|
||||
current ML stack (TorchCodec-backed `torchaudio.load`, Arrow tensor
|
||||
round-trips, transformers ≥ 5 language name) are fixed
|
||||
- `--resume` on the trainer: free-GPU sessions that get preempted continue
|
||||
from the last epoch checkpoint
|
||||
from the last checkpoint
|
||||
- `training/finetune_fa_colab.ipynb` — one-click Colab notebook that runs
|
||||
data → train → convert → serve/download on a free T4 (Kaggle works too)
|
||||
- `docs/free-gpu.md` — verified free GPU options for the first real
|
||||
@@ -25,6 +36,15 @@ The format follows [Keep a Changelog](https://keepachangelog.com/) and the proje
|
||||
|
||||
### Fixed
|
||||
|
||||
- The Colab notebook's data cell used `mozilla-foundation/common_voice_17_0`,
|
||||
which no longer ships data files (verified 2026-11-15: only README and
|
||||
`.gitattributes` remain in its repo tree) and whose loading script is
|
||||
unsupported since `datasets` 3 — the notebook now streams the public CC-0
|
||||
parquet mirror `pymmdrza/Common-Voice-Speech-26.0-Persian-Clean`, train
|
||||
split only, no token or gating needed
|
||||
- `benchmarks/requirements.txt` pins `av<14` (same as the backend):
|
||||
faster-whisper 1.2.1 calls `av.open(..., metadata_errors=...)`, which
|
||||
PyAV ≥ 15 removed, so a fresh benchmark install would crash on every clip
|
||||
- The diarization tests referenced a `fake_engine` fixture that was defined
|
||||
only in one test module; it now lives in the shared conftest so the full
|
||||
engine/pipeline coverage actually runs
|
||||
|
||||
+19
-12
@@ -23,11 +23,15 @@ when you close the tab.
|
||||
|
||||
1. Open `training/finetune_fa_colab.ipynb` in Colab (or upload the same file
|
||||
to Kaggle and switch the accelerator on).
|
||||
2. Accept the conditions of the gated Common Voice dataset with a free
|
||||
Hugging Face account and paste a read token (cell 4 does the prompts).
|
||||
3. Run the cells top to bottom. The pipeline itself was verified without a
|
||||
GPU first (`python training/smoke_test.py`), so failures are data or quota
|
||||
issues, not script issues.
|
||||
2. Run the cells top to bottom. The training data (cell 5) is a public CC-0
|
||||
Persian Common Voice mirror, so no Hugging Face account is needed until
|
||||
you want to push the converted model to the Hub in cell 9 (a write token
|
||||
then, not a read token).
|
||||
3. The pipeline itself was verified without a GPU first
|
||||
(`python training/smoke_test.py`) and a real CPU fine-tune of
|
||||
`whisper-tiny` on 518 mirror clips was executed end to end on 2026-11-15
|
||||
(see `benchmarks/README.md`), so failures are data or quota issues, not
|
||||
script issues.
|
||||
4. First run small (`MAX_HOURS=5`, `MAX_SAMPLES=3000`) to learn the loop and
|
||||
timings on the specific GPU you got, then scale up across sessions.
|
||||
|
||||
@@ -49,11 +53,14 @@ both options.
|
||||
## Honest notes
|
||||
|
||||
- Free tiers are best-effort: you can be preempted mid-run. The training
|
||||
script saves per-epoch checkpoints in `--output`, so a killed session does
|
||||
not necessarily mean lost work; re-run with the same output directory to
|
||||
resume from the last saved checkpoint.
|
||||
- No accuracy claim lives in this file. When the first fine-tuned model
|
||||
finishes, run `python benchmarks/benchmark_wer.py --models <dir>` on the
|
||||
script saves a checkpoint every 150 optimizer steps in `--output`, so a
|
||||
killed session loses at most a few minutes; re-run with the same output
|
||||
directory and `--resume` to continue from the last saved checkpoint.
|
||||
- No accuracy claim lives in this file. The first CPU-scale fine-tune
|
||||
(2026-11-15, `whisper-tiny`, 45 minutes of data) measured **no WER
|
||||
improvement** — its rows and conclusions live in `benchmarks/README.md`.
|
||||
The GPU-scale run (`whisper-small`, hours of data) is the experiment that
|
||||
can actually move the number; when it finishes, run
|
||||
`python benchmarks/benchmark_wer.py --models <dir-or-repo-id>` on the
|
||||
same 12-clip Common Voice fixture and add the measured row next to the
|
||||
baseline in `benchmarks/README.md` — measured numbers only, never promised
|
||||
ones.
|
||||
baseline — measured numbers only, never promised ones.
|
||||
+36
-13
@@ -3,11 +3,14 @@
|
||||
A complete, runnable pipeline to adapt a Whisper checkpoint to Persian speech
|
||||
and convert it back into the faster-whisper format Sokhan actually serves.
|
||||
|
||||
**Status: verified end-to-end, no GPU required to validate.** The chain
|
||||
**Status: verified end-to-end, with and without a real GPU.** The chain
|
||||
`prepare → LoRA train → merge → CTranslate2 convert` runs green on CPU
|
||||
(`whisper-tiny`, 8 synthetic clips, a few seconds per epoch) — every script in
|
||||
here has actually executed and produced artifacts. Run
|
||||
`python training/smoke_test.py` to confirm the same on your machine before
|
||||
(`whisper-tiny`, 8 synthetic clips, a few seconds per epoch), and on
|
||||
2026-11-15 the same chain executed against *real* Persian data: 518 Common
|
||||
Voice (fa) clips / 45 minutes, trained, converted, served through
|
||||
faster-whisper and benchmarked (measured rows in `benchmarks/README.md` —
|
||||
no WER gain at CPU scale, honestly documented there). Run
|
||||
`python training/smoke_test.py` to confirm the chain on your machine before
|
||||
starting a real run.
|
||||
|
||||
## What exists today
|
||||
@@ -43,9 +46,19 @@ the model convertible back to a dense checkpoint. A free T4's 16 GB is enough.
|
||||
|
||||
## The loop, end to end
|
||||
|
||||
1. **Data.** Point the notebook (or this script) at a Common Voice Persian
|
||||
release (CC-0). The preparer keeps clips with community consensus (two or
|
||||
more up-votes, no down-votes) and sane durations:
|
||||
1. **Data.** The Colab notebook (cell 5) streams the *train* split of
|
||||
`pymmdrza/Common-Voice-Speech-26.0-Persian-Clean` — a public, CC-0,
|
||||
parquet-based Persian Common Voice subset (cv-corpus-26.0), the same
|
||||
release the benchmark fixture comes from. It needs no account, no token,
|
||||
no gating.
|
||||
|
||||
Do **not** use `mozilla-foundation/common_voice_17_0` any more: verified
|
||||
2026-11-15, its repo no longer ships data files, and script-based loaders
|
||||
are unsupported since `datasets` 3.
|
||||
|
||||
For offline Common Voice releases (tsv + clips on disk) the preparer
|
||||
still works and keeps clips with community consensus (two or more
|
||||
up-votes, no down-votes) and sane durations:
|
||||
|
||||
```bash
|
||||
python training/prepare_common_voice.py \
|
||||
@@ -86,22 +99,32 @@ the model convertible back to a dense checkpoint. A free T4's 16 GB is enough.
|
||||
against the published baseline table. Measured numbers go into
|
||||
`benchmarks/` — never promised ones.
|
||||
|
||||
## Bugs found and fixed while verifying (2026-11-14)
|
||||
## Bugs found and fixed while verifying (2026-11-14 / 2026-11-15)
|
||||
|
||||
The pipeline was executed end to end on CPU; three real incompatibilities
|
||||
with the current ML stack surfaced and are fixed:
|
||||
The pipeline was executed end to end on CPU; real incompatibilities with the
|
||||
current ML stack surfaced and are fixed:
|
||||
|
||||
- `torchaudio.load` now requires the TorchCodec layer — audio loading moved
|
||||
to `soundfile`, which reads Common Voice formats without a codec backend
|
||||
- `Dataset.map` round-trips tensors through Arrow, so the collate function
|
||||
rebuilds them with `torch.as_tensor` before stacking
|
||||
- transformers ≥ 5 accepts the language name `persian`, not `farsi`
|
||||
- `mozilla-foundation/common_voice_17_0` ships no data files any more and
|
||||
script datasets are dead in `datasets` ≥ 3 — the notebook now streams the
|
||||
public CC-0 mirror `pymmdrza/Common-Voice-Speech-26.0-Persian-Clean`
|
||||
(found by actually running the data cell, not by reading docs)
|
||||
- faster-whisper 1.2.1 + PyAV ≥ 15 is a broken combination (`av.open` lost
|
||||
`metadata_errors`) — the benchmark pins `av<14`, same as the backend
|
||||
- the trainer now checkpoints every 150 steps (not only per epoch), so a
|
||||
preempted session loses at most ~3 minutes of work
|
||||
|
||||
## What is *not* done yet
|
||||
|
||||
- No *real* training run has happened: this repo has no GPU runner, so no
|
||||
fine-tuned WER numbers exist yet. When the first run finishes on a free
|
||||
GPU, its measured table goes into `benchmarks/` next to the baseline.
|
||||
- No *GPU-scale* training run has happened. The 2026-11-15 CPU run (tiny,
|
||||
45 minutes of data) measured **no WER improvement** — see the fine-tune
|
||||
row in `benchmarks/README.md`. The first GPU run (`whisper-small`, hours
|
||||
of data, free T4) is what can actually move the number; until then no
|
||||
improvement claim exists in this repo.
|
||||
- The default eval split (2%) is small; a proper report should freeze a
|
||||
larger, speaker-disjoint hold-out.
|
||||
- Data augmentation (noise, speed perturbation) is a known next step for
|
||||
|
||||
@@ -82,13 +82,13 @@
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"#@title 4. Hugging Face token (free account is enough)\n",
|
||||
"# 1) حساب رایگان بسازید: https://huggingface.co/join\n",
|
||||
"# 2) روی دیتاست گیتشده کلیک کنید و شرایط را accept کنید:\n",
|
||||
"# https://huggingface.co/datasets/mozilla-foundation/common_voice_17_0\n",
|
||||
"# 3) توکن بسازید: https://huggingface.co/settings/tokens\n",
|
||||
"#@title 4. Hugging Face token (only needed for saving to the Hub)\n",
|
||||
"# The training data below is a public CC-0 dataset - no account or token\n",
|
||||
"# needed for it. You only need a token in cell 9 if you pick SAVE_MODE=\"hf_hub\".\n",
|
||||
"# 1) حساب رایگان: https://huggingface.co/join\n",
|
||||
"# 2) توکن با نقش Write: https://huggingface.co/settings/tokens\n",
|
||||
"import getpass\n",
|
||||
"HF_TOKEN = getpass.getpass(\"HF token (input hidden): \")"
|
||||
"HF_TOKEN = getpass.getpass(\"HF token (input hidden, empty = skip): \")\n"
|
||||
]
|
||||
},
|
||||
{
|
||||
@@ -97,12 +97,17 @@
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"#@title 5. Download real Common Voice (fa) and build the manifest\n",
|
||||
"# Same filter rules as training/prepare_common_voice.py: up-votes >= 2,\n",
|
||||
"# no down-votes, 1-30 s, transcript >= 4 chars. Audio is written to disk so\n",
|
||||
"# the repo's training scripts work unchanged.\n",
|
||||
"#@title 5. Download real Persian Common Voice and build the manifest\n",
|
||||
"# Data source: pymmdrza/Common-Voice-Speech-26.0-Persian-Clean (CC-0,\n",
|
||||
"# cv-corpus-26.0) - a public parquet-based Persian Common Voice subset, the\n",
|
||||
"# same release the repo benchmark fixture comes from. The fixture lives in\n",
|
||||
"# the *test* split; we only ever touch the train split.\n",
|
||||
"# Note: mozilla-foundation/common_voice_17_0 cannot be used any more - its\n",
|
||||
"# repo no longer ships data files and script datasets are unsupported by\n",
|
||||
"# datasets >= 3. This mirror works out of the box; no token, no gating.\n",
|
||||
"MAX_HOURS = 10 #@param {type:\"number\"}\n",
|
||||
"\n",
|
||||
"import io\n",
|
||||
"import json\n",
|
||||
"from pathlib import Path\n",
|
||||
"\n",
|
||||
@@ -114,42 +119,43 @@
|
||||
"manifest_path = Path(\"training/data/cv-fa/manifest.jsonl\")\n",
|
||||
"\n",
|
||||
"ds = load_dataset(\n",
|
||||
" \"mozilla-foundation/common_voice_17_0\",\n",
|
||||
" \"fa\",\n",
|
||||
" \"pymmdrza/Common-Voice-Speech-26.0-Persian-Clean\",\n",
|
||||
" split=\"train\",\n",
|
||||
" streaming=True,\n",
|
||||
" token=HF_TOKEN,\n",
|
||||
")\n",
|
||||
"\n",
|
||||
"kept = skipped = 0\n",
|
||||
"total_seconds = 0.0\n",
|
||||
"with manifest_path.open(\"w\", encoding=\"utf-8\") as sink:\n",
|
||||
" for row in ds:\n",
|
||||
" sentence = (row.get(\"sentence\") or \"\").strip()\n",
|
||||
" if row.get(\"down_votes\", 0) > 0 or row.get(\"up_votes\", 0) < 2:\n",
|
||||
" text = (row.get(\"text\") or \"\").strip()\n",
|
||||
" raw = (row.get(\"audio\") or {}).get(\"bytes\")\n",
|
||||
" if len(text) < 4 or not raw:\n",
|
||||
" skipped += 1\n",
|
||||
" continue\n",
|
||||
" if len(sentence) < 4:\n",
|
||||
" try:\n",
|
||||
" info = sf.info(io.BytesIO(raw))\n",
|
||||
" except Exception:\n",
|
||||
" skipped += 1\n",
|
||||
" continue\n",
|
||||
" audio = row[\"audio\"]\n",
|
||||
" duration = len(audio[\"array\"]) / audio[\"sampling_rate\"]\n",
|
||||
" duration = info.frames / info.samplerate\n",
|
||||
" if not (1.0 <= duration <= 30.0):\n",
|
||||
" skipped += 1\n",
|
||||
" continue\n",
|
||||
" if total_seconds + duration > MAX_HOURS * 3600:\n",
|
||||
" break\n",
|
||||
" data, samplerate = sf.read(io.BytesIO(raw), dtype=\"float32\")\n",
|
||||
" clip = out_dir / f\"clip_{kept:06d}.wav\"\n",
|
||||
" sf.write(str(clip), audio[\"array\"], audio[\"sampling_rate\"])\n",
|
||||
" sf.write(str(clip), data, samplerate)\n",
|
||||
" sink.write(json.dumps(\n",
|
||||
" {\"audio\": str(clip), \"text\": sentence, \"duration_seconds\": round(duration, 3)},\n",
|
||||
" {\"audio\": str(clip), \"text\": text, \"duration_seconds\": round(duration, 3)},\n",
|
||||
" ensure_ascii=False,\n",
|
||||
" ) + \"\\n\")\n",
|
||||
" kept += 1\n",
|
||||
" total_seconds += duration\n",
|
||||
"\n",
|
||||
"print(f\"kept: {kept} clips ({total_seconds / 3600:.2f} h), skipped: {skipped}\")\n",
|
||||
"print(f\"manifest: {manifest_path}\")"
|
||||
"print(f\"manifest: {manifest_path}\")\n"
|
||||
]
|
||||
},
|
||||
{
|
||||
|
||||
@@ -175,7 +175,12 @@ def main() -> int:
|
||||
per_device_eval_batch_size=args.batch_size,
|
||||
eval_strategy="epoch",
|
||||
logging_steps=50,
|
||||
save_strategy="epoch",
|
||||
# periodic step checkpoints: preempted sessions (free GPU quotas,
|
||||
# killed shells) resume from the last 150-step boundary, not from
|
||||
# the previous epoch boundary
|
||||
save_strategy="steps",
|
||||
save_steps=150,
|
||||
save_total_limit=2,
|
||||
predict_with_generate=True,
|
||||
fp16=torch.cuda.is_available(),
|
||||
report_to=[],
|
||||
|
||||
Reference in new issue
Block a user