J Z commited on
Update tts.py
Browse files
tts.py
CHANGED
|
@@ -161,6 +161,7 @@ def _init_vllm_engine(model_name, hf_token):
|
|
| 161 |
engine_args = AsyncEngineArgs(
|
| 162 |
model=model_name,
|
| 163 |
dtype=dtype,
|
|
|
|
| 164 |
gpu_memory_utilization=gpu_mem_util,
|
| 165 |
max_model_len=4096, # Need room for ref audio tokens + generation
|
| 166 |
enforce_eager=True, # Avoid CUDA graph issues on HF Spaces
|
|
@@ -433,19 +434,19 @@ def generate_audio(text: str, output_filename: str = None) -> str:
|
|
| 433 |
logger.info(f"[{_ts()}] [TTS] Prompt: {len(prompt_ids)} tokens")
|
| 434 |
|
| 435 |
# Scale max_tokens to text length to prevent runaway generation
|
| 436 |
-
#
|
|
|
|
| 437 |
word_count = len(text.split())
|
| 438 |
-
scaled_max = min(990, max(
|
| 439 |
logger.info(f"[{_ts()}] [TTS] Words: {word_count} → max_tokens: {scaled_max}")
|
| 440 |
|
| 441 |
# Generation settings matched to mode
|
| 442 |
-
#
|
| 443 |
-
#
|
| 444 |
-
# Higher rep_penalty is the main speed lever; temperature adds variation
|
| 445 |
if _use_voice_cloning:
|
| 446 |
-
gen_kwargs = dict(max_tokens=scaled_max, temperature=0.
|
| 447 |
else:
|
| 448 |
-
gen_kwargs = dict(max_tokens=min(1200, word_count *
|
| 449 |
|
| 450 |
# Generate via vLLM
|
| 451 |
t1 = time.time()
|
|
|
|
| 161 |
engine_args = AsyncEngineArgs(
|
| 162 |
model=model_name,
|
| 163 |
dtype=dtype,
|
| 164 |
+
quantization="fp8", # FP8 dynamic quantization — ~1.5x faster on Ada Lovelace (L4)
|
| 165 |
gpu_memory_utilization=gpu_mem_util,
|
| 166 |
max_model_len=4096, # Need room for ref audio tokens + generation
|
| 167 |
enforce_eager=True, # Avoid CUDA graph issues on HF Spaces
|
|
|
|
| 434 |
logger.info(f"[{_ts()}] [TTS] Prompt: {len(prompt_ids)} tokens")
|
| 435 |
|
| 436 |
# Scale max_tokens to text length to prevent runaway generation
|
| 437 |
+
# Observed: model typically uses 35-43 tokens/word; cap at 45 for headroom
|
| 438 |
+
# This prevents runaway (50+ tok/word) while allowing natural stops
|
| 439 |
word_count = len(text.split())
|
| 440 |
+
scaled_max = min(990, max(200, word_count * 45))
|
| 441 |
logger.info(f"[{_ts()}] [TTS] Words: {word_count} → max_tokens: {scaled_max}")
|
| 442 |
|
| 443 |
# Generation settings matched to mode
|
| 444 |
+
# rep_penalty=1.2 gives slight speed boost without hurting voice clone quality
|
| 445 |
+
# temperature=0.5 keeps voice stable; top_p=0.9 for natural variation
|
|
|
|
| 446 |
if _use_voice_cloning:
|
| 447 |
+
gen_kwargs = dict(max_tokens=scaled_max, temperature=0.5, top_p=0.9, rep_penalty=1.2)
|
| 448 |
else:
|
| 449 |
+
gen_kwargs = dict(max_tokens=min(1200, word_count * 35), temperature=0.7, top_p=0.9, rep_penalty=1.2)
|
| 450 |
|
| 451 |
# Generate via vLLM
|
| 452 |
t1 = time.time()
|