Reference notes.
Model serving is the infrastructure and techniques for deploying ML models to production, handling inference requests efficiently at scale.
Deployment Options
Managed APIs
Use a provider’s hosted models via API.
Advantages:
- No infrastructure management
- Always latest models
- Scales automatically
Disadvantages:
- Cost at scale
- Data leaves your environment
- Vendor lock-in
- Rate limits
Providers: OpenAI, Anthropic, Google, Cohere, AWS Bedrock, Azure OpenAI
Self-hosted
Run models on your own infrastructure.
Advantages:
- Data privacy
- Cost control at scale
- Customisation
- No rate limits
Disadvantages:
- GPU infrastructure required
- Operational complexity
- Model updates are your responsibility
Inference Servers
vLLM
High-throughput LLM serving with PagedAttention.
- Continuous batching
- Tensor parallelism
- OpenAI-compatible API
- Best for: High throughput production
vllm serve meta-llama/Llama-3.3-70B-Instruct --port 8000Text Generation Inference (TGI) (archived)
Hugging Face’s former production server — archived in March 2026. Hugging Face now recommends vLLM or SGLang for production LLM serving.
Ollama
Simple local model running.
- Easy model management
- Automatic quantisation
- REST API
- Best for: Local development, prototyping
ollama run llama3LMStudio
Desktop app for running local models.
- GUI interface
- One-click downloads
- Local OpenAI-compatible server
llama.cpp
Highly optimised C++ inference.
- CPU and GPU support
- Minimal dependencies
- GGUF format
- Best for: Edge deployment, low resources
SGLang
High-performance serving from UC Berkeley, widely adopted for multi-turn and agentic workloads.
- RadixAttention — Caches shared prefixes in a radix tree, up to 5x faster for workloads with common system prompts
- Historically posted ~29% higher throughput than vLLM in specific single-workload benchmarks (legacy Llama 3.1 8B offline batch on 1× H100: ~16,200 vs ~12,500 tok/s); relative performance shifts across releases, so benchmark your own workload and engine versions
- Zero-overhead batch scheduler (CPU scheduling <2% of total time)
- Runs on NVIDIA, AMD GPUs, and TPUs (via SGLang-Jax)
- Best for: Multi-turn conversations, agentic tasks, structured generation
python -m sglang.launch_server --model meta-llama/Llama-3.3-70B-Instruct --port 8000LMDeploy
Optimised for running large models on limited hardware.
- Matched SGLang on legacy single-workload H100 benchmarks (~16,100 tok/s on Llama 3.1 8B offline batch; verify on current engine versions and your target workload)
- Strong Int4/FP8 quantisation support
- Best for: Large models (405B+) on constrained hardware
Others
- TensorRT-LLM — NVIDIA-optimised, best on B200 GPUs
- NVIDIA Dynamo — Disaggregated serving framework for dynamic GPU assignment
- MLC LLM — Universal deployment
Choosing an Inference Engine
| Engine | Best For |
|---|---|
| SGLang | Multi-turn, agentic, shared prefixes |
| vLLM | Broadest model support (218+ architectures), stable API |
| LMDeploy | Large models on limited hardware |
| TensorRT-LLM | Maximum performance on NVIDIA hardware |
| Ollama | Local development and prototyping |
Quantisation
Reduce model precision to decrease memory and increase speed.
Formats
Modern model weights typically ship in BF16/FP16 (or natively in FP8/FP4), so memory savings below are relative to BF16/FP16 rather than FP32:
| Format | Bits | Memory vs BF16 | Quality Loss |
|---|---|---|---|
| FP32 | 32 | 2× (legacy master weights) | None |
| FP16 / BF16 | 16 | Baseline | Baseline |
| FP8 | 8 | ~50% (2× smaller) | Negligible (native on H100/H200/B200) |
| INT8 | 8 | ~50% (2× smaller) | Small |
| FP4 / MXFP4 / NVFP4 | 4 | ~75% (4× smaller) | Low to moderate (native on Blackwell B200/B300 and RTX 5090) |
| INT4 | 4 | ~75% (4× smaller) | Moderate |
Methods
Post-training quantisation (PTQ)
Quantise after training. Fast but may lose quality.
- GPTQ — Popular 4-bit method
- AWQ — Activation-aware, better quality
- GGUF — llama.cpp format, various bit-widths
- bitsandbytes — Easy integration with Transformers
Quantisation-aware training (QAT)
Train with quantisation in mind. Better quality but expensive.
Practical Guidelines
- 8-bit: Negligible quality loss for most tasks
- 4-bit: Good for constrained environments, test quality
- Below 4-bit: Significant degradation, use carefully
Batching
Static Batching
Wait for N requests, process together. Simple but adds latency.
Dynamic Batching
Set max wait time, batch whatever arrives. Balances throughput and latency.
Continuous Batching
Process requests as they complete, add new ones to running batch. Best throughput.
vLLM and SGLang use continuous batching by default (as did legacy TGI).
Scaling
Horizontal Scaling
Multiple model replicas behind a load balancer.
- Stateless inference enables easy scaling
- Use Kubernetes for orchestration
- Consider GPU availability constraints
Tensor Parallelism
Split model across multiple GPUs on same node.
- Required for models exceeding single-GPU memory or to cut per-request latency
- Significant collective communication overhead — Ring AllReduce volume per GPU approaches activation size per synchronisation step, bottlenecked by NVLink bandwidth and cross-node latency
Pipeline Parallelism
Split model layers across GPUs.
- Lower communication overhead
- Creates pipeline bubbles
Expert Parallelism
For Mixture-of-Experts models, distribute experts across GPUs.
Hardware
GPUs & Accelerators
| Hardware | Memory | Use Case |
|---|---|---|
| RTX 4090 | 24GB | Development, small models |
| RTX 5090 | 32GB | Local inference, native FP4 (Blackwell) |
| Apple Silicon (M-series / MLX) | 32–512GB unified | Local/workstation serving of large quantised models via MLX or llama.cpp |
| A10G / L4 | 24GB | Entry cloud inference (AWS / GCP) |
| A100 80GB | 80GB | Medium to large models |
| H100 | 80GB | High throughput, native FP8 |
| H200 | 141GB | Higher HBM bandwidth and capacity than H100 |
| AMD MI300X / MI325X | 192GB / 256GB | High-capacity datacentre inference, strong vLLM/SGLang ROCm support |
| B200 / B300 (Blackwell) | 192GB / 288GB | Massive throughput, native FP4, frontier MoE scaling |
Memory Estimation
Rough formula for model weights only in BF16/FP16:
Weight Memory (GB) ≈ Parameters (B) × 2
With 4-bit quantisation:
Weight Memory (GB) ≈ Parameters (B) × 0.5
7B model weights: ~14GB BF16/FP16, ~3.5GB 4-bit. Production serving requires substantial additional VRAM for the KV cache (scales with batch size and context length — see LLMs), intermediate activations, and CUDA/runtime overhead (typically budget 20–40%+ extra headroom beyond weight memory, or more at long contexts and high concurrency).
Cloud GPU Providers
- AWS (p4d, p5 instances)
- GCP (A100, H100)
- Azure
- Lambda Labs
- RunPod
- Vast.ai
- Together AI
- Modal
Optimisation Techniques
KV Cache
Cache key-value pairs from previous tokens. Essential for autoregressive generation.
Flash Attention
Memory-efficient attention computation. Now standard in most servers.
Speculative Decoding
Use smaller draft model to propose tokens, verify with main model in parallel.
Prefix Caching
Cache common prefixes (system prompts) across requests.
Prefill–Decode (PD) Disaggregation
Separates compute-bound prompt processing (prefill) from memory-bandwidth-bound token generation (decode) across dedicated GPU pools, transferring KV caches over fast interconnect. Prevents long incoming prompts from stalling active decode streams and lets each stage tune batching independently (supported in vLLM, SGLang, and NVIDIA Dynamo).
Monitoring
Key Metrics
- Latency — Time to first token (TTFT), inter-token latency, total latency
- Throughput — Requests/second, tokens/second
- GPU utilisation — Memory, compute
- Queue depth — Pending requests
Tools
- Prometheus + Grafana
- Built-in server metrics endpoints
- LangSmith
- Arize Phoenix
Production Checklist
- Load testing under expected traffic
- Graceful degradation under overload
- Health checks and auto-restart
- Request timeouts
- Rate limiting
- Logging and tracing
- Cost monitoring
- Model versioning strategy
See Also
- Foundation Models — Available models and API providers
- LLMs — Architecture details relevant to serving
- Fine-tuning — Quantisation and PEFT for efficient serving