1 of 85

10-405/605/805�ML FROM LARGE DATASETS

2 of 85

Announcements

  • HW5
    • You may form groups of 2-3
    • Groups should share AWS credits
  • Miniproject
    • Recitation on Friday will discuss it
    • The schedule will be extended to compensate for the late release of miniproject details
      • stay tuned!

3 of 85

Outline

  • Recap:
    • Making models smaller:
      • Distillation, Quantization, Pruning
    • Key-Value Caching
    • Heavy Hitters
  • KV Caching Eviction Policies
    • Attention sinks – StreamingLLM
    • Predictive caching – SnapKV, FastGen
  • Discussion / review

​

​

4 of 85

Recap outline: Making models smaller

    • Distillation
      • Train a small model from a large one
    • Quantization
      • Reduce precision in (parts of ) a model
    • Model pruning
      • Unstructured: zero out some weights
      • Semi-structured: prune to N:M sparse matrix
      • Structured: remove layers, heads, etc
    • Key-value caching for Transformers
      • How to create/use a KV cache
      • Prefilling and decoding stages of generation
      • Restricted attention in Transformers: local vs global

​

​

​

​

✅

✅

5 of 85

Recap outline: Making models smaller

    • Distillation
      • Train a small model from a large one ✅
    • Quantization
      • Reduce precision in (parts of ) a model ✅
    • Model pruning
      • Unstructured: zero out some weights
      • Semi-structured: prune to N:M sparse matrix
      • Structured: remove layers, heads, etc
    • Key-value caching for Transformers
      • How to create/use a KV cache
      • Prefilling and decoding stages of generation
      • Restricted attention in Transformers: local vs global

​

​

​

​

6 of 85

Recap: Unstructured pruning

  • Unstructured pruning
    • zero out individual weights or neurons
      • anywhere in the model
    • re-train

- optionally repeat

  • Design decisions:
    • Which subset to prune?
    • How much to re-train, and on what data?
    • Do you iterate or not?
      • When do you stop?

​

​

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

7 of 85

Recap outline: Making models smaller

    • Distillation
      • Train a small model from a large one ✅
    • Quantization
      • Reduce precision in (parts of ) a model ✅
    • Model pruning
      • Unstructured: zero out some weights ✅
      • Semi-structured: prune to N:M sparse matrix
      • Structured: remove layers, heads, etc
    • Key-value caching for Transformers
      • How to create/use a KV cache
      • Prefilling and decoding stages of generation
      • Restricted attention in Transformers: local vs global

​

​

​

​

8 of 85

Recap: N:M pruning

  • Rank all weights
  • Compare weight scores to a “comparison set”
    • The four weights in a block
  • Drop the worse 2 of those 4 weights

N:M sparsity is supported by accelerator hardware

00, 11

9 of 85

Recap: N:M pruning

  • Rank all weights
  • Compare weight scores to a “comparison set”
    • The four weights in a block
  • Drop the worse 2 of those 4 weights

N:M sparsity is supported by accelerator hardware

00, 11,

01,10

10 of 85

Recap: WANDA Semi-structured pruning

comparison group = block of 4, always prune 2 from block

11 of 85

Recap outline: Making models smaller

    • Distillation
      • Train a small model from a large one ✅
    • Quantization
      • Reduce precision in (parts of ) a model ✅
    • Model pruning
      • Unstructured: zero out some weights ✅
      • Semi-structured: prune to N:M sparse matrix ✅
      • Structured: remove layers, heads, etc
    • Key-value caching for Transformers
      • How to create/use a KV cache
      • Prefilling and decoding stages of generation
      • Restricted attention in Transformers: local vs global

​

​

​

​

12 of 85

Recap: Shortened Llama

  • For each layer, compute increase in PPL on a calibration set if removed
    • Also use a gradient*weight metric, Taylor+
  • Prune layers one-shot to get target size
  • Retrain with LoRA

​

13 of 85

Recap: Minitron

  • Importance of neurons and attention heads: Wanda-like + aggregate

​

  • Importance of layers: PPL and “block importance” (~input/output similarity )

​

  • Retraining 🡪 distillation with intermediate losses

B,S = batch and sequence

