Model Serving: Architectures & Frameworks
From the course AI Infrastructure & MLOps
Serving an AI model at scale requires specialized infrastructure that handles the unique demands of model inference — GPU memory management, batching, and streaming.
Serving Architectures
Synchronous API: Request → Inference → Response. Best for real-time applications (chatbots, search). Requires low latency.
Asynchronous/Batch: Jobs queued and processed in bulk. Best for non-real-time workloads (document processing, report generation). Maximizes GPU utilization.
Streaming: Tokens streamed as they're generated. Essential for LLM applications where time-to-first-token matters more than total latency.
Key Serving Frameworks
vLLM: The de facto standard for LLM serving
- PagedAttention for efficient KV-cache management
- Continuous batching for maximum throughput
- Supports LoRA adapters, quantized models, and speculative decoding
- 2-4× faster than naive serving implementations
Text Generation Inference (TGI): Hugging Face's production server
- Docker-based deployment
- Built-in support for most Hugging Face models
- Flash Attention and quantization support
- Good default for getting started quickly
Triton Inference Server: NVIDIA's multi-framework server
- Supports PyTorch, TensorFlow, ONNX, and custom backends
- Advanced scheduling and batching
- Model ensembles (chain multiple models)
- Best for multi-model deployments
Ollama: For local and edge deployment
- Simple CLI-based model management
- Runs GGUF-quantized models efficiently
- Great for development and testing
- Not designed for high-throughput production
Batching Strategies
- Static batching: Wait for N requests, process together. Simple but adds latency.
- Dynamic batching: Process requests as they arrive with a short timeout window.
- Continuous batching: vLLM's approach — new requests join the batch as slots free up during generation.
Continuous batching can increase throughput by 2-5× compared to static batching.
GPU Memory Management
LLM inference is memory-bound. Key techniques:
- KV-cache optimization: PagedAttention allocates cache memory on-demand, reducing waste by 60-80%
- Model parallelism: Split large models across multiple GPUs (tensor parallel or pipeline parallel)
- Quantization: Reduce model precision from FP16 to INT8/INT4 for 2-4× memory reduction
Key Takeaways
- •vLLM with PagedAttention and continuous batching is the gold standard for LLM serving
- •Choose synchronous serving for real-time apps, batch processing for throughput-heavy workloads
- •Continuous batching increases throughput 2-5× over static batching
- •GPU memory optimization through KV-cache management and quantization is essential at scale
Progress is kept in this browser only.