feat: opt-in torch.compile of the code predictor loop (TTS_COMPILE_PREDICTOR=1)

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
mARTin-B78 2026-10-11 19:18:31 +02:00
parent 119b92ea15
commit ecd833cb89
2 changed files with 27 additions and 2 deletions

View File

@ -24,8 +24,8 @@ RUN git clone https://github.com/andimarafioti/faster-qwen3-tts.git /app && \
cd /app && git checkout --detach ${FASTER_QWEN3_TTS_REF} cd /app && git checkout --detach ${FASTER_QWEN3_TTS_REF}
# Apply DGX Spark patches (non_streaming_mode=True, per-voice temperature/top_k/top_p) # Apply DGX Spark patches (non_streaming_mode=True, per-voice temperature/top_k/top_p)
COPY patches/openai_server.patch /tmp/ COPY patches/openai_server.patch patches/predictor_compile.patch /tmp/
RUN cd /app && git apply /tmp/openai_server.patch RUN cd /app && git apply /tmp/openai_server.patch && git apply /tmp/predictor_compile.patch
# Create virtual environment (Ubuntu 24.04 enforces PEP 668) # Create virtual environment (Ubuntu 24.04 enforces PEP 668)
ENV VIRTUAL_ENV=/opt/venv ENV VIRTUAL_ENV=/opt/venv

View File

@ -0,0 +1,25 @@
diff --git a/faster_qwen3_tts/predictor_graph.py b/faster_qwen3_tts/predictor_graph.py
index 38a52ca..70851eb 100644
--- a/faster_qwen3_tts/predictor_graph.py
+++ b/faster_qwen3_tts/predictor_graph.py
@@ -13,6 +13,8 @@ Strategy:
- Unroll the full 15-step loop for deterministic shapes
- Capture the entire loop as a single CUDA graph
"""
+import os
+
import torch
from transformers import StaticCache
from transformers.masking_utils import create_causal_mask, create_sliding_window_causal_mask
@@ -175,6 +177,11 @@ class PredictorGraph:
self._init_cache_layers()
self._build_attention_masks()
+ # Opt-in: fuse the 15-step predictor loop with Inductor before graph capture.
+ # ~17% faster streaming on GB10 (0.6B); adds ~1 min to the first warmup.
+ if os.environ.get("TTS_COMPILE_PREDICTOR") == "1":
+ self._full_loop = torch.compile(self._full_loop, dynamic=False)
+
for _ in range(num_warmup):
self.static_cache.reset()
self._full_loop()