14 of 85

Recap: Minitron

  • Importance of neurons and attention heads: Wanda-like + aggregate

​

  • Importance of layers: PPL and “block importance” (~input/output similarity )

​

  • Retraining 🡪 distillation with intermediate losses

B,S = batch and sequence

Heads, layers…

  • Prune, distill to retrain, iterate

15 of 85

Recap outline: Making models smaller

    • Distillation
      • Train a small model from a large one ✅
    • Quantization
      • Reduce precision in (parts of ) a model ✅
    • Model pruning
      • Unstructured: zero out some weights ✅
      • Semi-structured: prune to N:M sparse matrix ✅
      • Structured: remove layers, heads, etc ✅
    • Key-value caching for Transformers
      • How to create/use a KV cache
      • Prefilling and decoding stages of generation
      • Restricted attention in Transformers: local vs global

​

​

​

​

16 of 85

Recap: How to KV Cache

“Q: What is the first law? A: …”

17 of 85

Recap: KV caching is important

  • Inference with an LLM has two phases
    • Prefilling: very parallel
      • process the prompt and context
      • this can be very long and repetitive
        • system prompt, chain-of-thought examples
        • agentic context
      • caching repeated parts of a user’s input can save up to 90% of inference costs
        • this requires knowing the user is likely repeat parts of their queries, via API call params or guessing
    • Decoding: sequential
      • generate the response token-by-token

18 of 85

Recap: KV caching is important

  • Inference with an LLM has two phases
    • Prefilling: very parallel
      • process the prompt and context
      • this can be very long and repetitive
        • system prompt, chain-of-thought examples
        • agentic context
      • caching repeated parts of a user’s input can save up to 90% of inference costs
        • this requires knowing the user is likely repeat parts of their queries, via API call params or guessing
    • Decoding: sequential
      • generate the response token-by-token

19 of 85

Recap: Transformers Are KV-Cache Optimized

20 of 85

Recap: Restricting attention with KV caching

  • In key-value caching we restrict attention after training by evicting from the cache
  • This is a crucial method for long inputs
    • or outputs, e.g. reasoning models (O1,…)

​

  • Big question: what is the eviction policy?

​

21 of 85

Recap: Backstory in restricted attention

  • Key idea in ETC: split tokens into local and global
  • Attention is global-local, local-global, and local-local with locality constraints
  • Local-local attention is not a mask but a “gather”

​

22 of 85

Recap: “Heavy Hitters” in KV Caches

2023

23 of 85

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

24 of 85

Recap: “Heavy Hitters” in KV Caches

  • Proposed method
    • Fix the cache size to K
    • Generate tokens i=1, …, …
      • Track score (cumulative attention) of each KV position
        • “local H2 statistic” – cumulative attention up to position i
      • When the cache is full, overwrite the token with lowest local H2 score
        • The “eviction policy”
    • Local H2 statistic is close to full oracle H2 statistic that looks at future tokens

25 of 85

Recap: “Heavy Hitters” in KV Caches

26 of 85

Recap outline:Making models smaller

    • Distillation
      • Train a small model from a large one ✅
    • Quantization
      • Reduce precision in (parts of ) a model ✅
    • Model pruning
      • Unstructured: zero out some weights ✅
      • Semi-structured: prune to N:M sparse matrix ✅
      • Structured: remove layers, heads, etc ✅
    • Key-value caching for Transformers
      • How to create/use a KV cache ✅
      • Prefilling and decoding stages of generation ✅
      • Restricted attention in Transformers: local vs global vs predictive KV-cache eviction policy

​

​

​

​

27 of 85

Outline

​

  • Recap:
    • Making models smaller: Distillation, Quantization, Pruning
    • Key-Value Caching
  • KV Caching Eviction Policies
    • Heavy Hitters
    • Attention sinks – StreamingLLM
    • Predictive caching – SnapKV, FastGen
  • Discussion / review

​

​

​

28 of 85

Outline

​

  • Recap:
    • Making models smaller: Distillation, Quantization, Pruning
    • Key-Value Caching
  • KV Caching Eviction Policies
    • Heavy Hitters
    • Attention sinks – StreamingLLM
    • Predictive caching – SnapKV, FastGen
  • Discussion / review

