10-405/605/805�ML FROM LARGE DATASETS
Announcements
Outline
Recap outline: Making models smaller
✅
✅
Recap outline: Making models smaller
Recap: Unstructured pruning
- optionally repeat
Rank by: weight magnitude, weights and activation (WANDA), …
Algorithmic structure of pruning method: prune once, prune and retrain, prune, retrain (or distill) and repeat, …
Many ranking schemes need validation data as well as the model
Recap outline: Making models smaller
Recap: N:M pruning
N:M sparsity is supported by accelerator hardware
00, 11
Recap: N:M pruning
N:M sparsity is supported by accelerator hardware
00, 11,
01,10
Recap: WANDA Semi-structured pruning
comparison group = block of 4, always prune 2 from block
Recap outline: Making models smaller
Recap: Shortened Llama
Recap: Minitron
B,S = batch and sequence
Recap: Minitron
B,S = batch and sequence
Heads, layers…
Recap outline: Making models smaller
Recap: How to KV Cache
“Q: What is the first law? A: …”
Recap: KV caching is important
Recap: KV caching is important
Recap: Transformers Are KV-Cache Optimized
Recap: Restricting attention with KV caching
Recap: Backstory in restricted attention
Recap: “Heavy Hitters” in KV Caches
2023
Recap: “Heavy Hitters” in KV Caches
sparsity: fraction of cache with < 1% of max attention score
Attention is sparse
Heavy Hitter KV Cache Entries are Important
Recap: “Heavy Hitters” in KV Caches
Recap: “Heavy Hitters” in KV Caches
Recap outline:Making models smaller
Outline
Outline
Other ways of predicting attention
2024
Other ways of predicting attention
Why are initial positions getting so much attention?
Conjecture: they are being used as “none of the above” in attention
StreamingLLM
red: stream LLM
orange: sliding window attention (local)
blue: dense attention
StreamingLLM and H2O
Outline
Predictive KV Caching: SnapKV
2024
Predictive KV Caching: SnapKV
Predictive KV Caching: SnapKV
Predictive KV Caching: SnapKV
SnapKV: Details
SnapKV: Experiment
Needle in a Haystack: Background
Needle in a Haystack: SnapKV results
Outline
Predictive KV Caching: FastGen
2024
Predictive KV Caching: FastGen
Prior analysis of BERT showed it often attends to separators
Also SepLLM showed separators + initial tokens are useful for KV-caching
Predictive KV Caching: FastGen
Which works best? It depends….
Different heads at level 20
Predictive KV Caching: FastGen
Which works best? It depends….
Same head different layers
Predictive KV Caching: FastGen
Predictive KV Caching: FastGen Results
Outline
Discussion
Model compression: �Recap and Overview
How should we think about these?
Heuristic: find a survey paper!
How should we think about these?
TACL 2024
To reduce the cost about the weight update process required by SparseGPT, Wanda (Sun et al., 2024) achieves model sparsity by pruning weights with the smallest magnitudes multiplied by the norm of the corresponding input activations, without the need for retraining or weight updates.
Recap: making a large model smaller
Quantization, Pruning, and KV Cache Management are really learning problems … with constraints on the model learned
Optimization with discrete constraints is harder—so in practice people approximate
Recap: making a large model smaller
Old-school ML in practice:
Recap: making a large model smaller
Quantization, Pruning, and KV Cache Management are really learning problems … with constraints on the model learned
Optimization with discrete constraints is harder—you need to find the best way to satisfy the discrete constraints and the best parameters
Work often looks like searching the discrete part of the space manually (or greedily or …)
Quantization: Background
optimizer accumulates gradients and scales by learning rate
Recap
Optimize parameter values via gradient descent (as usual) subject to constraint:
Quantization: Beyond 16 bits
Recap
Optimize parameter values via gradient descent (as usual) subject to constraint:
subset to be quantized is chosen with manually fixed rules (based on activation values)
Quantization: Beyond 16 bits
Hypothesis: outlier features are why int8 stops working!
Recap
Quantization: Beyond 16 bits
Recap
Optimize parameter values via gradient descent (as usual) subject to constraint:
subset to be quantized is chosen with manually fixed rules (based on activation values)
Quantization: Performance Tradeoffs
2024
Not a Recap
Quantization: Beyond 4 bits
Not a Recap
The model compression frontier
Gumbel-Softmax Quantization, April 2026
Riemannian Constrained Optimization, May 2026
Clever methods for gradient-based optimization for discrete choices
Recap: making a large model smaller
simple quant rules
complex rules, learning
“32 bits everywhere”
“16 bits except for bias”
int8() except for outliers, defined as ….
jointly optimize codebook/codes and where to quant while doing gradient updates on weights
Recap: making a large model smaller
Unstructured pruning
Recap
Optimize parameter while minimizing NNZ weights by alternating
Unstructured pruning: Wanda
Recap
Optimize parameter while minimizing NNZ weights by alternating
What sparse operations are supported?
Recap
What sparse operations are supported?
Speeds for WANDA using semi-structured N:M pruning
Recap
Optimize parameter while minimizing NNZ weights by alternating
Structured Pruning: Shortened Llama
Recap
Optimize parameter while reducing # layers:
Structured Pruning: Sheared Llama
Structured Pruning: Sheared Llama
Use gradients with Lagrange multipliers to jointly optimize perplexity and distance to a valid mask
Recap: making a large model smaller
simple optimization
complex optimization
Wanda: greedy weight pruning
shortened Llama: greedy layer pruning + LoRA
Magnitude: greedy weight pruning alternating with gradients
Sheared Llama: jointly optimize weights and continuous approximation to mask.
Important note:
complicated ≠ good!
Minitron: distillation retraining, lightweight architecture search, …: better result!
Recap: making a large model smaller
H2O: “Heavy Hitters” in KV Caches
Recap
Greedy pruning (eviction) based on running estimate of cumulative attention
StreamingLLM
red: stream LLM
orange: sliding window attention
blue: dense attention
Recap
Eviction is FIFO with an exception for first few tokens
StreamingLLM and H2O
Recap
Eviction is H2O rule with an exception for first few tokens
SnapKV: Details
Recap
Eviction for a prompt is based on a score learned from the observation window for that prompt
Predictive KV Caching: FastGen
2024
Recap
Predictive KV Caching: FastGen
Prior analysis of BERT showed it often attends to separators
Also SepLLM showed separators + initial tokens are useful for KV-caching
Recap
Predictive KV Caching: FastGen
Recap
Eviction strategy for a prompt is learned based on the strategy’s effectiveness in prefilling
…and head identity and layer is also a feature (i.e., each can have a different strategy)
Recap: making a large model smaller
simple optimization
complex optimization
+ start token
H2O: score by running accumulated attention
SnapKV: Adaptively pick specific weights based on observation window in prefilling
FastGen: Pick strategy per head and layer based on prefilling.
Score by recency (FIFO)
+ separator
Recap: making a large model smaller
Old-school ML in practice: