Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up

VPTQ, A Flexible and Extreme low-bit quantization algorithm

License

NotificationsYou must be signed in to change notification settings

microsoft/VPTQ

Repository files navigation

TL;DR

Vector Post-Training Quantization (VPTQ) is a novel Post-Training Quantization method that leveragesVector Quantization to high accuracy on LLMs at an extremely low bit-width (<2-bit).VPTQ can compress 70B, even the 405B model, to 1-2 bits without retraining and maintain high accuracy.

  • Better Accuracy on 1-2 bits, (405B @ <2bit, 70B @ 2bit)
  • Lightweight Quantization Algorithm: only cost ~17 hours to quantize 405B Llama-3.1
  • Agile Quantization Inference: low decode overhead, best throughput, and TTFT

News

  • [2025-03-12] VPTQ now provides preliminary support for inference withDeepseek R1! With our quantized models, you can efficiently run Deepseek R1 on A100 GPUs.TutorialInference Code
  • [2025-02-27]aphrodite-engine is the first inference engine which supports our VPTQ, Thanks for @AlpinDale's contribute!
  • [2025-01-18] VPTQ v0.0.5 released, featuring cmake support and an enhanced build pipeline!
  • [2025-01-13] VPTQ is formly support by Transformers in its wheel package release sincev4.48.0.
  • [2024-12-20] 🚀VPTQ ❤️ Huggingface Transformers VPTQ support has been merged into Huggingface Transformers main branch! Check out thecommit and our Colab example:VPTQ in Colab
  • [2024-12-15] 🌐 Open source community contributesMeta Llama 3.3 70B @ 1-4 bits models
  • [2024-11-01] 📦 VPTQ is now available onPyPI! You can install it easily using the command:pip install vptq.
  • [2024-10-28] ✨ VPTQ algorithm early-released atalgorithm branch, and checkout thetutorial.
  • [2024-10-22] 🌐 Open source community contributesMeta Llama 3.1 Nemotron 70B models, checkhow VPTQ counts 'r' on local GPU. We are continuing to work on quantizing the 4-6 bit versions. Please stay tuned!
  • [2024-10-21] 🌐 Open source community contributesMeta Llama 3.1 405B @ 3/4 bits models
  • [2024-10-18] 🌐 Open source community contributesMistral Large Instruct 2407 (123B) models
  • [2024-10-14] 🚀 Add earlyROCm support.
  • [2024-10-06] 🚀Try VPTQ on Google Colab.VPTQ In Colab
  • [2024-10-05] 🚀Add free Huggingface Demo:Huggingface Demo
  • [2024-10-04] ✏️ Updated the VPTQ tech report and fixed typos.
  • [2024-09-20] 🌐 Inference code is now open-sourced on GitHub—join us and contribute!
  • [2024-09-20] 🎉 VPTQ paper has been accepted for the main track at EMNLP 2024.

Installation

Dependencies

  • CUDA toolkit
  • python 3.10+
  • torch >= 2.3.0
  • transformers >= 4.44.0
  • Accelerate >= 0.33.0
  • flash_attn >= 2.5.0
  • latest datasets
  • cmake >= 3.18.0

Install VPTQ on Your Machine

Recommendation: To save time on building the package, please install VPTQ directly from the latest release on PyPI:

pip install vptq

or from:

https://github.com/microsoft/VPTQ/releases

Install from PyPI

To install from PyPI, run:

pip install git+https://github.com/microsoft/VPTQ.git --no-build-isolation

Build from Source

If a release package is not available, you can build the package from the source code:

NOTE: Ensure Python dependencies and the CUDA toolkit are installed, and thatnvcc is available in yourPATH.

  1. Build the wheel:

    python setup.py build bdist_wheel# Install the built wheelpip install dist/vptq-{version}.whl# Replace {version} with the version number
  2. Clean the build:

    python setup.py clean

Example: Run Llama 3.1 70b on RTX4090 (24G @ ~2bits) in real timeLlama3 1-70b-prompt


VPTQ is an ongoing project. If the open-source community is interested in optimizing and expanding VPTQ, please feel free to submit an issue or DM.


Evaluation

Models from Open Source Community

⚠️ The repository only provides a method of model quantization algorithm.

⚠️ The open-source communityVPTQ-community provides models based on the technical report and quantization algorithm.

⚠️ The repository cannot guarantee the performance of those models.

