Manuscript Offprint
arXiv:2610.41822Trainable Vector Quantization for Large Language Models
Anastasiia Prutianova, Alina Bogdanova, Mikhail Shutov, Dmitrii Poimanov, Anatoly Gorkov, and Ilia Zharikov(✉)
Huawei Technologies Co. Ltd.
Abstract. Vector Quantization (VQ) is a rapidly evolving technique for compressing Large Language Model (LLM) weights, reducing memory usage, and speeding up inference. However, extreme compression deteriorates model performance, which is challenging to recover due to the discrete nature of VQ parameters. Existing methods employ training-free approaches that are limited to layer-wise reconstruction loss minimization. To address this limitation, we propose TVQ, a novel method that leverages straight-through estimation to enable gradient descent-based optimization of vector-quantized LLMs. By reformulating VQ LLM optimization with trainable latent weights, TVQ enables arbitrary objective minimization. We constitute our approach by applying TVQ in a block-wise knowledge distillation paradigm, which balances quality and training efficiency, and propose several practical solutions to accelerate training. In experiments on modern LLMs, we demonstrate that TVQ is compatible with modern VQ schemes. As a result, TVQ achieves state-of-the-art quality in low-bit post-training quantization settings with a modest training budget and straightforward PyTorch implementation. For instance, TVQ achieves near-lossless 2-bit quantization for LLaMA2-70B with only 1% accuracy drop on popular Question-Answering benchmarks.
1 Introduction
Recent advancements in deep learning have led to significant progress in Natural Language Processing, particularly in text generation [1,13,14]. A significant factor driving this progress is the rapid increase in neural network size, which leads to enhanced performance but also raises computational costs and memory consumption, fueling demand for efficient language models.
Large Language Model (LLM) deployment is primarily memory-bound; for instance, the Llama3-70B [13] parameters require 140GB of memory, exceeding the capacity of modern Graphics Processing Units (GPU). As weight-only quantization allows for compressing the model several-fold, it has become crucial for efficient memory-constrained inference [11,43,7]. In particular, Post-Training
A. Prutianova, A. Bogdanova — Equal contributions.
A. Prutianova, A. Bogdanova et al.
Quantization (PTQ) [27,15,21,4] was widely adopted since it compresses pretrained weights without full model retraining, adding only negligible computational overhead for calibration.
Recently, Vector Quantization (VQ) has gained traction as it demonstrated significant memory reduction advantages over traditional scalar quantization [37,9]. Unlike scalar quantization [5,10,24], which encodes values of the weight matrix with a fixed set of integers, VQ represents the weight matrix using a fixed set of vectors, known as a codebook. Specifically, in VQ, the values of the pretrained weight matrix are grouped into fixed-length vectors, and each group is replaced with a codebook vector. An integer index matrix is then used to indicate which codebook vector is assigned to each group.
Since extreme compression inevitably introduces a performance gap relative to the original model, it is necessary to optimize the quantization parameters to recover model quality. The key challenge is that the majority of VQ parameters are concentrated in integer index matrices, resulting in a high-dimensional and discrete search space. Most existing VQ optimization methods [9,22,35,36] simplify the vector assignment optimization problem by considering individual model layers independently. These methods aim to minimize the quantization error of linear layer outputs, specifically , where and are compressed and original weight matrices, is a matrix of input activations. They rely on single-layer linearity and layer output loss as the primary objective. As a result, network layers have a limited ability to adapt to the quantization of other layers and cannot capture how local quantization errors propagate through subsequent layers.
We address this challenge by introducing Trainable Vector Quantization (TVQ), a method that enables simultaneous optimization of multiple VQ parameters with respect to arbitrary loss functions. To achieve this, we reformulate the index matrix optimization problem by introducing trainable continuous latent weights and leveraging the Straight-Through Estimator (STE) [2] to propagate gradients through discrete index assignments from quantized to latent weights.
Although TVQ allows simultaneous optimization of all parameters, full model training is resource-intensive. Instead, we chose to use TVQ within the block-wise Knowledge Distillation (KD) paradigm [20,15,41,31,4], which is known to be state-of-the-art in scalar PTQ in both computer vision and language domains. However, it remains unexplored in VQ LLMs due to the limitations of prior VQ optimization methods. Block-wise KD strikes a good balance between training speed and quality and requires only a small amount of calibration data. As a result, our block-wise TVQ achieves computational efficiency comparable to the layer-wise methods, while delivering significant quality improvements. Furthermore, TVQ outperforms the model-wise fine-tuning approach PV-tuning [25] in both speed and quality. Additionally, we suggest a straightforward implementation of TVQ with popular training frameworks such as PyTorch [28].
TVQ is suitable for modern advanced VQ schemes [35,36] introduced in previous works. We experimentally demonstrate that TVQ improves the model performance via better optimization while keeping the architecture of VQ LLM unchanged. As a result, models optimized with TVQ remain compatible with existing software tools for inference acceleration.
In summary, our contributions are the following:
– We introduce a novel VQ LLM optimization method TVQ, that enables gradient descent-based optimization of vector-quantized weights with respect to an arbitrary loss function. We propose to reformulate index assignment optimization via trainable continuous latent weights and enable backpropagation through the discrete assignment operation with a STE. We experimentally demonstrate that TVQ is applicable to existing advanced VQ schemes, computationally efficient, and easy to implement.
– In extensive experiments on modern LLMs, such as LLAMA 2 [34], MISTRAL [16], and LLAMA 3 [13], we show that TVQ outperforms existing optimization techniques. As a result, it achieves state-of-the-art performance in low-bit PTQ. Notably, for 2-bit Llama3-70B, TVQ improves upon the current best result by 1.9% of accuracy across popular Question-Answering benchmarks, substantially reducing the performance gap between the original and quantized models from 4.5% to 2.6%. In addition, we provide detailed ablation studies on the impact of the proposed method's components.
2.1 Vector-Quantized LLM Optimization
This section focuses on the techniques employed in related works, specifically for optimizing vector-quantized LLMs. Existing approaches follow a two-stage pipeline: layer-wise optimization that minimizes reconstruction loss, followed by fine-tuning with respect to global objectives.
Stage-1: Layer-wise Optimization. Prior methods start by optimizing the reconstruction error , where they jointly determine vector assignments and codebooks for a single linear layer. AQLM [9] employs an EM-algorithm that alternates between beam search for index matrix (E-step) and gradient descent for codebook optimization (M-step), with codebook initialization via standard k-means clustering. The VPTQ [22] achieves comparable quality with reduced training time via enhanced Hessian-weighted k-means codebook initialization and GPTQ-like [11] adaptive rounding approach for vector assignment. However, both AQLM and VPTQ are incompatible with the fixed hardware-efficient codebooks employed in QuIP# [35] and QTIP [36]. These immutable codebooks prevent M-step updates in AQLM and weighted k-means initialization in VPTQ. To optimize vector assignments with fixed codebooks, QuIP# and QTIP leverage the BlockLDLQ algorithm, which employs Hessian-aware adaptive rounding based on the LDL decomposition. However, both VPTQ and BlockLDLQ estimate the Hessian solely from layer inputs and therefore cannot account for error propagation through subsequent layers.
A. Prutianova, A. Bogdanova et al.
Stage-2: End-to-end Fine-tuning. To mitigate the accumulated quantization errors from the layer-wise stage, existing works fine-tune continuous parameters (codebooks, layer norms, LM head) for a global objective such as cross-entropy or KD losses, while keeping vector assignments fixed. PV-tuning [25], designed to complement Stage-1 algorithms, is the only method that considers model-wise vector assignment optimization, using gradient magnitude to select a small fraction of vectors for updates. However, PV-tuning requires significantly more compute than competing methods and does not naturally generalize to the current state-of-the-art VQ scheme, suggested in QTIP, where index matrices are bitshift trellis encoded and changing individual indices would break their codedependence.
In contrast, TVQ is applicable to all existing VQ schemes. Unlike existing Stage-1 approaches, which operate strictly in a layer-wise manner and cannot be directly extended to multi-layer optimization, TVQ captures inter-layer dependencies. For Stage-2 optimization, we apply continuous parameter fine-tuning as in most prior works.
2.2 Straight-Through Estimation
STE is a method that propagates gradients through non-differentiable or zero-gradient functions, allowing for gradient-based optimization. It was used in many areas where such functions naturally appear: in neural architecture search [8], pruning [39], scalar quantization [10]. It was widely used in computer vision and speech processing for learning codebooks [38,32,33]. However, STE has not previously been applied to the optimization of VQ LLMs; we address this gap by introducing TVQ.
3 Method
3.1 Vector Quantization Background
Let the weight matrix of a linear layer be denoted by . For vector quantization this matrix is partitioned into -dimensional vectors , forming a set of vectors:
For compression, each vector is replaced with one of representative vectors stored in the codebook matrix . Index matrix specifies indices of the codebook vectors assigned to each vector . Since matrices and together contain significantly fewer parameters than does, they form a compressed representation of . During inference, an uncompressed representation of , denoted by , is constructed from and as follows:
Notably, is not necessarily the closest approximation of the original weight , as the compressed representation is optimized to improve overall model performance.
Additionally, some works apply pre-/post-processing functions to and , respectively. Since pre-/post-processing and codebook optimization do not influence the logic behind our proposed index optimization method, TVQ, we omit them from the discussion in the next sections for simplicity.
3.2 VQ schemes
To introduce a general TVQ framework, we begin by formally describing existing VQ schemes from the optimization perspective.
In plain VQ, the codebook can be any matrix , and the index matrix can take any values . We refer to this unconstrained scheme as BasicVQ. Recent work has proposed more advanced VQ schemes to enhance quality-acceleration trade-offs. From the optimization perspective, these methods restrict the search spaces for the codebook and index matrices to and , respectively. For instance, the codebook matrix may be fixed and predefined to fit into the L1 GPU cache [35], meaning that contains only one element. Alternatively, may consist of index matrices whose entries are codependent for advanced bit-packing techniques [36] that improve storage efficiency. For clarity, we provide a summary of the existing VQ schemes in Appendix A.
3.3 Trainable Vector Quantization
In this section, we present the general Trainable Vector Quantization (TVQ) algorithm, which enables joint optimization of VQ parameters across multiple layers with respect to an arbitrary loss function, and is compatible with existing LLM VQ schemes.
The compressed representation of a weight matrix consists of a codebook matrix and an index matrix , with the majority of parameters concentrated in the index matrix (see Appendix E). Therefore, optimizing is crucial for recovering the model's quality. A key challenge is that the index matrix consists of integer values, resulting in a high-dimensional, combinatorial discrete search space and making direct optimization via standard gradient descent inapplicable. Nevertheless, leveraging gradient descent is highly desirable, as it provides a general mechanism to optimize models with respect to an arbitrary differentiable loss function .
To address this issue, we propose to reparameterize the index matrix as a function of the codebook and a continuous latent weight matrix as follows:
This function determines the indices that provide the closest approximation of the latent weight with codebook under the VQ scheme constraints.
A. Prutianova, A. Bogdanova et al.

