README.md

February 21, 2025 Β· View on GitHub

DeepCompressor Logo

Model Compression Toolbox for Large Language Models and Diffusion Models

Apache License

News

  • [2025/02] πŸŽ‰ QServe has been accepted to MLSys 2025!
  • [2025/01] πŸŽ‰ SVDQuant has been accepted to ICLR 2025 (Spotlight)!
  • [2024/12] πŸŽ‰ QServe has been integratedd into NVIDIA TensorRT-LLM!
  • [2024/11] πŸ”₯ Our latest W4A4 diffusion model quantization work SVDQuant algorithm and Nunchaku system is publicly released! Check our paper!
  • [2024/05] πŸ”₯ Our latest W4A8KV4 LLM quantization work QoQ algorithm and QServe system is publicly released! QoQ is short for quattuor-octō-quattuor which is 4-8-4 in latin. Check our paper!

Key Features

DeepCompressor is an open source model compression toolbox for large language models and diffusion models based on PyTorch. DeepCompressor currently supports fake quantization with any integer and floating-point data type within 8 bits, e.g., INT8, INT4 and FP4_E2M1. Here are examples that implement the following algorithms.

DeepCompressor also contains examples that integrate with other inference libraries.

Installation

Install from Source

  1. Clone this repository and navigate to deepcompressor folder
git clone https://github.com/mit-han-lab/deepcompressor
cd deepcompressor
  1. Install Package
conda env create -f environment.yml
poetry install

Highlights

SVDQuant: Absorbing Outliers by Low-Rank Components for 4-Bit Diffusion Models

[Website][Paper][Nunchaku Inference System]

Diffusion models have been proven highly effective at generating high-quality images. However, as these models grow larger, they require significantly more memory and suffer from higher latency, posing substantial challenges for deployment. In this work, we aim to accelerate diffusion models by quantizing their weights and activations to 4 bits. At such an aggressive level, both weights and activations are highly sensitive, where conventional post-training quantization methods for large language models like smoothing become insufficient. To overcome this limitation, we propose SVDQuant, a new 4-bit quantization paradigm. Different from smoothing which redistributes outliers between weights and activations, our approach absorbs these outliers using a low-rank branch. We first consolidate the outliers by shifting them from activations to weights, then employ a high-precision low-rank branch to take in the weight outliers with Singular Value Decomposition (SVD). This process eases the quantization on both sides. However, naΓ―vely running the low-rank branch independently incurs significant overhead due to extra data movement of activations, negating the quantization speedup. To address this, we co-design an inference engine Nunchaku that fuses the kernels of the low-rank branch into those of the low-bit branch to cut off redundant memory access. It can also seamlessly support off-the-shelf low-rank adapters (LoRAs) without the need for re-quantization. Extensive experiments on SDXL, PixArt-βˆ‘, and FLUX.1 validate the effectiveness of SVDQuant in preserving image quality. We reduce the memory usage for the 12B FLUX.1 models by 3.5Γ—, achieving 3.0Γ— speedup over the 4-bit weight-only quantized baseline on the 16GB laptop 4090 GPU, paving the way for more interactive applications on PCs.

Teaser SVDQuant

Quality Evaluation

Below is the quality and similarity evaluated with 5000 samples from MJHQ-30K dataset. IR means ImageReward. Our 4-bit results outperform other 4-bit baselines, effectively preserving the visual quality of 16-bit models.

ModelPrecisionMethodFID (↓\downarrow)IR (↑\uparrow)LPIPS (↓\downarrow)PSNR( ↑\uparrow)
FLUX.1-dev (50 Steps)BF16--20.30.953----
W4A16NF420.60.9100.27219.5
INT W4A420.20.9080.32218.5
INT W4A4SVDQuant19.90.9350.22321.0
NVFP420.30.9610.34516.3
NVFP4SVDQuant20.30.9450.20521.5
FLUX.1-schnell (4 Steps)BF16--19.20.938----
W4A16NF418.90.9430.25718.2
INT W4A418.10.9620.34516.3
INT W4A4SVDQuant18.30.9510.25718.3
NVFP419.00.9520.27617.6
NVFP4SVDQuant18.90.9660.22819.0
SANA-1.6b (20 Steps)BF16--20.60.952----
INT W4A420.50.8940.33915.3
INT W4A4SVDQuant19.30.9350.22017.8
NVFP419.70.9290.23617.4
NVFP4SVDQuant20.20.9410.17619.0
PixArt-Sigma (20 Steps)FP16--16.60.944----
INT W4A8ViDiT-Q37.30.5730.61112.0
INT W4A4SVDQuant19.20.8780.32317.6
NVFP431.80.6600.51714.8
NVFP4SVDQuant16.60.9400.27118.5

QServe: W4A8KV4 Quantization for Efficient LLM Serving

[Website][Paper][QoQ Algorithm Code][QServe GPU System]