​

​

​

29 of 85

Other ways of predicting attention

2024

30 of 85

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

31 of 85

StreamingLLM

  • Proposed method
    • Fix the cache size to K
    • Generate tokens i=1, …, …
      • Keep the first 4 tokens and the most recent K-4

​

red: stream LLM

​

orange: sliding window attention (local)

​

blue: dense attention

32 of 85

StreamingLLM and H2O

  • Proposed method
    • Fix the cache size to K
    • Generate tokens i=1, …, …
      • Keep the first 4 tokens and the most recent K-4

​

33 of 85

Outline

​

  • Recap:
    • Making models smaller: Distillation, Quantization, Pruning
    • Key-Value Caching
  • KV Caching Eviction Policies
    • Heavy Hitters
    • Attention sinks – StreamingLLM
    • Predictive caching – SnapKV, FastGen
  • Discussion / review

​

​

​

34 of 85

Predictive KV Caching: SnapKV

2024

35 of 85

Predictive KV Caching: SnapKV

  • Data: UltraChat
    • 1.4M sequences, selected dialog turns with prompt > 3k tokens, and response > 512 tokens
  • New observation about decoding phase:
    • The attention pattern for prompt tokens is consistent throughout decoding
    • The attention pattern for prompt tokens is predictable from LLM behavior before decoding starts

​

​

36 of 85

Predictive KV Caching: SnapKV

  • Example: Attn overlap between decoding and 128-tokens windows from the prompt
  • Each line is a layer
  • There is high overlap with the last window in the prompt

​

​

37 of 85

Predictive KV Caching: SnapKV

  • Example: Attn overlap between four 128-token windows in decoded response and last 128-token window in prompt

​

​

38 of 85

SnapKV: Details

  • Observation window: the n-th window in the prompt
  • Prefix: first n-1 windows in the prompt
  • SumAttn[head h, prefix position j]: attention weights
    • for head h to position j
    • summed over all positions in observation window
      • (Wobs in paper)
  • p: compression ratio, (e.g., 0.9)
  • Eviction policy: evict the KV cache entries for the bottom p*|Prefix| positions (for each head)
    • Refinement: also keep positions near a top (1-p) position (i.e., max-pool SumAttn locally) to get local attention

39 of 85

SnapKV: Experiment

  • “Needle-in-a-haystack” problem:
    • a long document with a sentence inserted randomly in the middle (e.g., recommend a coffeehouse in Pittsburgh in the middle of the Lord of the Rings)
    • a question answerable by the inserted sentence

40 of 85

Needle in a Haystack: Background

41 of 85

Needle in a Haystack: SnapKV results

42 of 85

Outline

​

  • Recap:
    • Making models smaller: Distillation, Quantization, Pruning
    • Key-Value Caching
  • KV Caching Eviction Policies
    • Heavy Hitters
    • Attention sinks – StreamingLLM
    • Predictive caching – SnapKV, FastGen
  • Discussion / review

​

​

​

43 of 85

Predictive KV Caching: FastGen

2024

44 of 85

