GENERATION STRATEGIES
The problem: Without KV cache, each new token requires recomputing attention over all previous tokens. Complexity: O(n²).
The solution: Store computed K,V pairs. Each new token only computes attention against cached keys/values. Complexity: O(n).
Memory cost: 2 × seq_len × num_layers × num_kv_heads × head_dim × 2 bytes (BF16).
Example: 7B model, 4096 context, BF16 = ~1.3GB KV cache. At 32K context = ~10GB.
vLLM
PagedAttention, continuous batching, highest throughput. The industry standard for serving.
TGI (Text Generation Inference)
Hugging Face's production server. Good integration with Hugging Face ecosystem.
Ollama
Local inference with GGUF quantized models. Simplest way to run models locally.
llama.cpp
CPU + GPU hybrid inference. Best for running large models on limited hardware.