Quantization, GGUF and Local Models
Introduction: The Local Inference Stack
- Why Engineers Care About Local Inference
- What This Book Will Not Teach You
- The Real Bottleneck: Memory Bandwidth, Not Compute
- How to Read This Book
Chapter 1: Transformer Inference Fundamentals
- From Training to Inference: What Changes
- The Forward Pass Anatomy
- Self-Attention and Its Costs
- Why Autoregression Matters
- Arithmetic Intensity and Compute Density
Chapter 2: Tokenization, Prefill, and Decode
- How Tokenizers Actually Work
- The Prefill Phase: Parallel Computation
- The Decode Phase: Sequential Bottleneck
- Context Length and Its Real Cost
- Why These Phases Demand Different Optimizations
Chapter 3: Model Weights, Formats, and GGUF Architecture
- From Checkpoints to Inference: Weight Formats
- The GGML Story and Design Goals
- GGUF Header Structure and Metadata
- Tensor Storage Layout and Quantization Types
- Reading a GGUF File: A Practical Walkthrough
Chapter 4: Quantization: Mathematics, Methods, and Tradeoffs
- Why Quantization Works on Transformers
- Symmetric vs Asymmetric Quantization
- Per-Tensor, Per-Channel, Per-Group Schemes
- GGUF Quantization Types Decoded
- Measuring Quality Loss: Benchmarks and Perception
- Choosing a Quant Level for Your Use Case
Chapter 5: Memory, Bandwidth, and Hardware Constraints
- Computing Model Size: The Exact Formula
- KV-Cache Memory Requirements
- Memory Bandwidth vs Compute Throughput
- CPU Architectures for Inference
- GPU Architectures and VRAM Realities
- Hardware Selection Decision Framework
Chapter 6: llama.cpp: Installation, Models, and Core Usage
- Building llama.cpp from Source
- Installing Prebuilt Binaries
- Acquiring Models: Hugging Face and Beyond
- Converting Weights to GGUF
- Quantizing Models with llama.cpp
- Your First Inference Run
Chapter 7: GPU Acceleration and Offloading Strategies
- How Offloading Works Under the Hood
- Full vs Partial Offloading: When Each Wins
- CUDA Backend Configuration
- Vulkan and Cross-Vendor GPU Support
- Apple Silicon and Metal Acceleration
- Diagnosing Offloading Failures
Chapter 8: KV-Cache, Context Windows, and Memory Management
- How the KV-Cache Works
- Sizing Your KV-Cache Correctly
- Context Overflow and Handling Strategies
- RoPE Scaling and Long-Context Techniques
- Cache Eviction and Sliding Windows
- Memory Fragmentation and Allocation Patterns
Chapter 9: Throughput, Batching, and Concurrency
- Single Request vs Concurrent Serving
- Static Batching Mechanics
- Continuous Batching and Scheduling Strategies
- Queue Management Under Load
- Configuring llama.cpp Server for Throughput
- Capacity Planning and Dimensioning
Chapter 10: Benchmarking, Profiling, and Bottleneck Diagnosis
- Metrics That Matter: Definitions and Formulas
- Designing Valid Benchmark Experiments
- Profiling CPU Utilization and Vector Units
- GPU Profiling and Occupancy Analysis
- Memory Bandwidth Measurement Techniques
- Systematic Bottleneck Diagnosis Workflow
Chapter 11: Production Systems: APIs, RAG, and Deployment
- Building a Private Local Assistant
- Coding Assistant Integration Patterns
- RAG Service Architecture
- Multi-User Inference API Design
- Containerization and Orchestration
- Observability, Security, and Reliability
Chapter 12: Troubleshooting, Comparisons, and the Road Ahead
- Common Failure Modes and Diagnostics
- Performance Troubleshooting Decision Tree
- llama.cpp vs Other Inference Runtimes
- What Is Durable vs Rapidly Changing
- Emerging Trends and Open Problems
