J Z commited on
Commit
b0cd63b
·
verified ·
1 Parent(s): f631086

Update tts.py

Browse files
Files changed (1) hide show
  1. tts.py +8 -7
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
- # ~50 audio tokens per word at faster speed; model should stop naturally before cap
 
437
  word_count = len(text.split())
438
- scaled_max = min(990, max(280, word_count * 50))
439
  logger.info(f"[{_ts()}] [TTS] Words: {word_count} → max_tokens: {scaled_max}")
440
 
441
  # Generation settings matched to mode
442
- # Official docs: "Increasing repetition_penalty and temperature makes the model speak faster"
443
- # For ~1.25x speed: bump rep_penalty from 1.1→1.3, temperature from 0.5→0.6
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.6, top_p=0.85, rep_penalty=1.3)
447
  else:
448
- gen_kwargs = dict(max_tokens=min(1200, word_count * 50), temperature=0.7, top_p=0.9, rep_penalty=1.3)
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()