TensorGPT: Efficient Tensor-Train Compression for LLMs
- TensorGPT is a tensor compression method that replaces high-dimensional parameter matrices with a series of low-dimensional tensor cores to reduce memory usage.
- The approach employs TT-SVD and matrix product state techniques to achieve up to 38.4× compression, significantly easing deployment on resource-constrained hardware.
- It integrates end-to-end training and optimized forward/backward propagation strategies, maintaining robust language modeling performance despite dramatic parameter reductions.
TensorGPT refers to a class of compression approaches for LLMs, particularly those within the GPT family, based on tensor-train decomposition (TTD) and matrix product state (MPS) representations. TensorGPT targets drastic reductions in model memory and storage requirements—making transformer architectures feasible for deployment on edge or resource-constrained devices—by exploiting the inherent low-rank structure of both token embeddings and weight matrices. It also includes schemes for end-to-end training and inference with tensorized layers. The fundamental innovation lies in replacing high-dimensional parameter matrices with a sequence of low-dimensional "cores," yielding significant parameter compression while preserving language modeling capacity (Xu et al., 2023, Chekalina et al., 2023).
1. Challenges in LLMs and Token Embeddings
State-of-the-art LLMs such as GPT-2 allocate a substantial portion of total parameters to the token embedding matrix. For instance, GPT-2's embedding table (with , ) constitutes approximately 31% of its overall 1.5 B parameters. The resulting tens of millions of parameters in not only increase storage burdens but also preclude on-device deployment, such as on a Raspberry Pi, which is restricted by limited RAM/flash capacity. The situation is aggravated if the vocabulary is dynamic, as naïvely recomputing a full SVD for every new token insertion is computationally infeasible (Xu et al., 2023).
These bottlenecks also affect the fully connected layers in the Transformer’s feed-forward blocks, where each linear projection contains millions of parameters—complicating training, storage, and inference, especially for non-datacenter applications (Chekalina et al., 2023).
2. Tensor-Train Decomposition and Matrix Product States
Tensor-Train Decomposition (TTD), introduced by Oseledets (2011), expresses high-dimensional tensors as products of cores , each of size , with . The representation is:
In physics, this format is known as the Matrix Product State (MPS). TT-SVD, a sequential SVD procedure, facilitates automated extraction of these cores (see Alg. 1 in (Xu et al., 2023)). By choosing the mode sizes 0 and number of cores 1 to approximate the original dimension and by truncating SVDs to lower TT-ranks, substantial parameter compression is achieved.
For weight matrices 2, a closely related Tensor Train Matrix (TTM) factorization views 3 as a 4-way tensor and factorizes it into 5 matrix-valued TT cores, reducing storage from 6 to a sum scaling as 7, where 8 is the uniform TT-rank and 9, 0 are mode sizes for input/output (Chekalina et al., 2023).
3. Methodology and Implementation in TensorGPT
Token Embedding Compression (MPS Approach)
Given the embedding matrix 1, TensorGPT compresses each token embedding 2 as follows:
- Padding & Tensorization: Pad 3 to a product of small mode sizes, ideally a power of two. For GPT-2, 4 is padded to 5, giving 6, 7.
- Per-token MPS/TT-SVD: Reshape 8 to an order-9 tensor 0 and perform TT-SVD, producing cores 1 for 2.
- Storage: Retain the set of TT cores across all tokens, vastly reducing memory versus storing the dense 3 (Xu et al., 2023).
This per-token compression is training-free, requires no extra data, and leverages a scan over TT-rank choices 4 (e.g., 5) to trade off reconstruction accuracy and storage.
Tensor Train Matrix for Projections
For fully-connected layers, the Tensor Train Matrix (TTM) representation proceeds as follows:
- Reshape: 6 is viewed as a 7-way tensor, dimensions 8; 9.
- TTM Factorization: 0, where each 1 is a rank-2 four-way core.
- Forward and Backward Propagation: Efficient einsum-based forward contraction and custom memory-aware backward passes are implemented. The optimal (Einsum forward + Full-Matrix backward) reduces per-layer gradient memory from 31 GB to 4192 MB (Chekalina et al., 2023).
4. Parameter Reduction and Empirical Performance
Embedding Layer Compression
Theoretical compression ratio is:
5
For typical choices (6, 7 for 8), this yields 9, i.e., a 3.31-fold reduction. Aggressive choices (0) can achieve up to 1 compression (Xu et al., 2023). For GPT-2, this method theoretically results in 2 fewer total model parameters, with a compression ratio 3 for the embedding layers.
| Method | TT-ranks | η (×) | Generation Loss |
|---|---|---|---|
| Original | – | 1.00 | 13.71 |
| Direct TT on 4 (2-core) | [1,32,1] | 23.64 | 10.14 |
| MPS on each 5 | [1,2,4,\ldots,4,2,1] | 3.31 | 9.01 |
| MPS on each 6 (max η) | [1,1,...,1] | 38.40 | 20.77 |
A compression of 7 yields a lower generation loss (9.01) than the original (13.71), indicating slight regularization from the low-rank approximation. Maximal compression reduces performance but maintains core semantic fidelity (Xu et al., 2023).
TTM for Feed-Forward Layers
By replacing GPT-2’s dense MLP matrices with TTM layers, the following parameter reductions and effects on perplexity are observed (Chekalina et al., 2023):
| Model | #Params (M) | % of Baseline | Perplexity |
|---|---|---|---|
| GPT-2 Small | 124.4 | 100% | 17.55 |
| TTM-16 | 68.1 | 54% | 21.33 |
| TTM-64 | 83.6 | 67% | 18.08 |
A 40% size reduction leads to a perplexity increase of only ≈3.2, with downstream GLUE and summarization performance matching or slightly underperforming standard GPT-2 and surpassing SVD-compressed and distilled baselines.
5. Computational Complexity and Hardware Implications
The offline TT-SVD compression for embeddings has 8 per token cost. Online reconstruction requires 9 per token, and storage is reduced to 0, which is significantly less than the 1 for the original matrices. For hardware-limited environments, such as Raspberry Pi, this enables models to fit entirely in memory or flash (Xu et al., 2023).
In the TTM approach for projections, TTM layers' forward passes have complexity 2; custom backpropagation routines ensure memory usage is comparable to dense layers (Chekalina et al., 2023).
6. Insights, Limitations, and Broader Applicability
A key empirical finding is that GPT embeddings admit a strong low-rank structure. Certain tensor modes exhibit lower mean absolute errors after reconstruction, suggesting interpretable subspace significance. While aggressive compression (3) degrades generation quality, moderate compression (4) can preserve or even improve downstream task performance—potentially via regularization effects (Xu et al., 2023).
Practical implementation guidelines recommend padding embedding dimensions to powers of two, initializing with low TT-ranks, and compressing new tokens in dynamic vocabularies without affecting existing TT cores.
Current limitations include the need to integrate position/mask embeddings into the MPS format and to validate full end-to-end inference speedup in hardware. Ongoing extensions involve generalizing TT-based compression to other transformer blocks, including BERT, GPT-3, and OPT, by replacing dense projections with TTM layers, and designing TT-based transformer blocks for entire model compression and acceleration (Xu et al., 2023, Chekalina et al., 2023).
7. Conclusion and Future Directions
TensorGPT demonstrates that LLMs, especially those from the GPT family, have substantial low-rank redundancy in both embeddings and dense projections. By leveraging tensor-train decomposition and matrix product state representations, up to 38.4× parameter compression is achievable without additional fine-tuning, and with little or no loss in performance for moderate compression settings. The approach is broadly applicable across transformer-based architectures and is particularly advantageous for on-device applications constrained by memory and storage. A plausible implication is that further efficiency gains are attainable by integrating positional/mask encodings into the tensorized formats and by implementing TT-based end-to-end transformer blocks, paving the way for highly compressed and efficient LLM deployments (Xu et al., 2023, Chekalina et al., 2023).