intel/neural-compressor
Fork: 257 Star: 2241 (更新于 2024-12-03 18:26:56)
license: Apache-2.0
Language: Python .
SOTA low-bit LLM quantization (INT8/FP8/INT4/FP4/NF4) & sparsity; leading model compression techniques on TensorFlow, PyTorch, and ONNX Runtime
最后发布版本: v2.6 ( 2024-06-14 21:55:11)
Intel® Neural Compressor
An open-source Python library supporting popular model compression techniques on all mainstream deep learning frameworks (TensorFlow, PyTorch, and ONNX Runtime)
Architecture | Workflow | LLMs Recipes | Results | Documentations
Intel® Neural Compressor aims to provide popular model compression techniques such as quantization, pruning (sparsity), distillation, and neural architecture search on mainstream frameworks such as TensorFlow, PyTorch, and ONNX Runtime, as well as Intel extensions such as Intel Extension for TensorFlow and Intel Extension for PyTorch. In particular, the tool provides the key features, typical examples, and open collaborations as below:
-
Support a wide range of Intel hardware such as Intel Gaudi Al Accelerators, Intel Core Ultra Processors, Intel Xeon Scalable Processors, Intel Xeon CPU Max Series, Intel Data Center GPU Flex Series, and Intel Data Center GPU Max Series with extensive testing; support AMD CPU, ARM CPU, and NVidia GPU through ONNX Runtime with limited testing; support NVidia GPU for some WOQ algorithms like AutoRound and HQQ.
-
Validate popular LLMs such as LLama2, Falcon, GPT-J, Bloom, OPT, and more than 10,000 broad models such as Stable Diffusion, BERT-Large, and ResNet50 from popular model hubs such as Hugging Face, Torch Vision, and ONNX Model Zoo, with automatic accuracy-driven quantization strategies
-
Collaborate with cloud marketplaces such as Google Cloud Platform, Amazon Web Services, and Azure, software platforms such as Alibaba Cloud, Tencent TACO and Microsoft Olive, and open AI ecosystem such as Hugging Face, PyTorch, ONNX, ONNX Runtime, and Lightning AI
What's New
- [2024/10] Transformers-like API for INT4 inference on Intel CPU and GPU.
- [2024/07] From 3.0 release, framework extension API is recommended to be used for quantization.
- [2024/07] Performance optimizations and usability improvements on client-side.
Installation
Install Framework
Install torch for CPU
pip install torch --index-url https://download.pytorch.org/whl/cpu
Use Docker Image with torch installed for HPU
Note: There is a version mapping between Intel Neural Compressor and Gaudi Software Stack, please refer to this table and make sure to use a matched combination.
Install torch/intel_extension_for_pytorch for Intel GPU
https://intel.github.io/intel-extension-for-pytorch/index.html#installation
Install torch for other platform
https://pytorch.org/get-started/locally
Install tensorflow
pip install tensorflow
Install from pypi
# Install 2.X API + Framework extension API + PyTorch dependency
pip install neural-compressor[pt]
# Install 2.X API + Framework extension API + TensorFlow dependency
pip install neural-compressor[tf]
Note: Further installation methods can be found under Installation Guide. check out our FAQ for more details.
Getting Started
Setting up the environment:
pip install "neural-compressor>=2.3" "transformers>=4.34.0" torch torchvision
After successfully installing these packages, try your first quantization program.
FP8 Quantization
Following example code demonstrates FP8 Quantization, it is supported by Intel Gaudi2 AI Accelerator.
To try on Intel Gaudi2, docker image with Gaudi Software Stack is recommended, please refer to following script for environment setup. More details can be found in Gaudi Guide.
# Run a container with an interactive shell
docker run -it --runtime=habana -e HABANA_VISIBLE_DEVICES=all -e OMPI_MCA_btl_vader_single_copy_mechanism=none --cap-add=sys_nice --net=host --ipc=host vault.habana.ai/gaudi-docker/1.18.0/ubuntu22.04/habanalabs/pytorch-installer-2.4.0:latest
Run the example:
from neural_compressor.torch.quantization import (
FP8Config,
prepare,
convert,
)
import torch
import torchvision.models as models
model = models.resnet18()
qconfig = FP8Config(fp8_config="E4M3")
model = prepare(model, qconfig)
# Customer defined calibration. Below is a dummy calibration
model(torch.randn(1, 3, 224, 224).to("hpu"))
model = convert(model)
output = model(torch.randn(1, 3, 224, 224).to("hpu")).to("cpu")
print(output.shape)
Weight-Only Large Language Model Loading (LLMs)
Following example code demonstrates weight-only large language model loading on Intel Gaudi2 AI Accelerator.
from neural_compressor.torch.quantization import load
model_name = "TheBloke/Llama-2-7B-GPTQ"
model = load(
model_name_or_path=model_name,
format="huggingface",
device="hpu",
torch_dtype=torch.bfloat16,
)
Note:
Intel Neural Compressor will convert the model format from auto-gptq to hpu format on the first load and save hpu_model.safetensors to the local cache directory for the next load. So it may take a while to load for the first time.
Documentation
Overview | |||||||
---|---|---|---|---|---|---|---|
Architecture | Workflow | APIs | LLMs Recipes | Examples | |||
PyTorch Extension APIs | |||||||
Overview | Dynamic Quantization | Static Quantization | Smooth Quantization | ||||
Weight-Only Quantization | FP8 Quantization | MX Quantization | Mixed Precision | ||||
Tensorflow Extension APIs | |||||||
Overview | Static Quantization | Smooth Quantization | |||||
Transformers-like APIs | |||||||
Overview | |||||||
Other Modules | |||||||
Auto Tune | Benchmark |
Note: From 3.0 release, we recommend to use 3.X API. Compression techniques during training such as QAT, Pruning, Distillation only available in 2.X API currently.
Selected Publications/Events
- EMNLP'2024: Optimize Weight Rounding via Signed Gradient Descent for the Quantization of LLMs (Sep 2024)
- Blog on Medium: Quantization on Intel Gaudi Series AI Accelerators (Aug 2024)
- Blog by Intel: Neural Compressor: Boosting AI Model Efficiency (June 2024)
- Blog by Intel: Optimization of Intel AI Solutions for Alibaba Cloud’s Qwen2 Large Language Models (June 2024)
- Blog by Intel: Accelerate Meta* Llama 3 with Intel AI Solutions (Apr 2024)
- EMNLP'2023 (Under Review): TEQ: Trainable Equivalent Transformation for Quantization of LLMs (Sep 2023)
- arXiv: Efficient Post-training Quantization with FP8 Formats (Sep 2023)
- arXiv: Optimize Weight Rounding via Signed Gradient Descent for the Quantization of LLMs (Sep 2023)
Note: View Full Publication List.
Additional Content
Communication
- GitHub Issues: mainly for bug reports, new feature requests, question asking, etc.
- Email: welcome to raise any interesting research ideas on model compression techniques by email for collaborations.
- Discord Channel: join the discord channel for more flexible technical discussion.
- WeChat group: scan the QA code to join the technical discussion.
最近版本更新:(数据更新于 2024-09-18 21:02:02)
2024-06-14 21:55:11 v2.6
2024-04-03 22:03:34 v2.5.1
2024-03-26 18:21:37 v2.5
2023-12-29 21:12:55 v2.4.1
2023-12-17 11:26:53 v2.4
2023-11-23 23:30:18 v2.3.2
2023-09-28 17:48:35 v2.3.1
2023-09-15 15:56:47 v2.3
2023-06-21 21:30:39 v2.2
2023-05-11 20:21:40 v2.1.1
主题(topics):
auto-tuning, awq, fp4, gptq, int4, int8, knowledge-distillation, large-language-models, low-precision, mxformat, post-training-quantization, pruning, quantization, quantization-aware-training, smoothquant, sparsegpt, sparsity
intel/neural-compressor同语言 Python最近更新仓库
2024-12-22 09:03:32 ultralytics/ultralytics
2024-12-21 13:26:40 notepad-plus-plus/nppPluginList
2024-12-21 11:42:53 XiaoMi/ha_xiaomi_home
2024-12-21 04:33:22 comfyanonymous/ComfyUI
2024-12-20 18:47:56 home-assistant/core
2024-12-20 15:41:40 jxxghp/MoviePilot