Quantization can accelerate large language model (LLM) inference. Going beyond INT8 quantization, the research community is actively exploring even lower precision, such as INT4. Nonetheless, state-of-the-art INT4 quantization techniques only accelerate low-batch, edge LLM inference, failing to deliver performance gains in large-batch, cloud-based LLM serving. We uncover a critical issue: existing INT4 quantization methods suffer from significant runtime overhead (20-90%) when dequantizing either weights or partial sums on GPUs. To address this challenge, we introduce QoQ, a W4A8KV4 quantization algorithm with 4-bit weight, 8-bit activation, and 4-bit KV cache. QoQ stands for quattuor-octo-quattuor, which represents 4-8-4 in Latin. QoQ is implemented by the QServe inference library that achieves measured speedup. The key insight driving QServe is that the efficiency of LLM serving on GPUs is critically influenced by operations on low-throughput CUDA cores. Building upon this insight, in QoQ algorithm, we introduce progressive quantization that can allow low dequantization overhead in W4A8 GEMM. Additionally, we develop SmoothAttention to effectively mitigate the accuracy degradation incurred by 4-bit KV quantization. In the QServe system, we perform compute-aware weight reordering and take advantage of register-level parallelism to reduce dequantization latency. We also make fused attention memory-bound, harnessing the performance gain brought by KV4 quantization. As a result, QServe improves the maximum achievable serving throughput of Llama-3-8B by 1.2Γ— on A100, 1.4Γ— on L40S; and Qwen1.5-72B by 2.4Γ— on A100, 3.5Γ— on L40S, compared to TensorRT-LLM.

QoQ-QServe QoQ

Perplexity Evaluation

Below is the WikiText2 perplexity evaluated with 2048 sequence length. The lower is the better.

MethodsPrecisionLlama-3.1 70BLlama-3.1 8BLlama-3 70BLlama-3 8BLlama-2 7BLlama-2 13BLlama-2 70BLlama 7BLlama 13BLlama 30BMistral 7BYi 34B
FP162.816.242.856.145.474.883.325.685.094.105.254.60
SmoothQuantW8A83.236.383.146.285.544.953.365.735.134.235.294.69
GPTQ-RW4A16 g1283.466.643.426.565.634.993.435.835.204.225.394.68
AWQW4A16 g1283.226.603.206.545.604.973.415.785.194.215.374.67
QuaRotW4A45.978.326.758.336.195.453.836.345.584.645.77-
SpinQuantW4A44.807.426.277.375.965.243.716.145.394.56--
AtomW4A4 g128--4.337.786.125.313.736.255.524.615.764.97
QoQW4A8KV43.686.873.656.815.755.113.505.925.274.315.444.73
QoQW4A8KV4 g1283.516.773.506.705.675.063.465.885.234.275.414.73

* SmoothQuant is evaluated with per-tensor static KV cache quantization.

Efficiency Benchmarks

When serving the large language models Llama-3-8B and Qwen1.5-72B on L40S and A100 GPUs, QServe demonstrates superior performance, achieving 1.2x-1.4x higher throughput compared to the leading industry solution, TensorRT-LLM, for Llama-3-8B, and a 2.4x-3.5x higher throughput for Qwen1.5-72B.

See more about benchmarking setting in QServe GPU Inference System.

L40S (48G)Llama-3-8BLlama-2-7BMistral-7BLlama-2-13BLlama-30BYi-34BLlama-2-70BQwen-1.5-72B
TRT-LLM-FP161326444156692OOMOOMOOMOOM
TRT-LLM-W4A161431681145736814831311917
TRT-LLM-W8A8263412712569440123364OOMOOM
Atom-W4A4--2120------------
QuaRot-W4A4--805--413133----15
QServe-W4A8KV4365623943774132750486928659
Throughput Increase*1.39x1.13x1.47x3.02x3.41x2.39x2.40x3.47x
A100 (80G)Llama-3-8BLlama-2-7BMistral-7BLlama-2-13BLlama-30BYi-34BLlama-2-70BQwen-1.5-72B
TRT-LLM-FP1625031549237148880145OOMOOM
TRT-LLM-W4A16237015492403871352569358143
TRT-LLM-W8A8239623342427127736164923553
Atom-W4A4--1160------------
QuaRot-W4A4--1370--289267----68
QServe-W4A8KV43005290829701741749803419340
Throughput Increase*1.20x1.25x1.22x1.36x2.07x1.23x1.17x2.38x

The absolute token generation throughputs of QServe and baseline systems (Unit: tokens/second. -- means unsupported). All experiments were conducted under the same device memory budget. Throughput increase of QServe is calculated with regard to the best baseline in each column.

Reference

If you find deepcompressor useful or relevant to your research, please kindly cite our paper:

@article{lin2024qserve,
  title={QServe: W4A8KV4 Quantization and System Co-design for Efficient LLM Serving},
  author={Lin*, Yujun and Tang*, Haotian and Yang*, Shang and Zhang, Zhekai and Xiao, Guangxuan and Gan, Chuang and Han, Song},
  journal={arXiv preprint arXiv:2405.04532},
  year={2024}
}

@article{
  li2024svdquant,
  title={SVDQuant: Absorbing Outliers by Low-Rank Components for 4-Bit Diffusion Models},
  author={Li*, Muyang and Lin*, Yujun and Zhang*, Zhekai and Cai, Tianle and Li, Xiuyu and Guo, Junxian and Xie, Enze and Meng, Chenlin and Zhu, Jun-Yan and Han, Song},
  journal={arXiv preprint arXiv:2411.05007},
  year={2024}
}

The following projects are highly related to QServe. Our group has developed full-stack application-algorithm-system-hardware support for efficient large models, receiving 9k+ GitHub stars and over 1M Huggingface community downloads.

You are also welcome to check out MIT HAN Lab for other exciting projects on Efficient Generative AI!

Acknowledgments

DeepCompressor is inspired by many open-source libraries, including (but not limited to) GPTQ, QuaRot and Atom.