QKV Projections Require a Fraction of Their Memory

Malik Khalaf, Yara Shamshoum, Nitzan Hodos, Yuval Sieradzki, Assaf Schuster

TL;DR

Training Large Language Models (LLMs) is notoriously memory-intensive, often bottlenecked by storing activation tensors for the backward pass. This paper introduces Point-Approximate Matrix Multiplication (PAMM), a novel tensor compression technique that slashes the memory footprint of $Q, K, V$ projection activations by up to $512\times$ with virtually no loss in model accuracy. Fully compatible with FlashAttention, PAMM offers a practical, plug-and-play solution for memory-efficient LLM training.

What Problem Does This Paper Address?

When training transformer-based LLMs, the forward pass must save intermediate activation tensors so they can be used to compute gradients during the backward pass. While recent innovations like FlashAttention have successfully optimized the memory bottleneck of the scaled dot-product operation itself, the linear layers that project the input embeddings into the Query ($Q$), Key ($K$), and Value ($V$) tensors are frequently ignored.

Storing these input activations ($X$) across multiple layers can account for up to 20% of the peak GPU memory within attention blocks. Existing activation compression methods typically target redundancies in the hidden (embedding) dimension, which can severely degrade model performance. This paper tackles this oversight by exploiting a much more abundant source of redundancy: the sequence (token) dimension.

Methods

The authors propose Point-Approximate Matrix Multiplication (PAMM), a data-dependent tensor compression method designed to approximate the gradient computation ($\nabla W = X^\top \nabla Z$) during backpropagation without storing the full activation matrix $X$.

  1. Random Sampling as Generators: Instead of storing all $b$ tokens in a batch, PAMM randomly samples a tiny fraction $k = r \cdot b$ of tokens (where $r$ is the compression ratio, e.g., $1/512$) to act as a "generating set" $C$. This completely avoids computationally heavy clustering algorithms like K-Means.
  2. Line Projection: Each original token activation is approximated by finding its closest point on the line spanned by the most similar generator in $C$ (determined via cosine similarity).
  3. Compressed Storage: Instead of the full matrix, only the small generator matrix $C$, an assignment mapping vector $f$, and a scaling coefficient vector $\alpha$ are stored.
  4. Efficient Backpropagation: During the backward pass, PAMM avoids reconstructing the full matrix. Instead, it mathematically restructures the matrix multiplication by first contracting the incoming gradient matrix using the stored assignments and scales, and then multiplying it by $C$, drastically reducing both computational and memory overhead.
Figure 2: Overview of training with PAMM. In a standard linear layer, backpropagation multiplies the upstream gradient by the input X to compute the gradient with respect to the parameters ∇W = X⊤·∇Z. In our method, for the WQ, WK, WV projections, we store a compressed version of X and approximate the gradient-input matrix multiplication with PAMM. Here, b denotes the total number of tokens in a training batch. Pseudocode is provided in Appendix A.

Datasets

The authors evaluated PAMM across three distinct training paradigms:

  • Pretraining: LLaMA models (ranging from 60M to 7B parameters) pretrained on the C4 (Colossal Clean Crawled Corpus) dataset.
  • Finetuning: RoBERTa-base evaluated on the GLUE (General Language Understanding Evaluation) benchmark.
  • Multi-Modal / PEFT: Pixtral-12B Vision-Language Model (VLM) combined with LoRA finetuning on the AID (Aerial Image Dataset) satellite image classification benchmark.

Key Insights and Ideas

  • Sequence Dimension Redundancy: Tokens within a training batch are highly redundant due to repeated language patterns, padding tokens, and local contextual similarities. This makes the sequence dimension a much safer target for aggressive compression than the embedding dimension.
  • Random Selection Suffices: Intuitively, finding optimal representative points sounds like a clustering problem (like K-Means), which would be too slow to run on-the-fly during training. Remarkably, the authors prove both theoretically and empirically that simply picking tokens at random provides an excellent generating set.
  • Less Constraint is Better: The algorithm includes a neighborhood tolerance parameter ($\varepsilon$) to discard poorly approximated tokens. However, empirical testing revealed that setting $\varepsilon \to \infty$ (enforcing no neighborhood constraint and mapping every token to its closest generator) actually yields the best training stability and perplexity.
  • PAMM as a Regularizer?: For larger models (like LLaMA-1B and 7B), training with PAMM actually improved (decreased) final perplexity compared to the full-rank baseline. This suggests that removing redundant token information acts as a form of regularization, preventing the model from overfitting to noisy or repetitive activation data.

Key Results

  • Massive Memory Savings: PAMM reduces the peak GPU memory consumed by $Q, K, V$ activations by over 97% across all model sizes. For instance, in LLaMA-1B, activation memory dropped from 3 GB to just 24 MB ($125\times$ reduction at $r=1/512$).
  • Preserved (or Improved) Performance: On LLaMA-1B pretraining, PAMM with $r=1/512$ achieved a perplexity of 15.36 compared to the baseline's 15.56. On the GLUE benchmark with RoBERTa-base, PAMM maintained an average score of 86.18% (vs. 86.28% full fine-tuning) while slashing projection activation memory from 288 MB to 3.37 MB.
  • Negligible Throughput Overhead: While compression adds extra steps, the reduction in matrix multiplication sizes compensates for it. As models scale up, the runtime overhead diminishes significantly: throughput degradation was only 2.67% for the 1B model and a tiny 2.1% for the 7B model.

Perplexity across model sizes Peak attention memory across model sizes

Limitations and Future Work

  • Output Projections Untouched: PAMM is currently only applied to the input projections ($Q, K, V$). It leaves the attention block's output projection layer untouched. This is because the output activation tensor is shared directly with FlashAttention, and compressing it would alter the gradients flowing back into the attention mechanism, potentially causing error accumulation.
  • Strategic Generator Selection: While random sampling works surprisingly well, the authors note that more sophisticated, sub-quadratic strategies for choosing the generating set $C$ could yield even better error bounds.
  • Extension to Other Layers: Future work includes extending this point-approximate matrix multiplication approach to other heavy linear layers within transformers, such as the Feed-Forward Network (FFN) blocks.

Summary updated

BibTeX
@inproceedings{khalaf2026qkv,
  author = {Malik Khalaf and Yara Shamshoum and Nitzan Hodos and Yuval Sieradzki and Assaf Schuster},
  title = {{QKV Projections Require a Fraction of Their Memory}},
  booktitle = {International Conference on Learning Representations},
  year = {2026},
  url = {https://openreview.net/forum?id=Xvpk1g02u2},
}
Figure