Abstract
The Multi-Head Attention mechanism is central to LLM operation, and multiple works target its compute and memory efficiency during training. While most works focus on approximating the scaled dot product, the memory consumption of the linear projections that compute the $Q$, $K$, and $V$ tensors from the input $x$ is often overlooked. To address this, we propose Point-Approximate Matrix Multiplication (PAMM), a novel tensor compression technique that reduces memory consumption of the $Q,K,V$ projections in attention layers by a factor of up to $\times 512$, effectively erasing their memory footprint, while achieving similar or better final perplexity. PAMM is fully composable with efficient attention techniques such as FlashAttention, making it a practical and complementary method for memory-efficient LLM training.
Introduction
Training Large Language Models (LLMs) is a memory-intensive process, primarily bottlenecked by the requirement to store activations for the backward pass. In a standard transformer architecture, every linear layer $Y = XW$ necessitates storing the input $X$ to compute the weight gradient $\nabla W = X^T \nabla Z$. While significant effort has been directed toward optimizing the attention mechanism itself (e.g., FlashAttention) or reducing optimizer state overhead, the linear projections for Query ($Q$), Key ($K$), and Value ($V$) are often neglected. These projections can account for up to 20% of peak GPU memory in typical LLM training scenarios.
Existing compression techniques often focus on reducing the hidden dimension. However, this work identifies that the primary redundancy in LLM activations resides in the sequence dimension. Due to local context, padding, and inherent data patterns, many tokens within a batch are highly similar.
Point-Approximate Matrix Multiplication (PAMM)
We introduce Point-Approximate Matrix Multiplication (PAMM), a two-stage strategy designed to approximate the gradient calculation $\nabla W = X^T \nabla Z$ by exploiting sequence redundancy.
Compression in the Forward Pass
Instead of storing the full input matrix $X \in \mathbb{R}^{b \times n}$ (where $b$ is the number of tokens), PAMM selects a small subset of $k$ "generator" tokens ($k \ll b$). These generators are sampled randomly from the batch. Each remaining token is then approximated as a scaled version of its nearest generator. Consequently, the hardware only needs to store the small set of generators, an assignment map, and a vector of scaling factors $\alpha_i$.
Efficient Backpropagation
During the backward pass, PAMM avoids the costly reconstruction of the full matrix $X$. Instead, it "contracts" the incoming gradients $\nabla Z$ into a compressed shape that aligns with the generators. The final gradient $\nabla W$ is computed using these compressed representations, significantly reducing computational overhead and memory access. Unlike traditional low-rank methods that utilize random projections (e.g., Gaussian noise), PAMM leverages actual data points from the input, which preserves more structural information.
Experimental Evaluation
The efficacy of PAMM was evaluated across several scales and tasks:
- Pretraining: LLaMA models (60M to 7B parameters) trained on the C4 dataset.
- Finetuning: RoBERTa-base evaluated on the GLUE benchmark.
- Multimodal/PEFT: Pixtral-12B Vision-Language Model (VLM) finetuned on the AID satellite image classification benchmark using LoRA.
Key Results and Insights
PAMM achieves massive memory savings, reducing the footprint of $Q, K, V$ activations by over 97%. In specific configurations, activations were compressed by a factor of $\times 512$ with negligible impact on model accuracy.
Performance and Scalability
On the GLUE benchmark, RoBERTa-base with PAMM achieved an average score of 86.18, nearly identical to the full fine-tuning baseline (86.28), while utilizing 85x less memory for the targeted layers. Furthermore, the throughput overhead is minimal; for a 1B parameter model, training throughput decreased by only 2.7%.
A significant theoretical finding is that as batch sizes increase, the number of required generators only needs to grow logarithmically to maintain accuracy. This makes PAMM exceptionally scalable for large-scale training. Interestingly, in several pretraining experiments, PAMM-trained models achieved lower (better) perplexity than full-rank baselines, suggesting that the approximation acts as a beneficial form of regularization.
Limitations and Future Work
Currently, PAMM is not applied to the output projection of the attention block, as modern implementations like FlashAttention share that activation with the attention mechanism itself. Future work involves deeper integration into FlashAttention kernels to address this. Additionally, while random sampling is effective, more strategic generator selection could potentially improve approximation quality at extreme compression ratios. Extending PAMM to Feed-Forward Network (FFN) layers, which consume substantial memory, remains a promising direction for future research.
Summary updated