# Training From Scratch Guide Full end-to-end training pipeline to train **Lua Nova V1** from raw audio and text without relying on any pre-trained Lua Nova V1 acoustic weights. --- ## Recommended Hardware & Dataset Size - **Dataset:** `6–10+ hours` (`~5,000–8,000` clean 24 kHz mono utterances, e.g., multi-thousand sentence single-speaker studio corpus). - **Hardware:** NVIDIA GPU with `>= 8 GB` VRAM (`RTX 3070 / 4070` or better; peak VRAM during Option B vocoder FT is `6.76 GB`), `16+ GB` system RAM, `~15 GB` free disk for feature tensors and HF caches. - **Total Wall Time (RTX 4070 reference):** `~2 hours` across all stages. --- ## Stage 0 — Acoustic Features & CTC Forced Alignment Ensure `train.jsonl` and `validation.jsonl` share **zero texts or IDs**. Audio files must be `24,000 Hz` mono WAV. ```bash uv run lua-nova-prepare --inputs data/raw/train.jsonl --split train --output data/features uv run lua-nova-prepare --inputs data/raw/validation.jsonl --split validation --output data/features uv run lua-nova-annotate \ --features data/features \ --output data/annotations \ --dataset-revision ptbr-scratch-v1 \ --device cuda \ --refine 2 --stage refined-2 ``` For multi-speaker datasets, provide a `--config my_config.json` defining `"speakers": ["F1", "M1", ...]` to both `lua-nova-prepare`, `lua-nova-annotate`, and `lua-nova-train-stage1`. --- ## Stage 1 — Phonetic Front End & Baseline (`lua-nova-train-stage1`) Trains the 4-layer RoPE phonetic encoder, duration/pause predictors, prosody predictor, and 5-layer acoustic stack (`SourceFilter` head is used only to bootstrap strong encoder/prosody representations cleanly without BigVGAN backprop): ```bash uv run lua-nova-train-stage1 \ --train data/annotations/train.jsonl \ --validation data/annotations/validation.jsonl \ --output runs/stage1 \ --steps 40000 \ --batch-frames 9000 --max-batch 32 \ --learning-rate 3e-4 --warmup 1000 \ --save-every 5000 --keep-every 10000 --device cuda ``` --- ## Stage 2 — Linguistic Context & ProsodyFlow (`lua-nova-train-prosody`) Freezes encoder/acoustic modules and trains the 26-channel `LinguisticContextAdapter`, 4-step `DurationFlow`, and 4-step multiscale `ProsodyFlow`: ```bash uv run lua-nova-train-prosody \ --train data/annotations/train.jsonl \ --validation data/annotations/validation.jsonl \ --init-stage1 runs/stage1/inference.pt \ --output runs/prosody_flow \ --steps 12000 \ --learning-rate 2e-4 --warmup 600 \ --eval-every 2000 --save-every 3000 --sample-every 0 --device cuda ``` --- ## Stage 3 — OT-CFM v5 in Slaney-100 Mel Space (`lua-nova-train-cfm`) Precomputes exact `BigVGAN` Slaney 100-band log-mels in RAM (leaving disk feature files untouched) and trains the 8-layer `FlowDecoder` (`d=320`) with CFG dropout and temporal/spectral derivative losses: ```bash uv run lua-nova-train-cfm \ --train data/annotations/train.jsonl \ --validation data/annotations/validation.jsonl \ --init-cfm runs/prosody_flow/inference_item3.pt \ --output runs/cfm_v5 \ --steps 25000 \ --batch-frames 6000 --max-batch 24 \ --lr 3e-4 --min-lr 1.5e-5 --warmup 500 \ --save-every 5000 --val-every 1000 --device cuda ``` --- ## Stage 4 — Option A: E2E Polish Through Frozen BigVGAN + NVIDIA MIT Discriminators Unrolls 4 ODE steps with `sway_coef=-0.5` through frozen `nvidia/bigvgan_base_24khz_100band` and frozen NVIDIA 5M-step pretrained `MPD`/`MRD` critics (`bigvgan_discriminator_optimizer.pt`), then averages 50/50 with Stage 3 weights: ```bash uv run lua-nova-train-e2e \ --train data/annotations/train.jsonl \ --validation data/annotations/validation.jsonl \ --init-v5 runs/cfm_v5/inference_v5_ema.pt \ --output runs/cfm_v5_e2e \ --steps 2000 --save-steps 1000 1500 2000 \ --batch-size 4 --grad-accum 3 --crop-frames 40 \ --lr 4e-5 --min-lr 4e-6 --device cuda ``` Create the 50/50 weight soup (`1500` steps gave the best trade-off between perceptual cleanliness and spectral sharpness): ```python from lua_nova_v1.utils import soup_checkpoints soup_checkpoints( "runs/cfm_v5/inference_v5_ema.pt", "runs/cfm_v5_e2e/inference_v5_e2e_step-001500.pt", "runs/cfm_v5_e2e/inference_v5_soup50.pt", alpha=0.5, ) ``` --- ## Stage 5 — Option B: Gentle Vocoder Adaptation (`lua-nova-train-vocoder`) Fine-tunes `nvidia/bigvgan_base_24khz_100band` for 2,000 steps using **pretrained NVIDIA MPD/MRD discriminators** (`--pretrained-disc --disc-warmup 0`) on 60% Stage-4 predicted mels + 40% ground-truth mels: ```bash uv run lua-nova-train-vocoder \ --train data/annotations/train.jsonl \ --validation data/annotations/validation.jsonl \ --cfm-ckpt runs/cfm_v5_e2e/inference_v5_soup50.pt \ --cfm-steps 8 --cfm-temp 0.35 --sway-coef -0.5 \ --model-id nvidia/bigvgan_base_24khz_100band \ --pretrained-disc --disc-warmup 0 \ --output runs/bigvgan_base_optB \ --steps 2000 --save-steps 500 1000 1500 2000 \ --batch-size 6 --grad-accum 2 --crop-frames 32 --cfm-prob 0.60 \ --lr-g 1e-5 --min-lr-g 1e-6 --warmup-g 100 \ --lr-d 1e-5 --lr-d-post 1e-5 --min-lr-d 1e-6 \ --val-every 250 --log-every 10 --device cuda ``` > If adapting `nvidia/bigvgan_24khz_100band` (`112M` params) on `8–12 GB` VRAM GPUs, add `--ema-on-cpu --batch-size 2 --grad-accum 6 --lr-g 5e-6 --lr-d 5e-6`.