15 min read
Lesson 3 of 5
GPU Optimization & Cost Management
From the course AI Infrastructure & MLOps
GPU compute is the biggest cost in AI infrastructure. Optimizing utilization and choosing the right hardware directly impacts both performance and budget.
GPU Selection Guide
| GPU | VRAM | Best For | Cloud Cost (approx/hr) |
|---|---|---|---|
| NVIDIA T4 | 16 GB | Inference (small models) | $0.50-1.00 |
| NVIDIA A10G | 24 GB | Inference (medium models) | $1.00-1.50 |
| NVIDIA L4 | 24 GB | Inference (efficient) | $0.70-1.20 |
| NVIDIA A100 40GB | 40 GB | Training & large inference | $3.00-4.00 |
| NVIDIA A100 80GB | 80 GB | Large model training | $4.00-5.00 |
| NVIDIA H100 | 80 GB | Frontier model training | $8.00-12.00 |
Optimization Techniques
Quantization: Reduce precision for faster inference
- FP16 → INT8: ~2× speedup, minimal quality loss
- FP16 → INT4 (GPTQ/AWQ): ~4× speedup, slight quality loss
- Always benchmark quality after quantization on your specific tasks
Speculative Decoding: Use a small "draft" model to predict multiple tokens, then verify with the large model in one pass. Can achieve 2-3× speedup for generation.
Flash Attention: Optimized attention computation that's 2-4× faster and uses significantly less memory. Supported by vLLM, TGI, and most modern frameworks.
Key-Value Cache Compression: Compress cached attention states to reduce memory usage during long-context generation.
Cost Management Strategies
- Right-size instances: Don't use an H100 for a 7B model. Match GPU to model size.
- Spot/preemptible instances: 60-90% savings for fault-tolerant workloads (batch processing, training)
- Auto-scaling: Scale GPU instances to zero during low-traffic periods
- Model distillation: Train a smaller model that mimics your large model. 10× cheaper to serve.
- Caching: Cache frequent responses to avoid redundant inference
- Request routing: Route simple queries to small models, complex ones to large models
Cost Calculation Framework
Monthly cost = (GPU cost/hr) × (hours/day) × 30 × (number of GPUs)
Cost per query = Monthly cost / Monthly query volume
Target: < $0.01 per query for most applications
Key Takeaways
- •Match GPU to model size — over-provisioning wastes budget, under-provisioning kills latency
- •Quantization (INT4/INT8) and Flash Attention provide the biggest performance gains
- •Spot instances, auto-scaling, and caching dramatically reduce costs
- •Model distillation can reduce serving costs 10× while maintaining acceptable quality
0 of 5 lessons marked complete
Progress is kept in this browser only.