Download code/docs/OPTIMIZATION.md from oProfM/LuaNovaV1: direct link, hf CLI and curl.
- Browser
- Download file 6.03 kB
-
https://huggingface.co/oProfM/LuaNovaV1/resolve/main/code/docs/OPTIMIZATION.md
- Command line
-
hf download hf://oProfM/LuaNovaV1/code/docs/OPTIMIZATION.md
-
curl -L -o OPTIMIZATION.md https://huggingface.co/oProfM/LuaNovaV1/resolve/main/code/docs/OPTIMIZATION.md
CPU & Latency Optimization Guide (v1.1.0)
Lua Nova V1 v1.1 adds three production optimizations on top of the baseline CFM v5 Option A+B + BigVGAN-base FT stack (~35.8M active parameters):
- Trajectory Distillation (
8-step Sway Midpoint -> 2-step Euler) vialua-nova-train-distill - Split ONNX Runtime CPU Export (opset 17) via
lua-nova-export-onnxandOnnxSynthesizer - Overlap-Crossfaded Chunked Streaming (
Synthesizer.speak_stream/OnnxSynthesizer.speak_stream)
1. Benchmark Results (Before vs. After)
Measured across 5 representative PT-BR sentences totaling 24.5 s of 24 kHz audio (warmup excluded; desktop 6 physical / 12 logical CPU cores + RTX 4070 GPU) and audited on the frozen tts-eval v1.0.0 suite (30 held-out studio sentences + 36 PT-BR stress sentences).
Latency & Throughput
| Runtime & Configuration | Audio / Wall (avg per utt) | Speed (RT ↑) | Streaming TTFA (avg) | Model Footprint |
|---|---|---|---|---|
PyTorch CPU — Baseline (8p Sway Midpoint) |
3,213 ms | 1.53× |
3,213 ms | 188.8 MB (135.1 + 53.7) |
PyTorch CPU — Distilled (2p Euler) |
2,337 ms | 2.10× |
2,337 ms | 136.9 MB (83.2 + 53.7) |
PyTorch CPU — Streaming (2p Euler, chunk=24) |
2,610 ms | 1.88× |
465.3 ms |
136.9 MB (83.2 + 53.7) |
ONNX CPU (6 threads) — Baseline (8p Sway Midpoint) |
4,223 ms | 1.16× |
4,223 ms | 145.0 MB (90.3 + 54.7) |
ONNX CPU (6 threads) — Distilled (2p Euler) |
3,469 ms | 1.41× |
3,469 ms | 141.0 MB (86.3 + 54.7) |
ONNX CPU (6 threads) — Streaming (2p Euler, chunk=24) |
5,166 ms | 0.95× |
554.9 ms |
141.0 MB (86.3 + 54.7) |
PyTorch GPU — Baseline (8p Sway Midpoint) |
535 ms | 9.10× |
535 ms | — |
PyTorch GPU — Distilled (2p Euler) |
437 ms | 11.13× |
437 ms | — |
Runtime selection tip: On x86 CPUs, PyTorch (
oneDNN/ MKL-DNN) executesBigVGAN's grouped dilated 1D convolutions andSnakeBetaactivations faster than ONNX Runtime CPU (2.10× RT/465 msTTFA vs.1.41× RT/555 msTTFA), whereas ONNX Runtime removes the PyTorch runtime dependency for C++/Go/Rust or edge hosts and still achieves555 msfirst-audio latency in streaming mode. If physical core count isP, passing--threads Pavoids Hyper-Threading contention.
Frozen tts-eval v1.0.0 Quality Preservation
| Model Variant | Held-out (30) | Nat | Anti-Rob | SCOREQ ↑ | Stress PT-BR (36) | WER ↓ | Phonetic CER ↓ |
|---|---|---|---|---|---|---|---|
Human Studio Reference (24 kHz) |
88.1 | 95.1 | 77.8 | 3.77 | — | — | — |
v1.0.0 Baseline (8p Sway Midpoint) |
83.9 | 91.6 | 59.1 | 3.74 | 85.0 | 1.85% | 0.28% |
v1.1.0 Distilled (2p Euler, 3k steps) |
85.2 | 91.0 | 64.4 | 3.74 | 84.8 | 1.67% | 0.23% |
Cutting the ODE solver from 16 FlowDecoder evaluations (8 Midpoint steps) down to 2 Euler evaluations preserves and even improves held-out naturalness stability and lowers stress-suite transcription error rate (1.67% WER).
2. How to Run Each Optimization
A. Distill an 8-step Sway Midpoint Model to 2-step Euler
Only flow (14.3M params) is trained while the phonetic encoder, duration flow, prosody flow, and prior head remain frozen, matching the inference noise scale (teacher_temp=0.35):
lua-nova-train-distill \
--train data/annotations/train.jsonl \
--validation data/annotations/validation.jsonl \
--teacher runs/cfm_v5_e2e/inference_v5_soup50.pt \
--output runs/cfm_v5_fast2 \
--steps 3000 \
--teacher-steps 8 \
--teacher-sway -0.5 \
--teacher-temp 0.35 \
--student-steps 2 \
--lr 1e-4 \
--save-every 3000
Synthesize with the distilled checkpoint in PyTorch:
lua-nova-speak \
--cfm runs/cfm_v5_fast2/inference_v5_fast2_step-003000.pt \
--vocoder runs/bigvgan_base_optB/bigvgan_ft_step-002000.pt \
--steps 2 --solver euler --sway-coef 0.0 --temperature 0.35 \
--text "Olá! A destilação reduziu a geração para dois passos Euler." \
--out fast2.wav --stream --chunk-frames 24
B. Export Split ONNX Graphs (opset 17)
Lua Nova V1 exports two composable ONNX graphs so clients can reuse the same vocoder across acoustic checkpoints or decode mel chunks for streaming:
cfm_v5_fast2.onnx:("tokens", "stress", "voice", "speed", "pitch_shift", "pitch_range") -> ("phys_mel", "frame_lengths")plus<stem>.meta.jsonbigvgan_base_ft.onnx:("mel",) -> ("audio",)with dynamicframesaxis ([1, T, 100] -> [1, T*256]) and folded alias-free resampling weights
lua-nova-export-onnx \
--cfm runs/cfm_v5_fast2/inference_v5_fast2_step-003000.pt \
--vocoder runs/bigvgan_base_optB/bigvgan_ft_step-002000.pt \
--out-dir runs/onnx_v5 \
--cfm-name cfm_v5_fast2.onnx \
--vocoder-name bigvgan_base_ft.onnx \
--steps 2 --solver euler --sway-coef 0.0 --temperature 0.35 --verify
C. Streaming Python & CLI Inference
import numpy as np
from lua_nova_v1 import OnnxSynthesizer
synth = OnnxSynthesizer("runs/onnx_v5/cfm_v5_fast2.onnx", "runs/onnx_v5/bigvgan_base_ft.onnx")
chunks = list(synth.speak_stream("Primeira frase curta. Segunda frase longa com pausas.", chunk_frames=24))
wav = np.concatenate(chunks)
synth.save_wav("streamed.wav", wav)
Or via CLI:
lua-nova-speak \
--onnx-cfm runs/onnx_v5/cfm_v5_fast2.onnx \
--onnx-vocoder runs/onnx_v5/bigvgan_base_ft.onnx \
--text "Síntese em CPU sem PyTorch e com streaming por chunks." \
--out onnx_stream.wav --stream --chunk-frames 24
Chunk seams use symmetric context_frames=8 receptive-field overlap during vocoder decoding plus a raised-cosine Hann crossfade across fade_frames=4 (1,024 samples), preserving exact waveform length without boundary clicks.