Manuscript Offprint

arXiv:2610.41822

Trainable Vector Quantization for Large Language Models

Anastasiia Prutianova, Alina Bogdanova, Mikhail Shutov, Dmitrii Poimanov, Anatoly Gorkov, Ilia Zharikov

Anastasiia Prutianova, Alina Bogdanova, Mikhail Shutov, Dmitrii Poimanov, Anatoly Gorkov, and Ilia Zharikov(✉)

Huawei Technologies Co. Ltd.

ilya.zharikov@huawei.com

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 ∥(Wq−W)X∥2\|(W^q - W)X\|_2, where WqW^q and WW are compressed and original weight matrices, XX is a matrix of input activations. They rely on single-layer linearity and L2L_2 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.

References (43)