PART 1 · VISUAL CONCEPTS · 05 / 05

Quantization & LoRA

How 140 GB models squeeze onto a single GPU by snapping weights to coarser grids, and adapt to new tasks by training 0.4% low-rank matrices.

Interactive Lab 01 · Symmetric Weight Quantization

Weight Quantization & Outlier Snapper

INT4 · Crisp
Memory Compression 3.8× vs FP16 baseline
70B Model VRAM 37.0 GB Fits on 1× 80GB H100
Mean Quant Error (MAE) 0.036 Avg |w − ŵ|
Signal Quality (SQNR) 24.2 dB · Crisp Signal-to-Noise Ratio
4×4 Weight Block (Click Cell) 1 Tensor Scale
Quantization Grid Snapper (Cyan: w → Rose: ŵ) Range: [−1.12, +1.12]
Selected Weight w[2] (Group G0) Clean Snap
1. Original w +0.840
2. Scale S = max|W| / q_max 0.1600
3. Quantized q = round(w / S) +5
4. Dequantized ŵ = q × S +0.800 (Δ 0.040)
Interactive Lab 02 · Low-Rank Adaptation (LoRA / QLoRA)

LoRA Decomposition (W + (α/r)·A×B) & QLoRA VRAM Lab

Rank r = 16 · 0.78% Trainable
Rank r: r = 1 r = 128 r = 16
Matrix Factorization (Shape Scales With Rank r) Training Path: W + (α/r)AB
Layer Params & Fine-Tuning GPU VRAM Fits 1× 24GB RTX 4090
Base W (d²) 16.78M
LoRA A+B (2dr) 131.1K
Trainable % 0.78%
FP16 Base NF4 Base Grads + Optimizer Activations
Mental Model · Pure Standard-Library Python

Symmetric INT4 Quantization & LoRALinear in 26 Lines

quant_and_lora.py

      

1 Outlier Crushes 1,000 Weights

One +14.8 spike stretches per-tensor scale S by 13×, collapsing normal weights to 0. Grouping (g=128) + AWQ FP16 protection preserves full INT4 precision.

Why B Starts at Exact Zero

Initializing B = 0 ensures ΔW = A × 0 = 0 at step 0, so the pretrained model starts from its exact learned distribution before gradients refine it.

Free Inference via Weight Merging

Computing W_merged = W + (α/r)·A·B offline removes all adapter FLOPs—or keep A, B unmerged to hot-swap hundreds of customer LoRAs on one GPU.