Cartridges: Lightweight and general-purpose long context representations
  via self-study
Large language models are often used to answer queries grounded in large text
corpora (e.g. codebases, legal documents, or chat histories) by placing the
entire corpus in the context window and leveraging in-context learning (ICL).
Although current models support contexts of 100K-1M tokens, this setup is
costly to serve because the memory consumption of the KV cache scales with
input length. We explore an alternative: training a smaller KV cache offline on
each corpus. At inference time, we load this trained KV cache, which we call a
Cartridge, and decode a response. Critically, the cost of training a Cartridge
can be amortized across all the queries referencing the same corpus. However,
we find that the naive approach of training the Cartridge with next-token
prediction on the corpus is not competitive with ICL. Instead, we propose
self-study, a training recipe in which we generate synthetic conversations
about the corpus and train the Cartridge with a context-distillation objective.
We find that Cartridges trained with self-study replicate the functionality of
ICL, while being significantly cheaper to serve. On challenging long-context
benchmarks, Cartridges trained with self-study match ICL performance while
using 38.6x less memory and enabling 26.4x higher throughput. Self-study also
extends the model's effective context length (e.g. from 128k to 484k tokens on
MTOB) and surprisingly, leads to Cartridges that can be composed at inference
time without retraining.
6847b4b43ec10bdd8ab4df33
Sabri Eyuboglu
extracted_pending
2025-06-10T04:29:41.818Z
6337537b267cee4d068f604d
/avatars/15267f0759a6570c98ee6a150558fcc0.svg
Sabri Eyuboglu
user
sabrieyuboglu
6847b4b43ec10bdd8ab4df34
Ryan Ehrlich
6847b4b43ec10bdd8ab4df35
Simran Arora
6847b4b43ec10bdd8ab4df36
Neel Guha
6847b4b43ec10bdd8ab4df37
Dylan Zinsley
6847b4b43ec10bdd8ab4df38
Emily Liu
6847b4b43ec10bdd8ab4df39
Will Tennien
6847b4b43ec10bdd8ab4df3a
Atri Rudra
6847b4b43ec10bdd8ab4df3b
James Zou
6847b4b43ec10bdd8ab4df3c
Azalia Mirhoseini
6847b4b43ec10bdd8ab4df3d
Christopher Re
Cartridges: Lightweight and general-purpose long context representations
  via self-study
Large language models are often used to answer queries grounded in large text
corpora (e.g. codebases, legal documents, or chat histories) by placing the
entire corpus in the context window and leveraging in-context learning (ICL).
Although current models support contexts of 100K-1M tokens, this setup is
costly to serve because the memory consumption of the KV cache scales with
input length. We explore an alternative: training a smaller KV cache offline on
each corpus. At inference time, we load this trained KV cache, which we call a
Cartridge, and decode a response. Critically, the cost of training a Cartridge
can be amortized across all the queries referencing the same corpus. However,
we find that the naive approach of training the Cartridge with next-token
prediction on the corpus is not competitive with ICL. Instead, we propose
self-study, a training recipe in which we generate synthetic conversations
about the corpus and train the Cartridge with a context-distillation objective.
We find that Cartridges trained with self-study replicate the functionality of
ICL, while being significantly cheaper to serve. On challenging long-context
benchmarks, Cartridges trained with self-study match ICL performance while
using 38.6x less memory and enabling 26.4x higher throughput. Self-study also
extends the model's effective context length (e.g. from 128k to 484k tokens on
MTOB) and surprisingly, leads to Cartridges that can be composed at inference
time without retraining.
Training a smaller, offline KV cache (Cartridge) with a context-distillation objective (self-study) for large language models reduces serving costs, matches ICL performance, and extends effective context length.
KV cache Cartridge in-context learning (ICL) self-study context-distillation objective MTOB