Skip to main content

Overview

Batch inference allows you to process multiple requests simultaneously, improving throughput and efficiency.

Basic Batch Inference

Key Considerations

Important: For batch generation, you must:
  1. Set padding_side = 'left' on the tokenizer
  2. Enable padding=True in apply_chat_template

Padding Configuration

Mixed Content Batching

You can batch requests with different content types:

Batch with Video Content

Performance Tips

Optimization Recommendations:
  1. Group similar requests: Batch requests with similar lengths to minimize padding overhead
  2. Use flash_attention_2: Significantly improves batch processing speed
  3. Adjust batch size: Balance between throughput and memory usage
  4. Monitor GPU memory: Larger batches require more VRAM

Enable Flash Attention

Memory Considerations

Batch size impacts memory usage:
  • Small batches (2-4): Better for mixed content types
  • Medium batches (4-8): Good balance for similar requests
  • Large batches (8+): Best for uniform, text-only requests
Video content uses significantly more memory than images. Reduce batch size when processing videos.

Error Handling

Next Steps

Generation Parameters

Configure sampling parameters for better outputs

Pixel Control

Optimize memory usage with resolution control