Quick Estimation of Model Bitwidth (Excluding Codebook Overhead):

  • Model Naming Convention: The model's name includes thevector length$v$,codebook (lookup table) size, andresidual codebook size. For example, "Meta-Llama-3.1-70B-Instruct-v8-k65536-256-woft" is "Meta-Llama-3.1-70B-Instruct", where:

    • Vector Length: 8
    • Number of Centroids: 65536 (2^16)
    • Number of Residual Centroids: 256 (2^8)
  • Equivalent Bitwidth Calculation:

    • Index: log2(65536) = 16 / 8 = 2 bits
    • Residual Index: log2(256) = 8 / 8 = 1 bit
    • Total Bitwidth: 2 + 1 = 3 bits
  • Model Size Estimation: 70B * 3 bits / 8 bits per Byte = 26.25 GB

  • Note: This estimate does not include the size of the codebook (lookup table), other parameter overheads, and the padding overhead for storing indices. For the detailed calculation method, please refer toTech Report Appendix C.2.

Model SeriesCollections(Estimated) Bit per weight
DeeSseek R1HF 🤗2.x bits, reshard for 4 GPUs2 bits, reshard for 4 GPUs3 bits, resahrd for 4 GPUs,3 bits2 bits
Llama 3.3 70B InstructHF 🤗4 bits3 bits2 bits (1)2 bits (2)1.875 bits1.625 bits
Llama 3.1 Nemotron 70B Instruct HFHF 🤗4 bits3 bits2 bits (1)2 bits (2)1.875 bits1.625 bits1.5 bits
Llama 3.1 8B InstructHF 🤗4 bits3.5 bits3 bits2.3 bits
Llama 3.1 70B InstructHF 🤗4 bits3 bits2.25 bits2 bits (1)2 bits (2)1.93 bits1.875 bits1.75 bits
Llama 3.1 405B InstructHF 🤗4 bits3 bits2 bits1.875 bits1.625 bits1.5 bits (1)1.5 bits (2)1.43 bits1.375 bits
Mistral Large Instruct 2407 (123B)HF 🤗4 bits3 bits2 bits (1)2 bits (2)1.875 bits1.75 bits1.625 bits1.5 bits
Qwen 2.5 7B InstructHF 🤗4 bits3 bits2 bits (1)2 bits (2)2 bits (3)
Qwen 2.5 14B InstructHF 🤗4 bits3 bits2 bits (1)2 bits (2)2 bits (3)
Qwen 2.5 32B InstructHF 🤗4 bits3 bits2 bits (1)2 bits (2)2 bits (3)
Qwen 2.5 72B InstructHF 🤗4 bits3 bits2.38 bits2.25 bits (1)2.25 bits (2)2 bits (1)2 bits (2)1.94 bits
Reproduced from the tech reportHF 🤗Results from the open source community for reference only, please use them responsibly.
Hessian and Inverse Hessian MatrixHF 🤗Collected from RedPajama-Data-1T-Sample, followingQuip#

Language Generation Example

To generate text using the pre-trained model, you can use the following code snippet:

The modelVPTQ-community/Meta-Llama-3.1-70B-Instruct-v8-k65536-0-woft (~2 bit) is provided by open source community. The repository cannot guarantee the performance of those models.

python-mvptq--model=VPTQ-community/Meta-Llama-3.1-70B-Instruct-v8-k65536-0-woft--prompt="Explain: Do Not Go Gentle into That Good Night"

Llama3 1-70b-prompt

Terminal Chatbot Example

Launching a chatbot:Note that you must use a chat model for this to work

python-mvptq--model=VPTQ-community/Meta-Llama-3.1-70B-Instruct-v8-k65536-0-woft--chat

Llama3 1-70b-chat

Huggingface Transformers API Example:

Now, huggingface transformers main branch supports VPTQ:

#! pip install transformers>=4.48.0 -U#! pip install vptq -UfromtransformersimportAutoModelForCausalLM,AutoTokenizermodel_name="VPTQ-community/Meta-Llama-3.3-70B-Instruct-v16-k65536-65536-woft"# Load VPTQ-quantized model directly from HuggingFace Hubmodel=AutoModelForCausalLM.from_pretrained(model_name,device_map="auto")tokenizer=AutoTokenizer.from_pretrained(model_name)# Simple inferenceprompt="Explain: Do not go gentle into that good night."output=model.generate(**tokenizer(prompt,return_tensors="pt").to(model.device))print(tokenizer.decode(output[0],skip_special_tokens=True))

Python API Example from VPTQ package:

Using the Python API from VPTQ package:

importvptqimporttransformersmodel_name="VPTQ-community/Meta-Llama-3.1-70B-Instruct-v8-k65536-0-woft"tokenizer=transformers.AutoTokenizer.from_pretrained(model_name)m=vptq.AutoModelForCausalLM.from_pretrained(model_name,device_map="auto")prompt="Explain: Do Not Go Gentle into That Good Night"out=m.generate(**tokenizer(prompt,return_tensors="pt").to("cuda"),max_new_tokens=100,pad_token_id=2)print(tokenizer.decode(out[0],skip_special_tokens=True))

Gradio Web App Example

