Skip to main content
This guide covers techniques to maximize Qwen3-TTS performance for production deployments, from GPU selection to memory optimization strategies.

FlashAttention 2

FlashAttention 2 is a highly optimized attention implementation that significantly reduces GPU memory usage and improves inference speed.

Installation

Install FlashAttention 2 with pip:
For machines with limited RAM (less than 96GB) and many CPU cores, limit compilation parallelism:

Hardware Requirements

FlashAttention 2 requires specific hardware:
  • GPU Architecture: Ampere (A100, A10) or newer (H100, L40)
  • Compute Capability: 8.0+ (Ampere) or 9.0+ (Hopper)
  • Data Types: Only works with torch.float16 or torch.bfloat16
Read more in the FlashAttention repository.

Usage

Enable FlashAttention 2 when loading the model:

Performance Impact

Batch Processing

Batch inference processes multiple requests simultaneously, dramatically improving throughput.

Batch Generation Example

Batch Size Guidelines

Throughput Gains

Memory Optimization

Data Type Selection

Choose the right dtype based on your hardware and quality requirements:
Pros:
  • Compatible with FlashAttention 2
  • Better numerical stability than float16
  • Native support on modern GPUs (Ampere, Hopper)
  • Minimal quality loss
Cons:
  • Requires Ampere or newer GPUs

float16

Pros:
  • Compatible with FlashAttention 2
  • Wide GPU support (Pascal, Turing, Ampere, Hopper)
  • Lower memory usage
Cons:
  • Less numerical stability than bfloat16
  • Potential for overflow/underflow in some cases

float32

Pros:
  • Maximum numerical precision
  • Universal GPU support
Cons:
  • 2x memory usage vs. float16/bfloat16
  • Slower inference
  • Cannot use FlashAttention 2

Memory Comparison

Memory usage shown is for model weights only. Add 2-4GB for activation memory during inference.

Gradient Checkpointing (Training)

For fine-tuning, gradient checkpointing trades computation for memory:
Memory savings:
  • Standard training: ~12-16GB for 1.7B model
  • With gradient accumulation (4 steps): Effective batch size 4x larger with same memory

GPU Selection

Choose the right GPU for your deployment:

Consumer GPUs

Data Center GPUs

Cloud GPU Recommendations

Streaming vs Non-Streaming

Qwen3-TTS supports both streaming and non-streaming generation.

Non-Streaming (Default)

Generates complete audio before returning:
Pros:
  • Simpler to use
  • Better for batch processing
  • Easier error handling
Cons:
  • Higher latency (wait for complete generation)
  • Not suitable for real-time interaction

Streaming

Outputs audio chunks as they’re generated: Key advantage: Qwen3-TTS features extreme low-latency streaming based on the Dual-Track hybrid streaming architecture:
  • First audio packet: Output immediately after a single character input
  • End-to-end latency: As low as 97ms
  • Real-time factor: Can generate audio faster than real-time playback
Streaming is ideal for conversational AI, virtual assistants, and any application requiring low-latency speech generation.
Use cases:
  • Real-time conversation systems
  • Interactive voice response (IVR)
  • Live audiobook narration
  • Low-latency TTS applications

Generation Parameters

Fine-tune generation quality and speed with these parameters:

max_new_tokens

  • Default: 2048 (recommended)
  • Lower values: Faster, but may truncate long audio
  • Higher values: Allow longer generation, but slower

Sampling Parameters

Pass Hugging Face Transformers sampling parameters:
Parameter guidelines:
  • temperature: 0.6-0.8 for natural variation, 0.3-0.5 for consistent output
  • top_p: 0.9-0.95 for balanced quality
  • top_k: 50 (default is usually good)

Evaluation Benchmark

Official evaluation was conducted with:
This configuration achieves:
  • Seed-TTS test-zh: 0.77 WER (1.7B model)
  • Seed-TTS test-en: 1.24 WER (1.7B model)

Performance Checklist

For optimal performance:
  • Install FlashAttention 2
  • Use dtype=torch.bfloat16 (or torch.float16)
  • Enable attn_implementation="flash_attention_2"
  • Use batch processing when possible
  • Select appropriate GPU with sufficient VRAM
  • Tune batch size based on GPU memory
  • Use streaming for low-latency applications
  • Set max_new_tokens=2048 for standard use cases
  • Profile your specific workload to find optimal settings

Troubleshooting

Out of Memory (OOM)

  1. Reduce batch size
  2. Switch to smaller model (1.7B → 0.6B)
  3. Use bfloat16/float16 instead of float32
  4. Enable FlashAttention 2
  5. Free up GPU memory from other processes

Slow Generation

  1. Install FlashAttention 2
  2. Enable attn_implementation="flash_attention_2"
  3. Use bfloat16 instead of float32
  4. Increase batch size for throughput
  5. Consider vLLM-Omni for production workloads

Quality Issues

  1. Avoid too-low temperature (less than 0.3)
  2. Use bfloat16 for better stability
  3. Ensure input text is clean and well-formatted
  4. Check that language is correctly specified

Next Steps