Week 22: Self-Hosting Open Models (`vLLM`, `Ollama`, GPU Math & Quantization)
Week 22 Daily Breakdown (7 Days)
Day 1: The Physics & Math of LLM Inference (VRAM & Bandwidth Calculators)
1 code file(s) • 3 Q&ADay 2: High-Throughput Serving with `vLLM` & PagedAttention
1 code file(s) • 3 Q&ADay 3: Local & Edge Model Serving with `Ollama` & `llama.cpp`
1 code file(s) • 3 Q&ADay 4: GPU Quantization Formats Compared — AWQ, GPTQ, GGUF, FP8
1 code file(s) • 3 Q&ADay 5: Building the Unified OpenAI-Compatible Serving Gateway
1 code file(s) • 3 Q&ADay 6: Automated Cost, Latency & Accuracy Benchmarking
1 code file(s) • 3 Q&ADay 7: Week 22 Mini-Project — High-Throughput Local Serving Engine
1 code file(s) • 3 Q&AWeek 22: Self-Hosting Open Models (vLLM, Ollama, GPU Math & Quantization)
In Week 21, you mastered parameter-efficient fine-tuning (LoRA, QLoRA) and preference alignment (DPO). You trained a custom SRE Incident Classification adapter.
Now comes the critical engineering question: How do you host, serve, and scale these open-weights models in production? Calling hosted proprietary APIs (OpenAI, Anthropic) is simple, but in high-volume production, hosting your own open-weights models (LLaMA-3, Qwen-2.5, Mistral) unlocks 4x to 10x cost reductions, sub-200ms p95 latencies, zero data egress risk, and complete operational independence.
1. The Physics & Roofline Model of LLM Inference
Senior AI Engineers understand that training and inference have completely different hardware bottlenecks:
- Training & Prefill (Prompt Processing): Highly compute-bound (GEMM: General Matrix Multiply). The arithmetic intensity (FLOPs / byte transferred) is high. Modern GPU Tensor Cores are fully utilized.
- Decoding (Autoregressive Token Generation): Heavily memory-bandwidth bound (GEMV: General Matrix-Vector Multiply). Every single newly generated token requires streaming every single weight of the model from High Bandwidth Memory (HBM) into SRAM cache!
The Generation Bandwidth Formula
For a single batch stream generating tokens autoregressively on a model of size (in gigabytes):
Concrete Example (LLaMA-3.1-8B in FP16 = 16 GB):
- On an NVIDIA RTX 4090 ($1,008\text{ GB/s}$ bandwidth):
- If quantized to 4-bit (AWQ / GPTQ = 4 GB): Quantization does not just save VRAM—it directly multiplies token decoding speed!
2. High-Throughput Serving: PagedAttention & Continuous Batching
In 2023, Woosuk Kwon et al. (UC Berkeley) identified the primary bottleneck in production LLM serving: KV Cache Memory Fragmentation.
PagedAttention Innovations
- Near-Zero Memory Waste (): Blocks are allocated on demand as tokens are generated.
- Continuous Batching (Iteration-Level Scheduling): Finished requests exit immediately; new requests enter at the next token step. The GPU runs at 100% capacity continuously.
- Prefix Caching: Identical system prompts and few-shot examples share the same physical KV blocks, dropping Time-To-First-Token (TTFT) by $90%$.
3. Quantization Landscape Compared
| Format | Quantization Method | Primary Target | Strengths | Ideal Production Use Case |
|---|---|---|---|---|
| AWQ | Activation-Aware (Protects salient 1% weights) | NVIDIA GPUs | Near-zero perplexity degradation, ultra-fast CUDA kernels. | vLLM production GPU serving (A100, H100, L4). |
| GPTQ | Second-order Hessian error minimization | NVIDIA GPUs | Very fast quantization, broad support. | Single-GPU inference. |
| GGUF | k-quants (Q4_K_M, Q5_K_M, Q8_0) | CPU / Apple Silicon / Metal | Highly portable single-file binary format, zero-copy mmap. | Ollama / Local dev & edge deployment. |
| FP8 | Native 8-bit Float (E4M3 / E5M2) | Ada / Hopper (L4, H100) | Native Tensor Core hardware execution, no dequantization overhead. | Enterprise H100 / L4 clusters. |
4. Week 22 Day-by-Day Syllabus
| Day | Topic | Source Module | Automated Test |
|---|---|---|---|
| Day 1 | The Physics & Math of LLM Inference (VRAM & Bandwidth) | src/inference_physics_and_vram_calculator.py | tests/test_inference_physics_and_vram_calculator.py |
| Day 2 | High-Throughput Production Serving with vLLM & PagedAttention | src/paged_attention_simulator.py | tests/test_paged_attention_simulator.py |
| Day 3 | Local & Edge Model Serving with Ollama & llama.cpp (GGUF) | src/ollama_model_manager.py | tests/test_ollama_model_manager.py |
| Day 4 | GPU Quantization Formats Compared: AWQ, GPTQ, GGUF, FP8 | src/quantization_benchmark_analyzer.py | tests/test_quantization_benchmark_analyzer.py |
| Day 5 | Building the Unified OpenAI-Compatible Serving Gateway | src/openai_compatible_gateway.py | tests/test_openai_compatible_gateway.py |
| Day 6 | Automated Cost, Latency & Accuracy Benchmarking | src/automated_benchmark_suite.py | tests/test_automated_benchmark_suite.py |
| Day 7 | Mini-Project: High-Throughput Local Model Serving Engine | src/high_throughput_serving_service.py | tests/test_high_throughput_serving_service.py |