An environment variable is available to control share link or not.export SHARE_LINK=1

python -m vptq.app

VPTQ Algorithm Early-released

VPTQ algorithm early-released atalgorithm branch, and checkout thetutorial.

Tech Report

VPTQ_tech_report

Scaling model size significantly challenges the deployment and inference of Large Language Models (LLMs). Due to the redundancy in LLM weights, recent research has focused on pushing weight-only quantization to extremely low-bit (even down to 2 bits). It reduces memory requirements, optimizes storage costs, and decreases memory bandwidth needs during inference. However, due to numerical representation limitations, traditional scalar-based weight quantization struggles to achieve such extreme low-bit. Recent research on Vector Quantization (VQ) for LLMs has demonstrated the potential for extremely low-bit model quantization by compressing vectors into indices using lookup tables.

Read tech report atTech Report andarXiv Paper

Early Results from Tech Report

VPTQ achieves better accuracy and higher throughput with lower quantization overhead across models of different sizes. The following experimental results are for reference only; VPTQ can achieve better outcomes under reasonable parameters, especially in terms of model accuracy and inference speed.

ModelbitwidthW2↓C4↓AvgQA↑tok/s↑mem(GB)cost/h↓
LLaMA-2 7B2.026.138.0758.239.92.282
2.265.957.8759.435.72.483.1
LLaMA-2 13B2.025.327.1562.426.94.033.2
2.185.287.0463.118.54.313.6
LLaMA-2 70B2.073.935.7268.69.719.5419
2.113.925.7168.79.720.0119

Road Map

  • Merge the quantization algorithm into the public repository.
  • Release onPypi
  • Improve the implementation of the inference kernel (e.g., CUDA, ROCm, Triton) and apply kernel fusion by combining dequantization (lookup) and Linear (GEMM) to enhance inference performance.
  • Support VLM models @YangWang92
  • Contribute VPTQ toHuggingface Transformerscommit
  • Contribute VPTQ to vLLM, LLM Compressor
  • Contribute VPTQ to llama.cpp/exllama.
  • Contribute VPTQ to Edge devices deployment.
  • TBC

Project main members:

  • Yifei Liu (@lyf-00)
  • Jicheng Wen (@wejoncy)
  • Ying Cao (@lcy-seso)
  • Yang Wang (@YangWang92)

Acknowledgement

  • We thank forJames Hensman for his crucial insights into the error analysis related to Vector Quantization (VQ), and his comments on LLMs evaluation are invaluable to this research.
  • We are deeply grateful for the inspiration provided by the papers QUIP, QUIP#, GPTVQ, AQLM, WoodFisher, GPTQ, and OBC.

Publication

EMNLP 2024 Main

@inproceedings{  vptq,title={VPTQ: Extreme Low-bit Vector Post-Training Quantization for Large Language Models},author={Yifei Liu and          Jicheng Wen and          Yang Wang and          Shengyu Ye and          Li Lyna Zhang and          Ting Cao and          Cheng Li and          Mao Yang},booktitle={The 2024 Conference on Empirical Methods in Natural Language Processing},year={2024},}

Star History

Star History Chart


Limitation of VPTQ

  • ⚠️ VPTQ should only be used for research and experimental purposes. Further testing and validation are needed before you use it.
  • ⚠️ The repository only provides a method of model quantization algorithm. The open-source community may provide models based on the technical report and quantization algorithm by themselves, but the repository cannot guarantee the performance of those models.
  • ⚠️ VPTQ is not capable of testing all potential applications and domains, and VPTQ cannot guarantee the accuracy and effectiveness of VPTQ across other tasks or scenarios.
  • ⚠️ Our tests are all based on English texts; other languages are not included in the current testing.

Contributing

This project welcomes contributions and suggestions. Most contributions require you to agree to aContributor License Agreement (CLA) declaring that you have the right to, and actually do, grant usthe rights to use your contribution. For details, visithttps://cla.opensource.microsoft.com.

When you submit a pull request, a CLA bot will automatically determine whether you need to providea CLA and decorate the PR appropriately (e.g., status check, comment). Simply follow the instructionsprovided by the bot. You will only need to do this once across all repos using our CLA.

This project has adopted theMicrosoft Open Source Code of Conduct.For more information see theCode of Conduct FAQ orcontactopencode@microsoft.com with any additional questions or comments.

Trademarks

This project may contain trademarks or logos for projects, products, or services. Authorized use of Microsofttrademarks or logos is subject to and must followMicrosoft's Trademark & Brand Guidelines.Use of Microsoft trademarks or logos in modified versions of this project must not cause confusion or imply Microsoft sponsorship.Any use of third-party trademarks or logos are subject to those third-party's policies.


[8]ページ先頭

©2009-2025 Movatter.jp