Overview
Batch processing allows you to:- Process multiple texts in a single forward pass
- Improve GPU utilization and throughput
- Reduce per-sample overhead
- Generate consistent audio for multiple inputs efficiently
Basic Batch Processing
All generation methods support batch inputs by passing lists:CustomVoice Batch
VoiceDesign Batch
Voice Clone Batch
Batch Size Considerations
Memory Management
Choose appropriate batch sizes based on your GPU memory:Processing Large Datasets
For large datasets, process in chunks:Performance Optimization
Model Selection
Choose the right model for your throughput needs:Use Non-Streaming Mode
For batch processing, disable streaming for better throughput:Enable FlashAttention-2
Always use FlashAttention-2 for best performance:Complete Batch Processing Example
Here’s a production-ready example:Batch with Different Voices
Process multiple texts with different cloned voices:Performance Benchmarks
Throughput Comparison
Benchmarks measured with FlashAttention-2 enabled and bfloat16 precision.
Memory Usage Guidelines
Best Practices
Choose appropriate batch size
Choose appropriate batch size
Start with batch_size=8 and increase until you hit memory limits. Monitor GPU memory usage with
nvidia-smi.Use consistent input lengths
Use consistent input lengths
Texts of similar length in each batch improve efficiency. Sort texts by length before batching.
Reuse voice prompts
Reuse voice prompts
When using the same voice multiple times, create the prompt once and reuse it across batches.
Enable non-streaming mode
Enable non-streaming mode
For batch processing,
non_streaming_mode=True provides better throughput than streaming.Use appropriate dtype
Use appropriate dtype
bfloat16 provides the best balance of speed and quality. fp16 may be slightly faster but less stable.
Troubleshooting
Out of memory errors
Out of memory errors
Reduce batch_size, use the 0.6B model instead of 1.7B, or enable gradient checkpointing if available.
Slow processing
Slow processing
Ensure FlashAttention-2 is installed and enabled. Use bfloat16 dtype. Increase batch size for better GPU utilization.
Inconsistent quality
Inconsistent quality
Some samples in batch have different quality? Check input text lengths - very short texts may have lower quality.
Next Steps
- Learn about Streaming for real-time applications
- See Custom Voice for speaker selection
- Explore Voice Cloning for personalized voices