Fig. 1. This figure illustrates the proposed TVQ method, applied to a single linear layer with the weight matrix . During optimization, these matrices are updated: the indices matrix , the weight matrix , and (optionally) the codebook . TVQ involves three main operations: is calculated according to (3); The dequantized weight matrix is gathered from and according to (2) and used to calculate the loss function; The gradients of the loss are propagated from to and , (and optionally ) is updated with gradient descent. After training, only the compressed representation consisting of and is stored and used for inference instead of the original weight matrix.
This reparameterization transforms optimization over the discrete index matrix into optimization over the continuous latent weight . As a result, becomes a differentiable function of continuous parameters and , thereby facilitating gradient-based optimization. The gradient of with respect to is defined as follows:
However, is equal to 0 almost everywhere, since (3) is a piecewise constant function of . According to (4), this yields , which results in zero gradient descent updates for and prevents learning.
We propose to use STE to propagate gradients directly from to . We replace a.e. zero gradient with the gradient of the identity function. Using this approximation in (4) we obtain the final gradient estimation, which we use for gradient descent updates of :
The proposed idea has a very simple implementation in PyTorch or TensorFlow frameworks (see Appendix B for the suggested pseudocode). The general scheme of TVQ is presented in Fig. 1.
3.4 Training pipeline
Our optimization pipeline consists of two stages. In the first stage, we apply TVQ to perform block-wise optimization of vector assignments. In the second stage, we conduct end-to-end model finetuning, adjusting only a small subset of parameters.
Stage-1: Block-wise PTQ. A modern Large Language Model is typically composed of sequential Transformer blocks:
where denotes the -th Transformer block, consisting of an attention module, a following multi-layer perceptron, and residual connections. The input activations to the -th block and its parameters are denoted as and , respectively. Similarly, a quantized model consisting of quantized blocks is defined in a similar way:
We optimize the quantized model blocks sequentially by minimizing the distance between their output activations and corresponding activations of the original model. Index matrices are trained using TVQ to reduce the reconstruction loss on the outputs,
where is input activations to block computed by the original model, is input activations to block computed by the quantized model, refers to the input training data.
Stage-2: Parameter efficient End-to-End Fine-Tuning. In this stage, we optimize the quantized model continuous parameters with gradient decent. We use Kullback-Leibler (KL) divergence as a loss function,
where is a selected subset of the VQ model's continuous parameters, such as layer normalization weights, codebooks, and the language modeling head. We optimize parameter subsets similar to those used in prior works, which vary depending on the specific quantization scheme employed.
A. Prutianova, A. Bogdanova et al.
3.5 Implementation details
TVQ requires recomputing the index matrices at each optimization step based on the updated latent weights, as defined in Equation (3). The index computation algorithm depends on the optimization constraints imposed by the chosen VQ scheme and can be computationally expensive (see Appendix F for details about computational overhead for different VQ schemes). To address this, we suggest two complementary acceleration strategies:
– Scheduled Index Updates. In some experiments, we update the index matrices once in optimization steps (rather than at each step), since it has a negligible impact on the final model quality, as we confirm in Section 4.4. Intuitively, these scheduled updates are similar to increasing the effective batch size via gradient accumulation.
– Approximate Nearest-Neighbor Search. For TVQ with the basic VQ scheme defined in Section 3.1 (referred to as TVQ+BasicVQ in the experimental results), we update index matrices via Approximate Nearest-Neighbor search. We utilize an approximate search [19] based on Voronoi cells partitioning, implemented in the FAISS library [17]. As we show in Appendix D, it has high precision and does not affect the final model quality while speeding up index matrix updates.
For further details on training acceleration see Appendix G.
4 Experiments
4.1 Experimental setup
Models and Data. We employ open-source LLMs available on the HuggingFace Model Hub [42], specifically Llama-3, Mistral-7B-v0.1, and Llama-2 model families. In all experiments, we train models on the open-source dataset RedPajama [40], as in prior VQ works.
Evaluation. We adopt a standard benchmarking framework to compare our models with existing approaches. We report perplexity on the WikiText-2 [26] test set and the validation set of the C4 dataset [29]. For perplexity, we use models' native sequence length, in particular 4096 tokens for Llama2 and 8192 tokens for Llama3 and Mistral-7B-v0.1. We also provide zero-shot accuracy on Winogrande [30], PiQA [3], HellaSwag [44], ARC-easy and ARC-challenge Question Answering (QA) benchmarks [6], using the Language Model Evaluation Harness library [12] for evaluation.
Training parameters. During both Stage-1 and Stage-2 models are trained using the standard Adam [18] optimizer, for Stage-1 we also use Cosine Annealing scheduler [23]. To support reproducibility, we provide all relevant hyperparameters – such as calibration data size, the number of epochs, learning rates, and index update steps – for both stages in Appendix C. For Stage-2, we use the same hyperparameters as in prior methods.
Table 1. Evaluation of quantized Llama2-7B/70B, Llama3-8B/70B, and Mistral-7B-v0.1 models. The table reports perplexity measured on the WikiText-2 test set (W2) and C4 validation set, and accuracy for 0-shot question answering benchmarks: Winogrande (WG), PiQA (PQ), HellaSwag (HS), ARC-easy (AE), ARC-challenge (AC) and QA Average with and without HellaSwag benchmark. As in prior works, we use a context length of 4096 for the Llama2 models and a context length of 8192 for both Mistral-7B-v0.1 and Llama3 models.
| Method | Bits | W2 | C4 | WG | PQ | HS | AE | AC | QA Avg. | |
|---|---|---|---|---|---|---|---|---|---|---|
| Llama3-8B | FP16 | 16 | 5.54 | 7.10 | 73.1 | 79.6 | 60.2 | 80.1 | 50.3 | 68.7 / 70.8 |
| QuIP# | 2.00 | 7.84 | 9.06 | 68.2 | 75.6 | - | 72.9 | 39.2 | - / 64.0 | |
| VPTQ | 2.08 | - | - | 65.9 | 75.1 | 52.2 | 71.0 | 36.9 | 60.2 / 62.2 | |
| QTIP | 2.00 | 7.33 | 8.62 | 70.7 | 77.6 | - | 75.2 | 44.2 | - / 66.9 | |
| PV-Tuning | 2.01 | 6.99 | 8.29 | 69.9 | 77.8 | 55.5 | 75.8 | 42.8 | 64.4 / 66.6 | |
| TVQ+BasicVQ | 2.02 | 7.59 | 8.86 | 71.5 | 76.6 | 54.3 | 73.5 | 41.3 | 63.4 / 65.7 | |
| TVQ+QuIP# | 2.00 | 7.56 | 8.82 | 69.1 | 76.9 | 54.3 | 74.4 | 41.8 | 63.3 / 65.6 | |
| TVQ+QTIP | 2.00 | 7.13 | 8.43 | 70.2 | 77.5 | 55.8 | 76.3 | 45.3 | 65.0 / 67.3 | |
| Llama3-70B | FP16 | 16 | 2.59 | 5.78 | 80.9 | 82.5 | 66.3 | 86.7 | 60.4 | 75.4 / 77.6 |
| QuIP# | 2.00 | 5.77 | 7.46 | 68.9 | 54.7 | - | 32.2 | 18.3 | - / 43.5 | |
| VPTQ | 2.08 | - | - | 77.9 | 80.4 | 61.7 | 81.8 | 52.5 | 70.9 / 73.2 | |
| QTIP | 2.00 | 4.97 | 6.80 | 72.6 | 57.1 | - | 35.2 | 28.0 | - / 48.2 | |
| PV-Tuning | 2.07 | 4.57 | 6.56 | 78.1 | 79.2 | 63.9 | 80.2 | 50.8 | 70.4 / 72.1 | |
| TVQ+BasicVQ | 2.07 | 4.74 | 6.77 | 76.3 | 78.2 | 63.2 | 79.1 | 48.0 | 69.0 / 70.4 | |
| TVQ+QuIP# | 2.00 | 5.33 | 7.02 | 75.5 | 81.1 | 62.0 | 83.7 | 54.6 | 71.4 / 73.7 | |
| TVQ+QTIP | 2.00 | 4.48 | 6.59 | 78.7 | 82.1 | 64.3 | 83.2 | 55.9 | 72.8 / 75.0 | |
| Mistral-7B-v0.1 | FP16 | 16 | 4.77 | 5.71 | 73.6 | 80.5 | 61.2 | 78.9 | 49.2 | 68.7 / 70.6 |
| AQLM | 2.01 | 5.76 | 6.60 | 68.7 | 77.6 | 56.4 | 73.3 | 42.7 | 63.7 / 65.6 | |
| VPTQ | 2.04 | 5.64 | 6.43 | 68.7 | 77.9 | 56.1 | 72.2 | 41.1 | 63.2 / 65.0 | |
| PV-Tuning | 2.01 | 5.29 | 6.17 | 72.8 | 79.1 | 58.2 | 77.4 | 44.2 | 66.3 / 68.4 | |
| TVQ+BasicVQ | 2.01 | 5.59 | 6.60 | 71.4 | 78.5 | 56.9 | 77.3 | 43.2 | 65.5 / 67.6 | |
| TVQ+QuIP# | 2.00 | 5.52 | 6.53 | 71.2 | 78.4 | 57.9 | 77.8 | 46.3 | 66.3 / 68.4 | |
| TVQ+QTIP | 2.00 | 5.38 | 6.39 | 71.4 | 79.2 | 58.4 | 78.1 | 47.0 | 66.8 / 68.9 | |
| Llama2-7B | FP16 | 16 | 5.12 | 6.63 | 67.3 | 78.5 | 56.7 | 69.3 | 40.0 | 62.4 / 63.8 |
| AQLM | 2.02 | 6.14 | 8.09 | 65.7 | 76.0 | 51.8 | 63.4 | 34.4 | 58.3 / 59.9 | |
| QuIP# | 2.00 | 6.19 | 8.16 | 64.9 | 75.1 | - | 64.6 | 34.6 | - / 59.8 | |
| VPTQ | 2.02 | 6.13 | 8.07 | 64.3 | 75.2 | 52.1 | 63.8 | 35.2 | 58.1 / 59.6 | |
| QTIP | 2.00 | 5.86 | 7.73 | 64.7 | 75.9 | - | 65.6 | 35.7 | - / 60.5 | |
| TVQ+BasicVQ | 2.02 | 6.11 | 7.99 | 65.4 | 76.3 | 52.8 | 67.7 | 37.5 | 59.9 / 61.7 | |
| TVQ+QuIP# | 2.00 | 6.01 | 7.96 | 66.5 | 76.9 | 52.6 | 65.1 | 37.6 | 59.7 / 61.5 | |
| TVQ+QTIP | 2.00 | 5.85 | 7.72 | 65.8 | 77.2 | 53.5 | 66.9 | 36.9 | 60.1 / 61.7 | |
| Llama2-70B | FP16 | 16 | 3.12 | 4.97 | 77.0 | 81.1 | 64.0 | 77.7 | 51.1 | 70.2 / 71.7 |
| AQLM | 2.07 | 3.83 | 5.62 | 74.4 | 80.9 | 62.2 | 74.6 | 49.0 | 68.2 / 69.7 | |
| QuIP# | 2.00 | 3.91 | 5.71 | 75.9 | 80.3 | 62.5 | 77.3 | 48.7 | 68.9 / 70.6 | |
| VPTQ | 2.07 | 3.93 | 5.72 | 75.0 | 80.3 | 63.0 | 77.1 | 47.7 | 68.6 / 70.0 | |
| QTIP | 2.00 | 3.70 | 5.48 | 75.1 | 80.2 | - | 76.3 | 48.0 | - / 69.9 | |
| TVQ+BasicVQ | 2.07 | 3.88 | 5.77 | 77.2 | 80.8 | 62.5 | 77.6 | 49.2 | 69.5 / 71.2 | |
| TVQ+QuIP# | 2.00 | 3.96 | 5.81 | 75.5 | 80.5 | 62.1 | 76.4 | 48.4 | 68.6 / 70.2 | |
| TVQ+QTIP | 2.00 | 3.72 | 5.50 | 74.6 | 81.3 | 62.9 | 77.0 | 48.2 | 68.8 / 70.3 |
A. Prutianova, A. Bogdanova et al.
4.2 Experimental results
We present our experimental results in Table 1. Our analysis focuses on the QA accuracy averaged across multiple benchmarks: WinoGrande, PiQA, HellaSwag, Arc Easy, and Arc Challenge. When comparing TVQ with QuIP# and QTIP, we exclude HellaSwag from the averaging calculation, as these methods do not provide metrics for this benchmark.
Comparison of optimization approaches. To fairly compare TVQ with previous optimization approaches, we consider that both the VQ scheme and the optimization method contribute to the final quality. Therefore, for several previous works, we replaced their optimization method with TVQ, maintaining their original VQ scheme. In this way, we isolated performance improvements attributable to our TVQ. In particular, we applied TVQ with the BasicVQ scheme defined in Section 3.1. These models, which we refer to as TVQ+BasicVQ, are architecturally identical to those used in AQLM. We also performed experiments with the quantization schemes proposed in QuIP# and QTIP. The resulting experimental configurations are referred to as TVQ+QuIP# and TVQ+QTIP, respectively.
By comparing results in pairs of VQ models that differ only in optimization method (TVQ+BasicVQ vs AQLM, TVQ+QuIP# vs QuIP#, TVQ+QTIP vs QTIP), we observe that TVQ consistently outperforms the layer-wise optimization strategies initially employed in AQLM, QuIP#, and QTIP methods. For instance, TVQ outperforms the beam search used in AQLM across all models by 1.5% on average, reducing the average compression-related accuracy drop from 3.7% to 2.2%.
TVQ also improves results for the QuIP# VQ scheme by 0.9% on average across all models except for LLama3-70B. For LLama3-70B, the improvement is particularly substantial, where the original QuIP# algorithm achieves only 43.5% accuracy, while TVQ+QuIP# reaches 73.7%. This considerable gap, undetected by perplexity metrics, also reveals the limited predictive value of perplexity for assessing quantization impact on downstream task performance in practical applications.
All TVQ+QTIP models achieve higher QA accuracy than their corresponding baseline QTIP models across all tested models. The combination of QTIP's advanced quantization scheme with TVQ's optimization approach yields the highest scores across multiple model architectures, establishing TVQ+QTIP as the leading configuration in our evaluation.
State-of-the-art performance. Models optimized with TVQ achieve state-of-the-art performance for all evaluated architectures. On Llama2-70B, TVQ achieves near-lossless results with only 0.7% performance degradation relative to the original model, improving upon the previous best result from QuIP# (1.3% accuracy degradation). For Llama2-7B, TVQ outperforms all other methods by 1-2%. On Llama3-70B, TVQ shows a 1.9% improvement, reducing the performance gap to the full-precision baseline from 4.5% to 2.6%. Unlike existing approaches, where no single method consistently leads (e.g., VPTQ performs best on Llama3-70B, PV-tuning on Mistral-7B-v0.1, and QTIP on Llama3-8B),
TVQ achieves a new state-of-the-art quality in low-bit PTQ for all considered architectures.
4.3 Training efficiency
While TVQ is primarily focused on the quality and simplicity of implementation, it also operates within a moderate computational budget, as shown in Table 2. TVQ+QuIP# and TVQ+BasicVQ are equally compute-consuming as QuIP# and AQLM correspondingly, while achieving better quality.
Table 2. Quantization computational costs of 2-bit Llama2-70B. The table reports the number of GPUs hours measured using a single NVIDIA 80GB Ampere100 GPU. As PV-tuning is applied on top of Stage-1 methods, we refer to its Stage-1 GPU hours as X. Note that the training time is significantly shorter since most methods, including TVQ, can be parallelized across multiple GPUs.
| Method | Stage-1 | Stage-2 | Total |
|---|---|---|---|
| AQLM | 250 | 50 | 300 |
| VPTQ | 74 | 50 | 124 |
| Quip# | 40 | 50 | 90 |
| QTIP | 50 | 50 | 100 |
| PV-tuning | X | 1500 | >1500 |
| TVQ+Quip# | 54 | 50 | 104 |
| TVQ+BasicVQ | 212 | 50 | 262 |
| TVQ+QTIP | 390 | 50 | 440 |
TVQ+QTIP reaches better quality than PV-tuning, which demands a huge computational budget (≈1,500 GPU-hours for Stage-2 alone) and requires an 8 Ampere100 GPU node. In contrast, our pipeline completes within 100-400 total GPU-hours using only 2-4 Ampere100 GPUs — the same scale as other efficient methods — while achieving better model quality. This demonstrates that our method attains superior quantization performance with reasonable computational cost, making it practical and applicable in real-world settings.
Table 3. Ablation study of the scheduled index matrix updates for TVQ+QTIP. The table reports results after Stage-1 optimization only. The training time is measured using 8 NVIDIA 32GB Volta100 GPU. Note that training time is significantly reduced when training on modern GPU architectures, such as Ampere or Hopper.
| S_upd | Stage-1 | Llama2-7B | Llama3-8B | Mistral-7B | |||
|---|---|---|---|---|---|---|---|
| time | W2↓ | QA↑ | W2↓ | QA↑ | W2↓ | QA↑ | |
| 8 | ≈32h | 6.15 | 59.0 | 8.45 | 63.3 | 5.72 | 65.8 |
| 16 | ≈21h | 6.17 | 58.9 | 8.60 | 62.2 | 5.71 | 66.0 |
| 32 | ≈15h | 6.22 | 58.8 | 8.68 | 62.0 | 5.74 | 65.7 |
| 64 | ≈14h | >100 | <10 | >100 | <10 | >100 | <10 |
A. Prutianova, A. Bogdanova et al.
4.4 Ablation study of Scheduled Index Updates
For both TVQ+BasicVQ and TVQ+QTIP experiments, the indices function computation constitutes a significant part of the overall computational cost. To address this bottleneck, we implement a strategy that performs index matrices updates every optimization steps.
Table 4. Ablation study of the scheduled index matrix updates for TVQ+BasicVQ experiments. The table reports results after Stage-1 optimization only. The training time is measured using 2 NVIDIA 80GB Ampere100 GPUs.
| Supd | Stage-1 time | Llama2-70B W2↓ | QA↑ |
|---|---|---|---|
| 1 | 51h | 4.11 | 68.2 |
| 2 | 33h | 4.10 | 68.1 |
| 3 | 24h | 4.11 | 68.1 |
| 4 | 19h | 4.15 | 67.8 |
For TVQ+QTIP, we evaluate how model quality depends on in Table 3. Experimental results demonstrate that setting to 8, 16, and 32, yields comparable quality metrics, while increasing to 64 leads to a significant quality degradation. Interestingly, experiments with equal to 32 and 64 exhibit nearly identical training times, as the index recomputation overhead becomes negligible relative to the total training cost. Based on these observations, we conclude that setting to 16 provides an optimal trade-off between quality and computational efficiency for the majority of TVQ+QTIP experiments.
For TVQ+BasicVQ experiments, we set to 1 as the default, meaning that indices are recomputed at each optimization step. This configuration prioritizes model quality over computational efficiency. We analyze the impact of on both quality metrics and training time in Table 4. This table demonstrates that increasing to 2 or 4 can accelerate experiments in practical scenarios, while incurring only a minor drop in quality.
5 Conclusions
In this work, we tackled the problem of vector assignment optimization in VQ models, introducing TVQ – an algorithm that enables gradient-based index optimization with arbitrary loss functions. Our experimental results confirm that TVQ consistently outperforms previous VQ optimization methods on popular LLM evaluation benchmarks. Moreover, TVQ is applicable to all existing vector quantization schemes and is straightforward to implement using popular deep learning frameworks. We believe that future research can leverage TVQ for index assignment optimization while advancing VQ architectures, further improving LLM efficiency.
6 Limitations
Several works, such as QTIP and AQLM, provide software tools for faster execution on modern hardware, such as CUDA kernels for NVIDIA GPUs. These works have shown that vector quantization not only reduces memory consumption but also significantly benefits throughput and latency. One limitation of our work is that we do not contribute to the further development of hardware-specific utilities for vector-quantized models. However, since TVQ preserves the structure of optimized models, they remain fully compatible with existing software tools and inherit the same efficiency and speedups as prior checkpoints.
References
-
Achiam, J., Adler, S., Agarwal, S., Ahmad, L., Akkaya, I., Aleman, F.L., Almeida, D., Altenschmidt, J., Altman, S., Anadkat, S., et al.: Gpt-4 technical report. arXiv preprint arXiv:2303.08774 (2023)
-
Bengio, Y., Léonard, N., Courville, A.: Estimating or propagating gradients through stochastic neurons for conditional computation. arXiv preprint arXiv:1308.3432 (2013)
-
Bisk, Y., Zellers, R., Gao, J., Choi, Y., et al.: Piqua: Reasoning about physical commonsense in natural language. In: Proceedings of the AAAI conference on artificial intelligence. vol. 34, pp. 7432–7439 (2020)
-
Chen, M., Shao, W., Xu, P., Wang, J., Gao, P., Zhang, K., Luo, P.: Efficientqat: Efficient quantization-aware training for large language models. In: Che, W., Nabende, J., Shutova, E., Pilehvar, M.T. (eds.) Proceedings of the 63rd Annual Meeting of the Association for Computational Linguistics (Volume 1: Long Papers), ACL 2025, Vienna, Austria, July 27 - August 1, 2025. pp. 10081–10100. Association for Computational Linguistics (2025), https://aclanthology.org/2025.acl-long.498/
-
Choi, J., Wang, Z., Venkataramani, S., Chuang, P.I.J., Srinivasan, V., Gopalakrishnan, K.: Pact: Parameterized clipping activation for quantized neural networks. arXiv preprint arXiv:1805.06085 (2018)
-
Clark, P., Cowhey, I., Etzioni, O., Khot, T., Sabharwal, A., Schoenick, C., Tafjord, O.: Think you have solved question answering? try arc, the ai2 reasoning challenge. arXiv preprint arXiv:1803.05457 (2018)
-
Dettmers, T., Pagnoni, A., Holtzman, A., Zettlemoyer, L.: Qlora: Efficient fine-tuning of quantized llms. Advances in neural information processing systems 36, 10088–10115 (2023)
-
Dong, X., Yang, Y.: Searching for a robust neural architecture in four gpu hours. In: Proceedings of the IEEE/CVF conference on computer vision and pattern recognition. pp. 1761–1770 (2019)
-
Egiazarian, V., Panferov, A., Kuznedelev, D., Frantar, E., Babenko, A., Alistarh, D.: Extreme compression of large language models via additive quantization. In: Forty-first International Conference on Machine Learning, ICML 2024, Vienna, Austria, July 21-27, 2024 (2024), https://openreview.net/forum?id=5mCaITRm0
-
Esser, S.K., McKinstry, J.L., Bablani, D., Appuswamy, R., Modha, D.S.: Learned step size quantization. In: 8th International Conference on Learning Representations, ICLR 2020, Addis Ababa, Ethiopia, April 26-30, 2020 (2020), https://openreview.net/forum?id=rkg066VKDS
A. Prutianova, A. Bogdanova et al.
-
Frantar, E., Ashkboos, S., Hoefler, T., Alistarh, D.: OPTQ: accurate quantization for generative pre-trained transformers. In: The Eleventh International Conference on Learning Representations, ICLR 2023, Kigali, Rwanda, May 1-5, 2023 (2023), https://openreview.net/forum?id=tcbBPnfwxS
-
Gao, L., Tow, J., Biderman, S., Black, S., DiPofi, A., Foster, C., Golding, L., Hsu, J., McDonell, K., Muennighoff, N., et al.: A framework for few-shot language model evaluation (2021)
-
Grattafori, A., Dubey, A., Jauhri, A., Pandey, A., Kadian, A., Al-Dahle, A., Letman, A., Mathur, A., Schelten, A., Vaughan, A., et al.: The llama 3 herd of models. arXiv preprint arXiv:2407.21783 (2024)
-
Guo, D., Yang, D., Zhang, H., Song, J., Wang, P., Zhu, Q., Xu, R., Zhang, R., Ma, S., Bi, X., et al.: Deepseek-r1: Incentivizing reasoning capability in llms via reinforcement learning. arXiv preprint arXiv:2501.12948 (2025)
-
Hubara, I., Nahshan, Y., Hanani, Y., Banner, R., Soudry, D.: Accurate post training quantization with small calibration sets. In: Meila, M., Zhang, T. (eds.) Proceedings of the 38th International Conference on Machine Learning, ICML 2021, 18-24 July 2021, Virtual Event. Proceedings of Machine Learning Research, vol. 139, pp. 4466–4475. PMLR (2021), http://proceedings.mlr.press/v139/hubara21a.html
-
Jiang, A.Q., Sablayrolles, A., Mensch, A., Bamford, C., Chaplot, D.S., de Las Casas, D., Bressand, F., Lengyel, G., Lample, G., Saulnier, L., Lavaud, L.R., Lachaux, M., Stock, P., Scao, T.L., Lavril, T., Wang, T., Lacroix, T., Sayed, W.E.: Mistral 7b. arXiv preprint arXiv:2310.06825 (2023)
-
Johnson, J., Douze, M., Jégou, H.: Billion-scale similarity search with gpus. IEEE transactions on big data 7(3), 535–547 (2019)
-
Kingma, D.P., Ba, J.: Adam: A method for stochastic optimization. In: Bengio, Y., LeCun, Y. (eds.) 3rd International Conference on Learning Representations, ICLR 2015, San Diego, CA, USA, May 7-9, 2015, Conference Track Proceedings (2015), http://arxiv.org/abs/1412.6980
-
Kolahdouzan, M., Shahabi, C.: Voronoi-based k nearest neighbor search for spatial network databases. In: Proceedings of the Thirtieth international conference on Very large data bases-Volume 30. pp. 840–851 (2004)
-
Li, Y., Gong, R., Tan, X., Yang, Y., Hu, P., Zhang, Q., Yu, F., Wang, W., Gu, S.: BRECQ: pushing the limit of post-training quantization by block reconstruction. In: 9th International Conference on Learning Representations, ICLR 2021, Virtual Event, Austria, May 3-7, 2021 (2021), https://openreview.net/forum?id=P0Wv6hDd9XH
-
Lin, J., Tang, J., Tang, H., Yang, S., Chen, W.M., Wang, W.C., Xiao, G., Dang, X., Gan, C., Han, S.: Awq: Activation-aware weight quantization for on-device llm compression and acceleration. vol. 6, pp. 87–100 (2024)
-
Liu, Y., Wen, J., Wang, Y., Ye, S., Zhang, L.L., Cao, T., Li, C., Yang, M.: Vptq: Extreme low-bit vector post-training quantization for large language models. In: Proceedings of the 2024 Conference on Empirical Methods in Natural Language Processing. pp. 8181–8196 (2024)
-
Loshchilov, I., Hutter, F.: SGDR: stochastic gradient descent with warm restarts. In: 5th International Conference on Learning Representations, ICLR 2017, Toulon, France, April 24-26, 2017, Conference Track Proceedings (2017), https://openreview.net/forum?id=Skq89Scxx
-
Ma, S., Wang, H., Ma, L., Wang, L., Wang, W., Huang, S., Dong, L., Wang, R., Xue, J., Wei, F.: The era of 1-bit llms: All large language models are in 1.58 bits. arXiv preprint arXiv:2402.17764 (2024)
-
Malinovskii, V., Mazur, D., Ilin, I., Kuznedelev, D., Burlachenko, K., Yi, K., Alistarh, D., Richtarik, P.: Pv-tuning: Beyond straight-through estimation for extreme llm compression. Advances in Neural Information Processing Systems 37, 5074–5121 (2024)
-
Merity, S., Xiong, C., Bradbury, J., Socher, R.: Pointer sentinel mixture models. In: 5th International Conference on Learning Representations, ICLR 2017, Toulon, France, April 24-26, 2017, Conference Track Proceedings (2017), https://openreview.net/forum?id=Byj72udxe
-
Nagel, M., Amjad, R.A., Van Baalen, M., Louizos, C., Blankevoort, T.: Up or down? Adaptive rounding for post-training quantization. In: III, H.D., Singh, A. (eds.) Proceedings of the International Conference on Machine Learning. vol. 119, pp. 7197–7206. PMLR (13–18 Jul 2020), https://proceedings.mlr.press/v119/nagel20a.html
-
Paszke, A., Gross, S., Massa, F., Lerer, A., Bradbury, J., Chanan, G., Killeen, T., Lin, Z., Gimelshein, N., Antiga, L., et al.: Pytorch: An imperative style, high-performance deep learning library. Advances in neural information processing systems 32 (2019)
-
Raffel, C., Shazeer, N., Roberts, A., Lee, K., Narang, S., Matena, M., Zhou, Y., Li, W., Liu, P.J.: Exploring the limits of transfer learning with a unified text-to-text transformer. Journal of machine learning research 21(140), 1–67 (2020)
-
Sakaguchi, K., Bras, R.L., Bhagavatula, C., Choi, Y.: Winogrande: An adversarial winograd schema challenge at scale. vol. 64, pp. 99–106. ACM New York, NY, USA (2021)
-
Shao, W., Chen, M., Zhang, Z., Xu, P., Zhao, L., Li, Z., Zhang, K., Gao, P., Qiao, Y., Luo, P.: Omniquant: Omnidirectionally calibrated quantization for large language models. In: The Twelfth International Conference on Learning Representations, ICLR 2024, Vienna, Austria, May 7-11, 2024 (2024), https://openreview.net/forum?id=8Wuvhh0LYW
-
Stock, P., Joulin, A., Gribonval, R., Graham, B., Jégou, H.: And the bit goes down: Revisiting the quantization of neural networks. In: 8th International Conference on Learning Representations, ICLR 2020, Addis Ababa, Ethiopia, April 26-30, 2020 (2020), https://openreview.net/forum?id=rJehVyrKwH
-
Tian, K., Jiang, Y., Yuan, Z., Peng, B., Wang, L.: Visual autoregressive modeling: Scalable image generation via next-scale prediction. Advances in neural information processing systems 37, 84839–84865 (2024)
-
Touvron, H., Martin, L., Stone, K., Albert, P., Almahairi, A., Babaei, Y., Bashlykov, N., Batra, S., Bhargava, P., Bhosale, S., et al.: Llama 2: Open foundation and fine-tuned chat models. arXiv preprint arXiv:2307.09288 (2023)
-
Tseng, A., Chee, J., Sun, Q., Kuleshov, V., Sa, C.D.: Quip#: Even better LLM quantization with hadamard incoherence and lattice codebooks. In: Forty-first International Conference on Machine Learning, ICML 2024, Vienna, Austria, July 21-27, 2024 (2024), https://openreview.net/forum?id=9BrydUVcoe
-
Tseng, A., Sun, Q., Hou, D., De, C.: Qtip: Quantization with trellises and incoherence processing. Advances in Neural Information Processing Systems 37, 59597–59620 (2024)
-
Van Baalen, M., Kuzmin, A., Koryakovskiy, I., Nagel, M., Couperus, P., Bastoul, C., Mahurin, E., Blankevoort, T., Whatmough, P.: Gptvg: The blessing of dimensionality for llm quantization. arXiv preprint arXiv:2402.15319 (2024)
-
Van Den Oord, A., Vinyals, O., et al.: Neural discrete representation learning. Advances in neural information processing systems 30 (2017)
A. Prutianova, A. Bogdanova et al.
- Vanderschueren, A., De Vleeschouwer, C.: Are straight-through gradients and soft-thresholding all you need for sparse training? In: Proceedings of the IEEE/CVF Winter Conference on Applications of Computer Vision. pp. 3808–3817 (2023)
- Weber, M., Fu, D.Y., Anthony, Q., Oren, Y., Adams, S., Alexandrov, A., Lyu, X., Nguyen, H., Yao, X., Adams, V., et al.: Redpajama: an open dataset for training large language models. vol. 37, pp. 116462–116492 (2024)
- Wei, X., Gong, R., Li, Y., Liu, X., Yu, F.: Qdrop: Randomly dropping quantization for extremely low-bit post-training quantization. In: The Tenth International Conference on Learning Representations, ICLR 2022, Virtual Event, April 25-29, 2022 (2022), https://openreview.net/forum?id=ySQH0oDyp7
- Wolf, T., Debut, L., Sanh, V., Chaumond, J., Delangue, C., Moi, A., Cistac, P., Rault, T., Louf, R., Funtowicz, M., et al.: Huggingface's transformers: State-of-the-art natural language processing. arXiv preprint arXiv:1910.03771 (2019)
- Xiao, G., Lin, J., Seznec, M., Wu, H., Demouth, J., Han, S.: Smoothquant: Accurate and efficient post-training quantization for large language models. In: Krause, A., Brunskill, E., Cho, K., Engelhardt, B., Sabato, S., Scarlett, J. (eds.) International Conference on Machine Learning, ICML 2023, 23-29 July 2023, Honolulu, Hawaii, USA. Proceedings of Machine Learning Research, vol. 202, pp. 38087–38099. PMLR (2023), https://proceedings.mlr.press/v202/xiao23c.html
- Zellers, R., Holtzman, A., Bisk, Y., Farhadi, A., Choi, Y.: Hellaswag: Can a machine really finish your sentence? In: Korhonen, A., Traum, D.R., Márquez, L. (eds.) Proceedings of the 57th Conference of the Association for Computational Linguistics, ACL 2019, Florence, Italy, July 28- August 2, 2019, Volume 1: Long Papers. pp. 4791–4800. Association for Computational Linguistics (2019), https://doi.org/10.18653/v1/p19-1472
A Existing VQ schemes
In this section, we summarize quantization schemes employed in related works. To introduce our framework, we formally define a VQ scheme in Section 3.2 as a pair , where denotes the codebook matrix search space and denotes the index matrix search space. In Table 5, we specify such pairs that characterize the quantization schemes adopted in prior works.
These schemes are used in our experiments with TVQ for index optimization. In TVQ+BasicVQ, we use the same scheme as in AQLM and VPTQ, where codebook and index matrices are unconstrained. In TVQ+Quip#, we use the scheme from QuIP#, where the codebook matrix is restricted to a single E8P codebook, which remains fixed throughout the entire optimization process, while the index matrices are unconstrained. For details on the construction and properties of the E8P codebook, we refer the reader to the QuIP# paper. In TVQ+QTIP, we employ the same scheme as QTIP, where hybrid (HYB) codebooks are constrained to those that can be constructed via bitwise operations on vectors drawn from a smaller, unconstrained codebook . The index matrices are restricted to those that can be compressed using the bitshift trellis bit-packing algorithm. For a detailed explanation of the bitshift trellis algorithm and the HYB codebooks, we refer to the QTIP paper.
B TVQ implementation
In this section, we detail the TVQ implementation. Algorithm 1 presents the pseudocode for the TVQ Training Pipeline described in Section 3.4. Listing 1 details our PyTorch implementation of the quantized weight classes used during Stage-1. In a pretrained model, the weights in the linear layers of Transformer blocks are replaced with one of the classes from Listing 1. Class WeightTVQ implements the core logic of the proposed TVQ method. Classes WeightTVQ_BasicVQ, WeightTVQ_QTIP, and WeightTVQ_QUIPsharp implement corresponding quantization schemes. IndicesUpdatesScheduler is used for scheduled indices updates (see Section 3.5 and Section 4.4).
C Experimental Setup details
In this section, we report the full set of hyperparameters employed at each stage of our pipeline. All experiments were conducted using the PyTorch library.
Table 8 provides the hyperparameters used for Stage-1. We used the Adam optimizer with default weight decay and beta values, along with the Cosine Annealing scheduler. All models were optimized using the reconstruction loss. The remaining hyperparameters varied depending on the specific configuration and are reported in the table. Table 9 provides the hyperparameters for Stage-2. During Stage-2, we optimize the KL divergence between the outputs of the
A. Prutianova, A. Bogdanova et al.
Table 5. Summary of quantization schemes used in prior works. From the optimization perspective, each vector quantization scheme is formally defined by the set of permissible codebooks and the set of permissible index matrices (see Section 3.2).
| Method | VQ scheme | |
|---|---|---|
| Codebook matrix constraints | Index matrix constraints | |
| AQLM, VPTQ | (unconstrained) | (unconstrained) |
| QuIP# | (unconstrained) | |
| QTIP | where isan unconstrainedsmaller codebookthat fits into L1 GPU cache | for all ,where is the average bitwidthof the packed index matrix |
quantized model and the original full-precision model. The parameters listed include learning rates, batch sizes, number of optimization steps, and other settings relevant to the fine-tuning process.
Table 6. Ablation study of the Approximate Nearest Neighbor search for the 2-bit Llama2-7B. denotes the number of Voronoi cells, — the number of visited cells. The grey line highlights the selected setting. The table shows evaluation metrics for the 2-bit Llama2-7B model after Stage-1, without the fine-tuning Stage-2.
| Search Accuracy | N | K | Speedup | W2↓ | C4↓ |
|---|---|---|---|---|---|
| 99.9% | 256 | 16 | 6.70 | 8.70 | |
| 99% | 1024 | 16 | 6.64 | 8.68 | |
| 98% | 256 | 8 | 6.63 | 8.69 | |
| 95% | 512 | 8 | 6.68 | 8.73 | |
| 80% | 1024 | 4 | 6.84 | 8.92 | |
| 60% | 1024 | 2 | 7.13 | 9.15 |
D Ablation study of Approximate Nearest Neighbor Search
In TVQ+BasicVQ experiments, the index function , defined in Equation (3), maps each vector of the trainable weight to the index of its Nearest-Neighbor in the codebook . The exact Nearest-Neighbor search requires computing pairwise distances between all codebook vectors and trainable weight vectors, reaching trillions of distance calculations for modern LLMs. As a result, the exhaustive search presents a significant computational bottleneck.
To solve this problem, we adopt the Approximate Nearest-Neighbor (ANN) search via Voronoi cells, which is implemented in the open-source library FAISS. This approach groups codebook vectors into clusters named Voronoi cells. Then, for each vector of the trainable weight , it finds several nearest cells and performs an exhaustive Nearest-Neighbor search only within these cells. Thus, a large number of distant vectors is excluded from the search space, and a naive exhaustive Nearest-Neighbor search is only performed with the remainder.
We analyze the impact of the Approximate Nearest-Neighbor search parameters on the final model quality. We conduct experiments, varying the parameters that affect the search quality, particularly the number of Voronoi cells and the number of cells for exhaustive search . Search quality is evaluated using accuracy, which is defined as the percentage of queries where the approximate search matches the exact search. Additionally, we measure the speedup by comparing the approximate search against the exact search implemented on a single NVIDIA 32GB Volta100 GPU. As shown in Table 6, the approximate search that reaches 99.99% of accuracy is five times faster than the exact search. The model quality remains unaffected even when search accuracy drops to 95%, and the decline is minimal even at 80% accuracy. These findings suggest that opting for ANN search over exact search is unlikely to degrade the model quality.
E Distribution of the number of VQ parameters
Since different VQ schemes employ distinct configuration settings — such as codebook sizes, vector dimensionality, and storage strategies — the distribution of the number of VQ parameters and their storage requirements varies accordingly.
In the BasicVQ scheme, all weights in both index matrices and codebooks are subject to optimization and are retained for inference. For example, in 2-bit-per-weight quantization of the 7-8B models, 1.86 bits per weight contain information about the index matrices, while only 0.16 bits per weight correspond to the codebooks. For larger 70B models, index matrices constitute an even larger fraction of the total weights (2 bits per weight for index matrices vs. 0.07 bits per weight for codebooks). Detailed estimations of the Basic-VQ model size are provided in the AQLM paper, which we refer to. In the QuIP# and QTIP schemes, codebooks contain fewer than 0.01 bits per weight of adjustable parameters, while the index matrices contain approximately 2 adjustable bits per weight.
These observations conclude that the largest part of the parameters resides in index matrices, underscoring the importance of their optimization.
A. Prutianova, A. Bogdanova et al.
Table 7. Index matrix update time in seconds, measured on a single NVIDIA 80GB Ampere100 GPU (≈2 bits VQ, ; for Quip# and BasicVQ, for QTIP).
| Method | Index update algorithm | Update time (sec) |
|---|---|---|
| TVQ+Quip# | E8-lattice NN search | 0.236 0.001 |
| TVQ+BasicVQ | ANN search | 1.31 0.02 |
| TVQ+QTIP | Viterbi search | 41.8 0.2 |
Algorithm 1 Training Pipeline
Input: pretrained model fp_model, input data D, weight class WeightTVQ_Class, indices recomputation step upd_step, number of optimization steps in Stage-1 , Stage-2
Output: vector-quantized model vq_model
1: # Create vector quantized model 2: vq_model = copy(fp_model) 3: for layer linear_layers(vq_model) do 4: layer.weight = WeightTVQ_Class( layer.weight, upd_step ) 5: end for 6: # Block-Wise PTQ (Stage-1) 7: X = fp_model.input_embeddings(D) 8: 9: for i = 1 to model.num_blocks do 10: fp_block = fp_model.get_block(i) 11: vq_block = vq_model.get_block(i) 12: # Optimize block 13: for j = 1 to do 14: 15: # k - batch index at iteration j 16: Calculate gradients of 17: Update W and C (optionally) with Adam 18: end for 19: # Collect input data for the next block 20: X = fp_block(X) 21: 22: end for 23: # End-to-End Fine-tuning (Stage-2) 24: for j = 1 to do 25: 26: # k - batch index at iteration j 27: Calculate gradients of 28: Update trainable parameters with Adam 29: end for
Table 8. Training parameters used in Stage-1: input data sequence length (SL), number of sequences (SN), number of training epochs (E), batch size (BS), parameters of the Approximate Nearest-Neighbor search (ANNs, the number of Voronoi cells/the number of visited cells), indices recomputation step (), learning rate for the codebooks (), learning rate for the weights ().
| Model | Method | SL | SN | E | BS | ANNs | |||
|---|---|---|---|---|---|---|---|---|---|
| Llama2-7B | TVQ+BasicVQ | 4096 | 2048 | 2 | 8 | 256/8 | 1 | 5e-5 | 5e-5 |
| TVQ+QuIP# | 4096 | 2048 | 2 | 8 | - | 1 | - | 1e-5 | |
| TVQ+QTIP | 4096 | 2048 | 2 | 8 | - | 16 | - | 1e-5 | |
| Llama2-70B | TVQ+BasicVQ | 4096 | 2048 | 1 | 8 | 128/8 | 1 | 5e-5 | 5e-5 |
| TVQ+QuIP# | 4096 | 2048 | 1 | 8 | - | 2 | - | 1e-5 | |
| TVQ+QTIP | 4096 | 2048 | 1 | 8 | - | 16 | - | 1e-5 | |
| Mistral-7B-v0.1 | TVQ+BasicVQ | 8192 | 1024 | 2 | 4 | 256/8 | 1 | 1e-4 | 2e-5 |
| TVQ+QuIP# | 8192 | 1024 | 2 | 4 | - | 1 | - | 6e-6 | |
| TVQ+QTIP | 8192 | 1024 | 2 | 4 | - | 16 | - | 2e-6 | |
| Llama3-8B | TVQ+BasicVQ | 4096 | 2048 | 4 | 8 | 256/8 | 1 | 3e-4 | 1e-4 |
| TVQ+QuIP# | 4096 | 2048 | 2 | 8 | - | 1 | - | 5e-6 | |
| TVQ+QTIP | 4096 | 2048 | 4 | 8 | - | 8 | - | 4e-6 | |
| Llama3-70B | TVQ+BasicVQ | 4096 | 2048 | 1 | 8 | 128/8 | 4 | 5e-5 | 5e-5 |
| TVQ+QuIP# | 4096 | 2048 | 1 | 8 | - | 2 | - | 5e-6 | |
| TVQ+QTIP | 4096 | 2048 | 1 | 8 | - | 16 | - | 5e-6 |
Table 9. Training parameters used in the Stage-2 of optimization: input data sequence length (SL), number of sequences (SN), batch size (BS), learning rate for the codebooks (), learning rate for the incoherence processing parameters (), learning rate for the language modeling head ().
| Model | Method | SL | SN | BS | |||
|---|---|---|---|---|---|---|---|
| Llama2-7B | TVQ+BasicVQ | 4096 | 4096 | 50 | 1e-5 | - | - |
| TVQ+QuIP# | 4096 | 4096 | 50 | - | 5e-4 | 5e-5 | |
| TVQ+QTIP | 4096 | 4096 | 50 | 1e-3 | 5e-4 | 5e-5 | |
| Llama2-70B | TVQ+BasicVQ | 4096 | 4096 | 50 | 1e-5 | - | - |
| TVQ+QuIP# | 4096 | 8192 | 50 | - | 5e-4 | 5e-5 | |
| TVQ+QTIP | 4096 | 8192 | 50 | 1e-3 | 5e-4 | 5e-5 | |
| Mistral-7B-v0.1 | TVQ+BasicVQ | 8192 | 4096 | 50 | 1e-5 | - | - |
| TVQ+QuIP# | 8192 | 4096 | 50 | - | 5e-4 | 5e-5 | |
| TVQ+QTIP | 8192 | 4096 | 50 | - | 5e-4 | 5e-5 | |
| Llama3-8B | TVQ+BasicVQ | 8192 | 4096 | 50 | 1e-5 | - | - |
| TVQ+QuIP# | 8192 | 4096 | 50 | - | 5e-4 | 5e-5 | |
| TVQ+QTIP | 8192 | 8192 | 50 | 5e-3 | 5e-4 | 5e-5 | |
| Llama3-70B | TVQ+BasicVQ | 8192 | 1024 | 50 | 1e-5 | - | - |
| TVQ+QuIP# | 8192 | 1024 | 50 | - | 5e-4 | 5e-5 | |
| TVQ+QTIP | 8192 | 1024 | 50 | 5e-3 | 5e-4 | 5e-5 |
A. Prutianova, A. Bogdanova et al.
listing 1 PyTorch implementation of TVQ Weight Classes
class IndicesUpdateScheduler: def init(self, upd_step=1): self.upd_step = upd_step self.step = 0
def next(self): self.step += 1 state = self.step % self.upd_step return state==0
class WeightTVQ(nn.Module): def init(self, W_fp, codebook_init, indices_fn, processing, upd_step): super().init(()) self.processing = processing self.W = processing.preprocess(W_fp) self.C = codebook_init self.indices_fn = indices_fn self.I = self.indices_fn(self.W, self.C) self idx_upd_scheduler = IndicesUpdateScheduler(upd_step)
def forward(self): if next(self idx_upd_scheduler): self.I = self.indices_fn( self.W, self.C ) W_q = self.C[self.I] W_q = W_q + self.W - self.W.detach() return self.processing.postprocess(W_q)
def backward(self, grad_output): # automatic by PyTorch
class WeightTVQ_BasicVQ(WeightTVQ): def init(self, W, upd_step): processing = per_channel_scaling codebook = kmeans( processing.preprocess(W) ) indices_fn = approx_nn_search super().init(W, codebook, indices_fn, processing, upd_step)
class WeightTVQ_QTIP(WeightTVQ): def init(self, W, upd_step): processing = incoherence_processing codebook = qtip_hyb_codebook indices_fn = viterbi_search super().init(W, codebook, indices_fn, processing, upd_step)
class WeightTVQ_QUIPsharp(WeightTVQ): def init(self, W, upd_step): processing = incoherence_processing codebook = quip_sharp_E8_codebook indices_fn = fast_E8_rounding super().init(W, codebook, indices_fn, processing, upd_step)
F Index updates computational costs
In TVQ, index matrices are computed according to Equation (3) defined in Section 3.3. It requires searching for the index matrix that minimizes the distance between the trainable latent weight and the dequantized weight. The search is performed in the index matrix search space ; therefore searching algorithm varies for different VQ schemes. Table 7 summarizes the computational resources needed for different search algorithms.
G Training acceleration details
In addition to accelerating index matrix updates, we employ standard techniques to optimize overall training efficiency. For block-wise training in Stage-1 of TVQ, we parallelize index matrices updates inside a Transformer block across multiple processing units. Additionally, we cache intermediate activations and in Random Access Memory to reduce the number of forward passes. We also leverage popular tools such as the JIT-compiling PyTorch API, mixed-precision matrix multiplication, activation checkpointing, and batch accumulation.