News: The vLLM project has fully adopted AutoAWQ
It is no secret that maintaining a project such as AutoAWQ that has 2+ million downloads, 7000+ models on Huggingface, and 2.1k stars is hard for a solo developer who is doing this in their free time.
Important Notice:
AutoAWQ is officially deprecated and will no longer be maintained.
The last tested configuration used Torch 2.6.0 and Transformers 4.51.3.
If future versions of Transformers break AutoAWQ compatibility, please report the issue to the Transformers project.
Alternative:
AutoAWQ has been adopted by the vLLM Project:
https://github.com/vllm-project/llm-compressor
MLX-LM now supports AWQ for Mac devices:
http://github.com/ml-explore/mlx-lm
For further inquiries, feel free to reach out:
X:
_
LinkedIn:
https://www.linkedin.com/in/casper-hansen-804005170/
|
|
|
|
Supported by
AutoAWQ is an easy-to-use package for 4-bit quantized models. AutoAWQ speeds up models by 3x and reduces memory requirements by 3x compared to FP16. AutoAWQ implements the Activation-aware Weight Quantization (AWQ) algorithm for quantizing LLMs. AutoAWQ was created and improved upon from the
from MIT.
Latest News 🔥
[2024/06] CPU inference support (x86) - thanks Intel. Cohere and Phi3 support.
[2024/04] StableLM and StarCoder2 support.
[2024/03] Gemma support.
[2024/02] PEFT-compatible training in FP16.
[2024/02] AMD ROCm support through ExLlamaV2 kernels.
[2024/01] Export to GGUF, ExLlamaV2 kernels, 60% faster context processing.
[2023/12] Mixtral, LLaVa, QWen, Baichuan model support.
[2023/11] AutoAWQ inference has been integrated into 🤗 transformers. Now includes CUDA 12.1 wheels.
[2023/10] Mistral (Fused Modules), Bigcode, Turing support, Memory Bug Fix (Saves 2GB VRAM)
[2023/09] 1.6x-2.5x speed boost on fused models (now including MPT and Falcon).
[2023/09] Multi-GPU support, bug fixes, and better benchmark scripts available
[2023/08] PyPi package released and AutoModel class available
Install
Prerequisites
NVIDIA: Your NVIDIA GPU(s) must be of Compute Capability 7.5. Turing and later architectures are supported.
Your CUDA version must be CUDA 11.8 or later.
AMD: Your ROCm version must be compatible with Triton.
Intel CPU and Intel GPU: Your torch and intel_extension_for_pytorch package version should at least 2.4 for optimized performance.
Alternatively, you can rely on triton kernels for GPU, then you'll need to install
along with compatible torch and transformers. Easiest way is to use
.
Install from PyPi
There are a few ways to install AutoAWQ:
Default:
pip install autoawq
NOTE: The default installation includes no external kernels and relies on Triton for inference.
From release with kernels:
pip install autoawq[kernels]
NOTE: This requires you to match the latest torch version that the kernels were build with.
NOTE: This installs
https://github.com/casper-hansen/AutoAWQ_kernels
From main branch for Intel CPU and Intel XPU optimized performance:
pip install autoawq[cpu]
NOTE: Minimum of torch 2.4.0 is required.
Usage
Under examples, you can find examples of how to quantize, run inference, and benchmark AutoAWQ models.
INT4 GEMM vs INT4 GEMV vs FP16
There are two versions of AWQ: GEMM and GEMV. Both names relate to how matrix multiplication runs under the hood. We suggest the following:
GEMV (quantized): 20% faster than GEMM, only batch size 1 (not good for large context).
GEMM (quantized): Much faster than FP16 at batch sizes below 8 (good with large contexts).
FP16 (non-quantized): Recommended for highest throughput:
.
Compute-bound vs Memory-bound
At small batch sizes with small 7B models, we are memory-bound. This means we are bound by the bandwidth our GPU has to push around the weights in memory, and this is essentially what limits how many tokens per second we can generate. Being memory-bound is what makes quantized models faster because your weights are 3x smaller and can therefore be pushed around in memory much faster. This is different from being compute-bound where the main time spent during generation is doing matrix multiplication.
In the scenario of being compute-bound, which happens at higher batch sizes, you will not gain a speed-up using a W4A16 quantized model because the overhead of dequantization will slow down the overall generation. This happens because AWQ quantized models only store the weights in INT4 but perform FP16 operations during inference, so we are essentially converting INT4 -> FP16 during inference.
Fused modules
Fused modules are a large part of the speedup you get from AutoAWQ. The idea is to combine multiple layers into a single operation, thus becoming more efficient. Fused modules represent a set of custom modules that work separately from Huggingface models. They are compatible with model.generate() and other Huggingface methods, which comes with some inflexibility in how you can use your model if you activate fused modules:
Fused modules are activated when you use fuse_layers=True.
A custom cache is implemented. It preallocates based on batch size and sequence length. You cannot change the sequence length after you have created your model.
Reference: AutoAWQForCausalLM.from_quantized(max_seq_len=seq_len, batch_size=batch_size)
The main accelerator in the fused modules comes from FasterTransformer, which is only compatible with Linux.
The past_key_values from model.generate() are only dummy values, so they cannot be used after generation.
Examples
More examples can be found in the
.
QuantizationExpect this to take 10-15 minutes on smaller 7B models, and around 1 hour for 70B models.
fromawqimportAutoAWQForCausalLMfromtransformersimportAutoTokenizermodel_path='mistralai/Mistral-7B-Instruct-v0.2'quant_path='mistral-instruct-v0.2-awq'quant_config= { "zero_point": True, "q_group_size": 128, "w_bit": 4, "version": "GEMM" } # Load modelmodel=AutoAWQForCausalLM.from_pretrained(model_path) tokenizer=AutoTokenizer.from_pretrained(model_path, trust_remote_code=True) # Quantizemodel.quantize(tokenizer, quant_config=quant_config) # Save quantized modelmodel.save_quantized(quant_path) tokenizer.save_pretrained(quant_path) print(f'Model is quantized and saved at "{quant_path}"')InferencefromawqimportAutoAWQForCausalLMfromtransformersimportAutoTokenizer, TextStreamerfromawq.utils.utilsimportget_best_devicedevice=get_best_device() quant_path="TheBloke/zephyr-7B-beta-AWQ"# Load modelmodel=AutoAWQForCausalLM.from_quantized(quant_path, fuse_layers=True) tokenizer=AutoTokenizer.from_pretrained(quant_path, trust_remote_code=True) streamer=TextStreamer(tokenizer, skip_prompt=True, skip_special_tokens=True) # Convert prompt to tokensprompt_template="""\<|system|></s><|user|>{prompt}</s><|assistant|>"""prompt="You're standing on the surface of the Earth. "\ "You walk one mile south, one mile west and one mile north. "\ "You end up exactly where you started. Where are you?"tokens=tokenizer( prompt_template.format(prompt=prompt), return_tensors='pt' ).input_ids.to(device) # Generate outputgeneration_output=model.generate( tokens, streamer=streamer, max_seq_len=512 )Benchmarks
These benchmarks showcase the speed and memory usage of processing context (prefill) and generating tokens (decoding). The results include speed at various batch sizes and different versions of AWQ kernels. We have aimed to test models fairly using the same benchmarking tool that you can use to reproduce the results. Do note that speed may vary not only between GPUs but also between CPUs. What matters most is a GPU with high memory bandwidth and a CPU with high single core clock speed.
Tested with AutoAWQ version 0.1.6
GPU: RTX 4090 (AMD Ryzen 9 7950X)
Command: python examples/benchmark.py --model_path <hf_model> --batch_size 1
🟢 for GEMV, 🔵 for GEMM, 🔴 for avoid using
Model NameSizeVersionBatch SizePrefill LengthDecode LengthPrefill tokens/sDecode tokens/sMemory (VRAM)Vicuna7B🟢GEMV16464639.65198.8484.50 GB (19.05%)Vicuna7B🟢GEMV1204820481123.63133.1916.15 GB (26.02%)...........................Mistral7B🔵GEMM164641093.35156.3174.35 GB (18.41%)Mistral7B🔵GEMM1204820483897.02114.3555.55 GB (23.48%)Mistral7B🔵GEMM864644199.181185.254.35 GB (18.41%)Mistral7B🔵GEMM8204820483661.46829.75416.82 GB (71.12%)...........................Mistral7B🟢GEMV16464531.99188.294.28 GB (18.08%)Mistral7B🟢GEMV120482048903.83130.665.55 GB (23.48%)Mistral7B🔴GEMV86464897.87486.464.33 GB (18.31%)Mistral7B🔴GEMV820482048884.22411.89316.82 GB (71.12%)...........................TinyLlama1B🟢GEMV164641088.63548.9930.86 GB (3.62%)TinyLlama1B🟢GEMV1204820485178.98431.4682.10 GB (8.89%)...........................Llama 213B🔵GEMM16464820.3496.748.47 GB (35.83%)Llama 213B🔵GEMM1204820482279.4173.821310.28 GB (43.46%)Llama 213B🔵GEMM364641593.88286.2498.57 GB (36.24%)Llama 213B🔵GEMM3204820482226.7189.57316.90 GB (71.47%)...........................MPT7B🔵GEMM164641079.06161.3443.67 GB (15.51%)MPT7B🔵GEMM1204820484069.78114.9825.87 GB (24.82%)...........................Falcon7B🔵GEMM164641139.93133.5854.47 GB (18.92%)Falcon7B🔵GEMM1204820482850.97115.736.83 GB (28.88%)...........................CodeLlama34B🔵GEMM16464681.7441.0119.05 GB (80.57%)CodeLlama34B🔵GEMM1204820481072.3635.831620.26 GB (85.68%)...........................DeepSeek33B🔵GEMM164641160.1840.2918.92 GB (80.00%)DeepSeek33B🔵GEMM1204820481012.134.009319.87 GB (84.02%)Multi-GPU
GPU: 2x NVIDIA GeForce RTX 4090
ModelSizeVersionBatch SizePrefill LengthDecode LengthPrefill tokens/sDecode tokens/sMemory (VRAM)Mixtral46.7B🔵GEMM13232149.74293.40625.28 GB (53.44%)Mixtral46.7B🔵GEMM164641489.6493.18425.32 GB (53.53%)Mixtral46.7B🔵GEMM11281282082.9592.944425.33 GB (53.55%)Mixtral46.7B🔵GEMM12562562428.5991.518725.35 GB (53.59%)Mixtral46.7B🔵GEMM15125122633.1189.145725.39 GB (53.67%)Mixtral46.7B🔵GEMM1102410242598.9584.675325.75 GB (54.44%)Mixtral46.7B🔵GEMM1204820482446.1577.051627.98 GB (59.15%)Mixtral46.7B🔵GEMM1409640961985.7877.568934.65 GB (73.26%)CPU
CPU: 48 cores SPR (Intel 4th Gen Xeon CPU)
Command: python examples/benchmark.py --model_path <hf_model> --batch_size 1 --generator hf
ModelVersionBatch SizePrefill LengthDecode LengthPrefill tokens/sDecode tokens/sMemoryTinyLlama 1Bgemm13232817.8670.931.94 GB (0.00%)TinyLlama 1Bgemm1204820485279.1536.832.31 GB (0.00%)Falcon 7Bgemm13232337.5126.419.57 GB (0.01%)Falcon 7Bgemm120482048546.7118.813.46 GB (0.01%)Mistral 7Bgemm13232343.0828.469.74 GB (0.01%)Mistral 7Bgemm1204820481135.2313.2310.35 GB (0.01%)Vicuna 7Bgemm13232340.7328.869.59 GB (0.01%)Vicuna 7Bgemm1204820481143.1911.1410.98 GB (0.01%)Llama 2 13Bgemm13232220.7918.1417.46 GB (0.02%)Llama 2 13Bgemm120482048650.946.5419.84 GB (0.02%)DeepSeek Coder 33Bgemm13232101.618.5840.80 GB (0.04%)DeepSeek Coder 33Bgemm120482048245.023.4841.72 GB (0.04%)Phind CodeLlama 34Bgemm13232102.479.0441.70 GB (0.04%)Phind CodeLlama 34Bgemm120482048237.573.4842.47 GB (0.04%)Reference
If you find AWQ useful or relevant to your research, you can cite their
:
@article{lin2023awq, title={AWQ: Activation-aware Weight Quantization for LLM Compression and Acceleration}, author={Lin, Ji and Tang, Jiaming and Tang, Haotian and Yang, Shang and Dang, Xingyu and Han, Song}, journal={arXiv}, year={2023} }