NERDDISCO's picture
kale-tts-1
f21d6eb
|
Raw History Blame Contribute Delete
10.3 kB
<!-- SPDX-License-Identifier: Apache-2.0 | Copyright 2026 Kale -->
# recipe/textside: kale-tts-1-tiny's Ettin text side
kale-tts-1-tiny does not run ALBERT. A small phoneme encoder (embedding -> 3 conv blocks -> + word features -> 2 transformer blocks ->
512-d predictor input, 3.00 M params) plus word features from the frozen Ettin encoder (jhu-clsp/ettin-encoder-17m: mean of its last two
layers, mean over a word's sub-tokens, previous sentence as left context) replace ALBERT + bert_encoder. The student is distilled from
the release teacher's own text side on text only (L1 on the predictor input, durations, pitch, loudness), with the teacher's predictor
frozen and reused, on all 10 release voices (a random voice per sentence), 20k steps. d03 / d13 sentences use en-GB ids. Pitch loss is
in semitones on voiced frames. The graph keeps the teacher's predictor, its text encoder and the t10k decoder.
## Files
- `prep_text.py`: in: text pools + held-out lines (`config/text.json`). Out: `work/sents.jsonl` ({text, prev}, deduplicated, shuffled,
bench and guard sentences held out), `work/trace.jsonl` (the volcano line, used to trace the export) and `work/check_texts.json`
(20 bench lines for the export check). From our `prep_text.py` (sentence part) + `prep_bench.py` (the trace line).
- `make_ids.mjs`: in: `{text, prev}` lines + accent. Out: the same lines plus `ids` (Kokoro ids, no pads) and `widx` (word index per
id), through the release front end (`../../frontend/words`). From our `gbids.mjs` + the word-map code of our `prep_text.py`.
- `textside.py` (Modal): `upload_entry` puts the id files on the runs volume; `train_entry` trains the student
(`<volume_dir>/<run>/stepNNNNNN.pt`, `last.pt`, `train.log`); `export_entry` writes the one-file fp32 graph
(`<volume_dir>/export/<name>/model.fp32.onnx`, `export.json`, trace inputs) and copies it to `work/<name>/`. From our `k20c.py`
(`_mods`, `_teacher` kind tiny10, `_batch`, `train`, `clamp_onnx`, `export10` with the voice_sound input) + the `export10` entry of
`k20c_cpu.py`.
- `build_q.sh`: in: `model.fp32.onnx`. Out: `A.onnx` (fp32 + exact decoder rewrites), `D-fixed.onnx`, `ettin-q.onnx` (release
precision) and `ettin-fp32.onnx` (fp32 partner). It chains the existing ../export/speedtools/harmsum.py and apply_stft.py with
prec.py, prec2.py, prune.py and ../export/toposort.py. From our `qsweep.sh` and the steps in our notes.
- `prec.py`: in: fp32 graph + `--dec/--text/--keep32/--table`. Out: D-fixed (int8 decoder, decoder text encoder fp16, rest fp32).
Copied unchanged.
- `prec2.py`: in: D-fixed + `group=mode` list + token counts. Out: per-group int8 / fp16 graph with the hybrid word table. Copied; the
tokenizer and text paths became `--counts` / `--freq-text` / `--tokenizer`.
- `prune.py`: in: graph. Out: the same graph without initializers no node reads. Copied unchanged.
- `check_items.mjs`: in: `[{id, text}]` + accent. Out: per-sentence ids + Ettin inputs (as `../../js/kale-tts.mjs` feeds them) for
`CHECK_ETTIN` of ../export/export_check.py. From our generic `ettin_items.mjs`.
- `config/textside.json`: voices, en-GB voices, teacher paths, training settings (run t10e: 20k steps, batch 64, lr 3e-4 with 1k warm-up
+ cosine to 5 %, loss weights 1, f0_log), student sizes, end clamp (tail 36 frames, 6 semitones, thr 50 Hz, min 85 Hz), export ck / name /
trace voice. `config/text.json`: pools, held-out files, 3-60 words, seed 0, 500-id cap. `config/precision.json`: the D-fixed and
ettin-q arguments. `config/ettin_token_counts.json`: the release run's Ettin token counts over its 54,919 training sentences (sets
the 8192 fp32 rows of the hybrid table).
## Run order
```
python3 -I prep_text.py # -> work/sents.jsonl, trace.jsonl, check_texts.json
node make_ids.mjs en-us work/sents.jsonl work/sents_us.jsonl
node make_ids.mjs en-gb work/sents.jsonl work/sents_gb.jsonl
node make_ids.mjs en-us work/trace.jsonl work/trace_us.jsonl # trace inputs (baked into the export image)
node make_ids.mjs en-gb work/trace.jsonl work/trace_gb.jsonl
modal run textside.py::upload_entry # -> runs volume textside/sents.jsonl, sents_gb.jsonl
modal run --detach textside.py::train_entry # 1 x H100, ~72 min; release run t10e, step 20000
modal run textside.py::export_entry # CPU -> work/t10e-20k/model.fp32.onnx (~185 MB)
zsh build_q.sh work/t10e-20k/model.fp32.onnx work/q # -> work/q/ettin-q.onnx (73.9 MB), work/q/ettin-fp32.onnx (183 MB)
python3 -I ../export/ettin_voice_clamp.py work/q/ettin-q.onnx work/q/ettin-q.vc.onnx [<model dir> ../export/end_clamp_floors.json]
python3 -I ../export/phase_float32.py work/q/ettin-q.vc.onnx <model dir>/model.onnx
python3 -I ../export/ettin_voice_clamp.py work/q/ettin-fp32.onnx work/q/ettin-fp32.vc.onnx
python3 -I ../export/phase_float32.py work/q/ettin-fp32.vc.onnx <model dir>/model.fp32.onnx
node check_items.mjs en-us work/check-us.json work/check_texts.json
node check_items.mjs en-gb work/check-gb.json work/check_texts.json
CHECK_ETTIN=work/check-us.json,work/check-gb.json python3 -I ../export/export_check.py <model dir>/model.onnx <model dir>/model.fp32.onnx <model dir> --json work/q/export-check.json
```
`<model dir>` is the release folder for kale-tts-1-tiny (`voices.json`, `voices/<id>.bin` style tables, `voices/<id>.extra.bin` =
voice_sound, from ../export's tiny build). The release ran ../export/phase_float32.py on ettin-q and on the sorted fp32 partner. The
per-voice end clamp comes from ../export/ettin_voice_clamp.py: it replaces the graph's per-sentence floor with the voice's floor (input
`voice_pitch_floor`, values in ../export/end_clamp_floors.json). Run it with the model dir arguments only once, because it appends to
each `.extra.bin`. Both scripts are used unchanged. Checked locally: from our fp32 export A, `prec.py`, `prec2.py`, `prune.py` and the
sort give byte-identical copies of D-fixed (sha256 cb3f74f2…), ettin-q (9786f9bf…, 73,899,344 bytes) and the fp32 partner (5e2bf5df…).
## Inputs from earlier steps
- `../teacher` (teacher volume, `/t`): `export/teacher/teacher.pth` (ALBERT, bert_encoder, predictor, text encoder) and
`export/teacher/packs/<voice>.pt` (voice packs, 510x1x256) for the 10 voices.
- `../train` (runs volume, `/data`): `run/t10d2/kdur/step01500.pt` (duration head), `run/t10p/kpros/step01000.pt` (pitch/loudness heads +
per-voice offsets `pv`, added to each pack's prosody half) and `run/t10k/kdec/last.pt` (tiny decoder). Also the code: `kline.py`,
`model.py`, `onnx_export.py` and `third_party/paradee`, which are added to the image.
- `../render`: the text pools `work/jobs-v7.jsonl` and `work/singles.jsonl` (`text` field); `../bench`: `script.jsonl` and
`config/bench.json` (`guard_lines`) for the held-out lines and the trace line. No audio: this step trains on text only.
- `../../frontend` (release front end) and `../../models/kale-tts-1-tiny/` (`ettin-tokenizer.json`, `tokenizer.json`).
- `../config/modal.json`: `textside_app`, `runs_volume`, `teacher_volume`.
## Third-party parts
- Ettin encoder (jhu-clsp/ettin-encoder-17m, MIT): the weights are downloaded into the image at build time (`config/textside.json`
`ettin_model`) and are frozen in training. The graph embeds them, so the release files carry MIT-licensed weights. Its tokenizer
(byte-level BPE, MIT) ships as `../../models/kale-tts-1-tiny/ettin-tokenizer.json` and runs in `../../frontend/ettin.js` and in
transformers (Apache-2.0) during training and export.
- Kokoro-82M / kokoro (Apache-2.0, hexgrad): the teacher text side, loaded through `../train/kline.py`. paradee portions (Apache-2.0)
in `../train/onnx_export.py` (`strip`, `HeadX`). StyleTTS2 lineage (MIT). All of them are imported, not copied here.
- Every file in this folder is our code (Apache-2.0).
## What was trimmed from the research code
- Teachers and arms that did not make the release are gone: teachers of other model lines, the 8-voice port, the nano student (an Ettin nano
added size and no speed), EttinLite, the no-Ettin arm, unfreezing the predictor (the release kept it frozen, and the export never
loaded a predictor from the checkpoint), the per-voice graphs with int8-decoder / int8-lookup copies, and the ALBERT baseline graph.
- The bench render function (torch, CPU, used to compare checkpoints) and the native-runner manifest of the trace inputs are gone. The
`.bin` files + `raw_inputs.json` stay.
- Volumes went from six to two (runs + teacher), with paths from `config/textside.json`. Logs are stamped in UTC.
- Ids: our run made en-US ids with an earlier Python copy of the same lexicon + g2p, and en-GB ids with an earlier copy of the British
front end. `make_ids.mjs` uses the release front end with the public override lists. Spot check on 2,000 of our sentences: en-US ids
identical on 98.2 % (word index 99.3 %), en-GB 99.95 % (word index 100 %). The volcano trace line is identical.
## Known gaps
- Text: our 54,919 sentences came from research text pools of our Maya renders, which are not shipped. `prep_text.py` on
../render's pool gives a similar set, not the same one. The held-out split (seed 1, 256 sentences) and the random voice draws then
differ too. The shipped token counts keep the hybrid table's 8192 rows exactly as released. To count over your own sentences, use
`prec2.py --freq-text work/sents_us.jsonl --tokenizer ../../models/kale-tts-1-tiny/ettin-tokenizer.json` instead of `--counts`.
- Ettin weights: pinned to jhu-clsp/ettin-encoder-17m @ 987607455c61e7a5bbc85f7758e0512ea6d0ae4c (`ettin_revision`). Our run used the
default branch without a pin; that commit's weights file matches the release graph bit for bit on every encoder tensor.
- Distilled text sides swing from checkpoint to checkpoint while the loss falls smoothly. The release is step 20000, chosen on the
bench over the 5k and 10k checkpoints. Pick by the bench, not by the loss. Our per-checkpoint renders came from a torch render
function that is not included; ../bench renders release graphs.
- The export check needs `check_items.mjs` (a node that imports `.ts` files, >= 23.6, for the terms table) and the release model dir. The Whisper
part is ../export/whisper_check.py.