10-605 / 10-805
Machine Learning from Large Datasets
Recap of Monday
Outline
Outline
Performance analysis: Why MQA
Notation (one query):
Fast Transformer Attention: … Shazeer 2019 https://arxiv.org/pdf/1911.02150
construct the query q for x
aside: P_q = what we called WQ
construct keys and values from M
dot prod similarities and attn scores
attn-weighted sum of values
project back to dimension of x
parallel over all heads
Performance analysis
Notation:
Encoder / prefilling: batched MHA with batches of different positions in a sequence
construct the query Q for X
construct keys and values from M
dot prod similarities and attn scores
attn-weighted sum of values
project back to dimension of x
Performance analysis
Notation:
Assume
Encoder / prefilling: batched MHA with batches of different positions in a sequence
FLOPS: O(bnd2)
Matmul: mk,kn 🡪 mn uses mnk2 FLOPS
Q: bnd,dkh 🡪 bhnk
= bnd,d(d/h)h 🡪 bhn(d/h)
= bnd,dd matmul uses bnd2 FLOPS
Performance analysis
Notation:
Assume
Encoder / prefilling: batched MHA with batches of different positions in a sequence
Memory:
O(bnd) +
O(bhn2) +
O(d2)
…because
X,M,Q,K,V,O,Y
logits, weights
P’s
FLOPS: O(bnd2)
Performance analysis
Encoder / prefilling: batched MHA with batches of different positions in a sequence
Memory:
O(bnd) +
O(bhn2) +
O(d2)
…because
X,M,Q,K,V,O,Y
logits, weights
P’s
FLOPS: O(bnd2)
Claim: FLOPs/sec <= FLOPs/byte * bytes/sec
moving data from HBM to Matmul units is “slow”
This is nice and low!
Recap: LLM inference
Performance analysis
Notation:
Decoding: extend KY cache K and V
construct the query q for x
compute new keys and values and
update key-value cache
attn-weighted sum of values
project back to dimension of x
Performance analysis
Decoding: extend KY cache K and V
construct the query q for x
compute new keys and values and
update key-value cache
attn-weighted sum of values
project back to dimension of x
More memory transfer
Less compute
This is not small if n is large … which it is for RAG/FiD
Fusion in Decoder (FiD)
FLOP analysis: Encoder is 6x as expensive as decoder!
…but at inference time decoding is slowest. Why?
Predicted by counting FLOPS for all the matmuls and assuming nt << ns and nt << d
Predicted by memory/FLOPs!
Outline
LUMEN: FiD with caching
…
LUMEN: FiD with caching
question
…
lookup
LUMEN: FiD with caching
The first N-K layers of the FiD encoder
The last K layers of the FiD encoder
FiD decoder
Passages are encoded and stored off-line for every document
LUMEN: FiD with caching
As you scale up you can do a larger fraction of the work off-line
LUMEN: FiD with caching
Using 2/3 offline and 1/3 live is better than doing everything off-line
LUMEN: FiD with caching
As you scale up there are larger benefits from doing the off-line computation
Outline
GLIMMER: LUMEN with reranking
2023
Recap: Cross-Encoders
query
i-th candidate
c1, c2, … cN
relevance of i-th candidate to query
Recap: LUMEN=FiD with caching
Similar to cross-encoding
Except for using LUMEN’s trick of pre-computing the first few layers of the encodings independently
GLIMMER=LUMEN with reranking
Trained with “perplexity distillation loss”
log pLM = perplexity of answer a for a decoder using only di, q
train to reduce KL between predicted scores and pk – w a temperature in the softmax
GLIMMER=LUMEN with reranking
Trained with “perplexity distillation loss”
Only the top few documents are presented to the decoder
GLIMMER=LUMEN with reranking
select top 5
of 25 retrieved
GLIMMER=LUMEN with reranking
Average performance on multiple tasks from the KILT dataset
Retrieve 25 passages, rerank, and decode with top 5
Outline
not the “dumbest thing possible”
RETRIEVAL WITH DECODER-ONLY LLMS
Recap: Discussion of DPR
Decoder only
Discussion of DPR
Encoder only
Decoder only
Encoder-decoder
But … everybody is working on improving decoder-only LLMs, so it would be great if we could use them!
How can you use a Decoder-Only LLM to Improve Retrieval?
2023
Hypothetical Document Embedding (HyDE)
Recap: Discussion of DPR
2022
RECAP
RECAP
Language Model as Retriever (LameR)
https://arxiv.org/pdf/2304.14233 2023 Shen et al
Outline
ExpandR
EMNLP 2025
ExpandR
loosely interpreted
ExpandR
ExpandR
RL: doesn’t need dq but does need preferences dq1 > dq2
ExpandR: DPO Background
where:
ExpandR: DPO Background
Note the gradient of the loss looks like this:
where:
ExpandR
*and some other tricks
loosely interpreted
ExpandR: Results
Outline
Decoder-only models as encoders?
2023
2025
PromptEOL
Echo embeddings
PromptEOL: Key ideas
This sentence: “x” means in one word:
Echo embeddings: key ideas
Rewrite the sentence: x; rewritten sentence: x
Outline
“FID” WITH DECODER-ONLY LLMS
Main ideas in FiD and extensions
FlashAttention (2023) and FlexAttention (2024)—also improve decoder bottlenecks
Parallel Context Windows (PCW) - 2023
TurboRAG, Blockwise Sparse Attention - 2024
Dynamic Blockwise Sparse Attention - 2025
Analog for decoder-only LLMs
2023
Key idea: cross-attend within a context window, and cross-attend between task tokens and all context windows.
Very similar to FiD
2023
Key idea: cross-attend within a context window, and cross-attend between task tokens and all context windows.
Very similar to FiD
Good results for NQ (vs conventional RAG system) and ICL (especially classification with many classes)
Implemented with attention masks rather than parallel generation of keys and values
2024
Key idea: same as PCW except
TTFT = Time To First Token
FLOPS also for first token
2025
Key idea: same as Block-Attention except
DBSA: Details
Baseline: many-shot learning
DBSA: Details
Dynamic example selection
DBSA: Results
Total latency including set-up time
DBSA: Results
TurboRAG EMNLP 2025
Similar plan as DBSA
TurboRAG
KV Retrieval vs KV Cache Eviction