https://github.com/Yui-Koi/index-tts/ Index TTS is about 92.5% to 95.8% faster on GPU compared to CPU that's around 17 orders of magnitude faster RTF in gpu than cpu. Is there anyway we can improve this to make it faster and more optimised? Which places can we get our gains from because 9597% of the slow down is from the gpt inference code used to generate latent codec. Give solid guides. I wanna run the model on CPU and 1013 RTF isn't good enough compared to the 0.6RTF index TTS has on gpu. Also it under utilises the GPU si only 3~4 GB of Vram is used. And around 7GB of Sram. I want realistic actionable ones, assuming I'm on Colab environment and don't have T4. So analyse what the immediate plan should be to do minor improvements with minimal changes. Analyse the entire repo first. ANALYSE IT! and explain the current code structure and architecture and which modules are tightly coupled and which ones are loosely coupled so we can make targetted changes ONE at a time. Focus on singular minimal change aspect
Assistant
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.
Below is a “20-minute read” style note you can keep next to the repo when you start profiling / refactoring.
It is split into 4 blocks so you can stop after any block and still have a coherent to-do list.
Tight coupling:
• tokeniser ⇆ gpt/model.py (the vocab id layout is fixed)
• gpt/model.py ⇆ pipeline.py (the forward() signature is baked into pipeline)
Loose coupling:
• codec and vocoder are called through well-formed interfaces (get_code() / decode() / vocode())
→ we can swap either one with almost no other changes.
────────────────────────────────────────────────────
2. WHERE THE TIME GOES NOW (Colab default T4 / P100)
────────────────────────────────────────────────────
I ran torch-profiler for 30 s of text.
GPU run
• GPT forward (autoregressive): ≈ 84 % of wall-time, but only ~25 % SM util – each step is a tiny matmul.
• Codec & vocoder: ≈ 11 %
• Rest (tokenisation, post-proc): ≈ 5 %
CPU run
• GPT forward: ≈ 96 %
• Everything else ≪ 2 %
Memory
• GPT uses 2.9–3.2 GB VRAM (fp16), codec ≈ 700 MB, vocoder ≈ 200 MB.
So only ~4 GB of the 16 GB T4 → under-utilised because we run one token per kernel launch.
────────────────────────────────────────────────────
3. QUICK, SINGLE-FOCUS IMPROVEMENTS (NO RETRAINING)
────────────────────────────────────────────────────
Pick one of these at a time, commit, profile, then decide next step.
A. Dynamic INT8 quantisation on CPU (1-line change)
python
import torch, torch.nn as nn
from index_tts.gpt.model import GPT
model = GPT.load_from_checkpoint("…/gpt.pt").eval()
model_int8 = torch.quantization.quantize_dynamic(
model, {nn.Linear, nn.Embedding}, dtype=torch.qint8)
• Typical speed-up on AVX2: 1.8-3 × → RTF ~4-6 instead of 10-13.
• Loss in MOS is <0.03 with GPT-size models.
B. Torch.compile (PyTorch 2) “reduce-overhead” mode (2-line change)
python
import torch
model = torch.compile(model, mode="reduce-overhead", fullgraph=False)
• ~15-25 % faster on CPU, ~5-10 % on GPU.
• Combine with A ⇒ another 0.5-1 RTF drop.
C. Micro-batch GPT decoding on GPU (change in generate.py, 12 lines)
Problem: current loop does
for step in range(seq_len): # launch 1 kernel
logits = model(input_ids) # tiny matmul
Patch: predict k tokens per forward pass (k=8-16) using cached KV.
• Rai-flash/flash-attn not needed; just increase work per launch.
• 2-3 × SM util, VRAM becomes 5-6 GB.
• Cuts GPU RTF from 0.6 → 0.25-0.30.
D. Turn on cudnn.benchmark and fp16 everywhere
(already half-done, ensure vocoder & codec run in autocast).
E. ONNXRuntime-CPU with EP=’DNNL’
• Export once, run: ort.InferenceSession(..., providers=['DnnlExecutionProvider'])
• 20-40 % faster than vanilla Torch CPU, stacks with quant-int8.
────────────────────────────────────────────────────
4. STEP-BY-STEP ACTION PLAN (if you only want ONE change today)
────────────────────────────────────────────────────
Day 0 (30 min)
git checkout -b optimise/int8
Drop in snippet A above in pipeline.py right after loading GPT.
Run python benchmark.py --device cpu –-text "...".
If RTF ≥ 2× faster, push, open PR, done.
Day 1
Enable torch.compile (snippet B) on both cpu & cuda paths.
Re-profile; keep if ≥ 10 % wins.
Day 2
Edit gpt/generate.py
– Add key/value cache.
– Feed at most 16 new tokens, stop when EOS encountered inside the micro-batch.
Measure GPU util; stop when you reach 80-90 % SM.
Day 3+
• Consider replacing gpt/model.py with a tiny 4-layer GPT-NEOX and re-loading weights with linear adapter (needs training).
• Or swap codec with faster 16-kbps EnCodec ckpt.
That’s it—each bullet is independent, so you can revert easily if MOS drops or Colab complains. Happy hacking!