Cartridge
7 memberslucid.peft.tuners.cartridgelucid.peft.tuners.cartridge — Cartridge: a trained key-value cache that stands in for a long document.
Cartridge (Eyuboglu et al., 2025, arXiv:2506.06266) is a trained key-value cache: num_virtual_tokens
learned key and value pairs per attention layer, put in front of the model's own in place of a long
document it would otherwise read at every query. It is trained by self-study, with the model
answering questions about the document, and a Cartridge for a corpus costs a fraction of the memory
of the corpus in context. Pick it for serving many queries over one large, unchanging document.
The cache is laid out and applied as prefix tuning's is, but it is stored directly, not produced by
a projection, so a Cartridge can be started from the keys and values the model makes of a text
(initialize_kv_prefix_from_text) and several can be joined (compose_cartridge_adapters). The
first num_frozen_tokens rows are never trained: the paper keeps one as an attention sink.
Here: CartridgeEncoder (the cache, trained) and CartridgeModel (the tuner), the config, and
the four utilities of lucid.peft.tuners.cartridge.utils. CartridgeConfig, CartridgeEncoder
and the utilities are exported from lucid.peft, as the reference exports them; the tuner is not,
the reference having no model class. Importing the package registers the method (its config under
PeftType.CARTRIDGE, its tuner and encoder), which is what makes get_peft_model and
PeftModel.from_pretrained know it.
Eyuboglu, Sabri, et al. "Cartridges: Lightweight and General-Purpose Long Context Representations via Self-Study." [arXiv:2506.06266](https://arxiv.org/abs/2506.06266), 2025.
A Cartridge (Eyuboglu et al., 2025, arXiv:2506.06266 — Cartridges: Lightweight and general-purpose long
context representations via self-study) is a trained key-value cache. num_virtual_tokens learned
key/value pairs per attention layer are put in front of the model's cache, in place of a long document the
model would otherwise read at every query. The first num_frozen_tokens of them stay fixed; the paper
recommends freezing one as an attention sink. The cache is laid out as in prefix tuning, and starting it from
text or from a past cache is a separate step.
Classes
CartridgeConfigHow lucid.peft.get_peft_model adapts a model with Cartridge.
CartridgeEncoder14 methodsA cache of keys and values that is trained, as a matrix of rows (one per virtual token) of every layer's key and value.
CartridgeModel11 methodsThe tuner of Cartridge: a CartridgeEncoder per adapter, read as every layer's cached keys and values.
Functions
compose_cartridge_adapters→ NoneJoin saved Cartridges into one by laying their caches end to end.
initialize_kv_prefix_from_past_key_values→ TensorStart a Cartridge (or an unprojected prefix) from the keys and values of a cache you have.
initialize_kv_prefix_from_text→ TensorStart a Cartridge from a text: read it with the model, and keep the first keys and values.
prompt_embeddings_from_past_key_values→ TensorPack the first keys and values of a cache into the matrix an adapter file holds.