Predictive KV Caching: FastGen

  • Caching policies explored in past work
    • Locality (Clocal)
      • hyperparam: rlocal = (#local tokens)/(cache size)
    • Heavy Hitter (Cfrequent)
      • hyperparam: rfrequent = (#HH tokens)/(cache size)
    • Special tokens (Cspecial)
      • Examples: start-of-sequence <s>, …
      • hyperparam: none
    • Punctuation (Cpunct)
      • Examples: period (.), colon (:), question mark (?), …
      • hyperparam: none
    • No eviction (Cfull)
    • Hybrid strategies: e.g., Cspecial + Clocal
      • union of the two caches

​

​

​

Prior analysis of BERT showed it often attends to separators

Also SepLLM showed separators + initial tokens are useful for KV-caching

45 of 85

Predictive KV Caching: FastGen

Which works best? It depends….

​

​

​

Different heads at level 20

46 of 85

Predictive KV Caching: FastGen

Which works best? It depends….

​

​

​

Same head different layers

47 of 85

Predictive KV Caching: FastGen

  • Which caching strategy to use?
    • Pick a policy for each head/layer based on the prefilling
    • Use that policy to initialize KV cache, and in decoding

48 of 85

Predictive KV Caching: FastGen Results

49 of 85

Outline

​

  • Recap:
    • Making models smaller: Distillation, Quantization, Pruning
    • Key-Value Caching
  • KV Caching Eviction Policies
    • Heavy Hitters
    • Attention sinks – StreamingLLM
    • Predictive caching – SnapKV, FastGen
  • Discussion / review

​

​

​

50 of 85

Discussion

  • Heavy Hitter Oracle (H2O):
    • Observations:
      • power-law of cumulative attn
      • running total of cumulative attn is good approximation
    • Strategy: evict lowest cumulative attn KV pairs (during decoding)
  • Streaming LLM:
    • Observation: first few tokens are “attention sinks”
    • Strategy: don’t evict the first few tokens (during decoding)
    • Experiment: H2O is a little better with StreamingLLM
  • SnapKV:
    • Observation: last window of prompt predicts attention during decoding
    • Strategy: compress the KV pairs from the prompt based on last-window attention before decoding
  • FastGen:
    • Observation: no uniform caching strategy is optimal
    • Strategy: pick a strategy for each head/layer (based on prompt)

​

51 of 85

Model compression: �Recap and Overview

52 of 85

How should we think about these?

  • Quantization
  • Pruning
  • Key-Value Cache Management
    • …which is also pruning

Heuristic: find a survey paper!

53 of 85

How should we think about these?

TACL 2024

54 of 85

55 of 85

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.

56 of 85

Recap: making a large model smaller

  • Distillation
    • briefly discussed
  • Quantization
  • Pruning
  • Key-Value Cache Management
    • …which is also pruning

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

57 of 85

Recap: making a large model smaller

  • Quantization
  • Pruning
  • Key-Value Cache Management

Old-school ML in practice:

  1. examine the data
  2. select/engineer features
  3. pick a simple learning/optimization method that worked for that task
    • sometimes invent a new optimization method
    • sometimes invent a new representation for models

58 of 85

Recap: making a large model smaller

  • Distillation
    • briefly discussed
  • Quantization
  • Pruning
  • Key-Value Cache Management
    • …which is also pruning

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 …)

  1. Manual rules for satisfying constraints
    • better rules based on data analysis
  2. Greedy search
    • better metrics
  3. More complex search
  4. Simple “learning”
  5. …

59 of 85

Quantization: Background

  • Working with even fp32 requires some care
    • E.g., accelerators support “fused multiply add” (FMA)
      • FMA(x,y,z)=round(x*y + z) != round(round(x*y) + z)
    • Dot product computation is chain of FMAs
  • FP16 usually is part of mixed precision training

​

  • Matmul precision can also be adjusted

​

optimizer accumulates gradients and scales by learning rate

Recap

Optimize parameter values via gradient descent (as usual) subject to constraint:

  • parameters are stored in bfloat16

60 of 85

Quantization: Beyond 16 bits

  • Going from fp32 🡪 int8 or int4 requires some tricks:
    • Quantize different parts of the model differently
      • quantize(x; S, Z) = round(x/S + Z)
        • S is “scale”
        • Z is “zero point”
        • S, Z are set for this model slice to get the needed range [⍺,β]
      • do as much as you can in quantized space instead of quantizing and de-quantizing frequently (the FMA trick)
        • complete matmul, conv2D-BatchNorm-ReLU
    • Quantize dynamically
      • set S, Z after you see the activation values
    • Don’t quantize everything
      • eg bias layers aren’t usually quantized

​

Recap

Optimize parameter values via gradient descent (as usual) subject to constraint:

  • groups of parameters are stored in int8/int4
  • multiple S,Z optimized independently by group
  • groups to be quantized: by manual rules

subset to be quantized is chosen with manually fixed rules (based on activation values)

  1. Optimize weights by training LLM
  2. Optimize quantization next (don’t retrain)

61 of 85

Quantization: Beyond 16 bits

  • Feature: any single dimension of a token representation
  • Outlier feature: magnitude >= 6 in 25% of the layers and 6% of token positions
  • Observation: outliers are
    • probabilistic in smaller models (in some layers and not others)
    • systematic in larger models (most layers)

Hypothesis: outlier features are why int8 stops working!

Recap

62 of 85

Quantization: Beyond 16 bits

  • Going from fp32 🡪 int8 or int4 requires some tricks:
    • Mixed-precision quantization – keep large “outlier” features (which are consistently in fixed locations)

​

Recap

Optimize parameter values via gradient descent (as usual) subject to constraint:

  • groups of parameters are stored in int8/int4
  • multiple S,Z optimized independently by group
  • groups to be quantized: by manual rules

subset to be quantized is chosen with manually fixed rules (based on activation values)

63 of 85

Quantization: Performance Tradeoffs

2024

Not a Recap

64 of 85

Quantization: Beyond 4 bits

  • Quantization-aware training
      • (de)quantization operations are not differentiable
      • partial solutions
        • approximate the ops
        • use “straight through estimation” (STE) of gradients
      • extreme quantization requires methods quantize vectors by combining vectors from a “codebook”
        • similar to product quantization
        • e.g. ”additive quantization”
      • learning should ideally jointly optimize the continuous parts (codebook values) and discrete parts (assignment of values to code)
        • this can’t be done with gradient descent only

​

  1. Optimize weights by training LLM
  2. Optimize quantization next
  3. Then retrain to jointly optimize weights and quantization strategy

Not a Recap

65 of 85

The model compression frontier

Gumbel-Softmax Quantization, April 2026

Riemannian Constrained Optimization, May 2026

Clever methods for gradient-based optimization for discrete choices

66 of 85

Recap: making a large model smaller

  • Distillation
    • briefly discussed
  • Quantization
  • Pruning
  • Key-Value Cache Management
    • …which is also pruning

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

67 of 85

Recap: making a large model smaller

  • Distillation
    • briefly discussed
  • Quantization
  • Pruning
  • Key-Value Cache Management
    • …which is also pruning

68 of 85

Unstructured pruning

  • Observations (on CNNs):
    • pruning only occasionally causes major degradation in performance
    • performance recovers quickly with re-training
    • performance only slightly degrades even with lots of sparsity

​

​

  • For each layer to prune:
    • Repeat i=1,…,t:
      • Sort weights by |wj|
    • Zero* out weights to reach sparsity si
      • *by adjusting a binary mask
    • Re-train for n steps (also adjusting learning rate)

​

Recap

Optimize parameter while minimizing NNZ weights by alternating

  1. reducing NNZ weights (greedily)
  2. optimizing NZ weights (gradient)

69 of 85

Unstructured pruning: Wanda

  • Design decisions:
    • Which subset to prune?
    • How much to re-train, and on what data?
    • Do you iterate or not?
      • When do you stop?

​

​

Recap

Optimize parameter while minimizing NNZ weights by alternating

  1. reducing NNZ weights (greedily, with weights times activations)
  2. optimizing NZ weights (gradient)

70 of 85

What sparse operations are supported?

  • Nvidia supports 2:4 sparse matrices
    • General version is “N:M”
    • In each contiguous block of 4 weights at least 2 are zero.

Recap

71 of 85

What sparse operations are supported?

  • Nvidia supports 2:4 sparse matrices
    • General version is “N:M”
    • In each contiguous block of 4 weights at least 2 are zero.

Speeds for WANDA using semi-structured N:M pruning

​

Recap

Optimize parameter while minimizing NNZ weights by alternating

  1. reducing NNZ weights (greedily, with weights times activations, in a comparison group)
  2. optimizing NZ weights (gradient)

72 of 85

Structured Pruning: Shortened Llama

  • Approach
    • For each layer, compute increase in PPL on a calibration set if removed
    • Also use a gradient*weight metric, Taylor+
    • Prune layers one-shot to get target size
    • Retrain with LoRA

Recap

Optimize parameter while reducing # layers:

  1. reducing layers (greedily)
  2. optimizing remaining layers (LoRA)

73 of 85

Structured Pruning: Sheared Llama

  • Some key ideas:
    • Prune to a particular target architecture
      • Optimize a loss that includes PPL on a validation set + loss indicating how masks are mismatched to target architecture
      • Use Lagrange multipliers and soft approximation of the mask in training (slow!)

74 of 85

Structured Pruning: Sheared Llama

  • Some key ideas:
    • Prune to a particular target architecture
      • Pruning and retraining are done in the same optimization pass
      • Retrain to a ”reference loss” predicted by scaling laws.
      • In pruning/retraining, focus on high-loss slices of the data.

​

Use gradients with Lagrange multipliers to jointly optimize perplexity and distance to a valid mask

75 of 85

Recap: making a large model smaller

  • Distillation
    • briefly discussed
  • Quantization
  • Pruning
  • Key-Value Cache Management
    • …which is also pruning

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!

76 of 85

Recap: making a large model smaller

  • Distillation
    • briefly discussed
  • Quantization
  • Pruning
  • Key-Value Cache Management
    • …which is also pruning
      • … pruning parts of the key-value cache

77 of 85

H2O: “Heavy Hitters” in KV Caches

  • Proposed method
    • Fix the cache size to K
    • Generate tokens i=1, …, …
      • Track score (cumulative attention) of each token in the cache
        • “local H2 statistic” – cumulative attention up to position i
      • When the cache is full, overwrite the token with lowest local H2 score
        • (Attention to recent-past tokens keeps tokens from being evicted too quickly)
      • The“eviction policy”
    • Local H2 statistic is close to full oracle H2 statistic that looks at future tokens

Recap

Greedy pruning (eviction) based on running estimate of cumulative attention

78 of 85

StreamingLLM

  • Proposed method
    • Fix the cache size to K
    • Generate tokens i=1, …, …
      • Keep the first 4 tokens and the most recent K-4

​

red: stream LLM

​

orange: sliding window attention

​

blue: dense attention

Recap

Eviction is FIFO with an exception for first few tokens

79 of 85

StreamingLLM and H2O

  • Proposed method
    • Fix the cache size to K
    • Generate tokens i=1, …, …
      • Keep the first 4 tokens and the most recent K-4

​

Recap

Eviction is H2O rule with an exception for first few tokens

80 of 85

SnapKV: Details

  • Observation window: the n-th window in the prompt
  • Prefix: first n-1 windows in the prompt
  • SumAttn[head h, prefix position j]: attention weights
    • for head h to position j
    • summed over all positions in observation window
      • (Wobs in paper)
  • p: compression ratio, (e.g., 0.9)
  • Caching strategy: evict the KV cache entries for the bottom p*|Prefix| positions (for each head)
    • Refinement: also keep positions near a top (1-p) position (i.e., max-pool SumAttn locally)

Recap

Eviction for a prompt is based on a score learned from the observation window for that prompt

81 of 85

Predictive KV Caching: FastGen

2024

Recap

82 of 85

Predictive KV Caching: FastGen

  • Caching policies explored in past work
    • Locality (Clocal)
      • hyperparam: rlocal = (#local tokens)/(cache size)
    • Heavy Hitter (Cfrequent)
      • hyperparam: rfrequent = (#HH tokens)/(cache size)
    • Special tokens (Cspecial)
      • Examples: start-of-sequence <s>, …
      • hyperparam: none
    • Punctuation (Cpunct)
      • Examples: period (.), colon (:), question mark (?), …
      • hyperparam: none
    • No eviction (Cfull)
    • Hybrid strategies: e.g., Cspecial + Clocal
      • union of the two caches

​

​

​

Prior analysis of BERT showed it often attends to separators

Also SepLLM showed separators + initial tokens are useful for KV-caching

Recap

83 of 85

Predictive KV Caching: FastGen

  • Which caching strategy to use?
    • Pick a policy for each head/layer based on the prefilling
    • Use that policy to initialize KV cache, and in decoding

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)

84 of 85

Recap: making a large model smaller

  • Distillation
    • briefly discussed
  • Quantization
  • Pruning
  • Key-Value Cache Management

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

85 of 85

Recap: making a large model smaller

  • Quantization
  • Pruning
  • Key-Value Cache Management

Old-school ML in practice:

  1. examine the data
  2. select/engineer features
  3. pick a learning/optimization method that works
    • sometimes invent a new method