Intel® Neural Compressor, formerly known as Intel® Low Precision Optimization Tool, is an open-source Python library that runs on Intel CPUs and GPUs, which delivers unified interfaces across multiple deep-learning frameworks for popular network compression technologies such as quantization, pruning, and knowledge distillation. This tool supports automatic accuracy-driven tuning strategies to help the user quickly find out the best quantized model. It also implements different weight-pruning algorithms to generate a pruned model with predefined sparsity goal. It also supports knowledge distillation to distill the knowledge from the teacher model to the student model. Intel® Neural Compressor is a critical AI software component in the Intel® oneAPI AI Analytics Toolkit.
Note: GPU support is under development.
Visit the Intel® Neural Compressor online document website at: https://intel.github.io/neural-compressor.
Python version: 3.7, 3.8, 3.9, 3.10
- Release binary install
# install stable basic version from pip pip install neural-compressor # Or install stable full version from pip (including GUI) pip install neural-compressor-full
- Nightly binary install
git clone https://github.com/intel/neural-compressor.git cd neural-compressor pip install -r requirements.txt # install nightly basic version from pip pip install -i https://test.pypi.org/simple/ neural-compressor # Or install nightly full version from pip (including GUI) pip install -i https://test.pypi.org/simple/ neural-compressor-full
More installation methods can be found at Installation Guide. Please check out our FAQ for more details.
# A TensorFlow Example
pip install tensorflow
# Prepare fp32 model
wget https://storage.googleapis.com/intel-optimized-tensorflow/models/v1_6/mobilenet_v1_1.0_224_frozen.pb
import tensorflow as tf
from neural_compressor.experimental import Quantization, common
tf.compat.v1.disable_eager_execution()
quantizer = Quantization()
quantizer.model = './mobilenet_v1_1.0_224_frozen.pb'
dataset = quantizer.dataset('dummy', shape=(1, 224, 224, 3))
quantizer.calib_dataloader = common.DataLoader(dataset)
quantizer.fit()
Quantization with GUI
# An ONNX Example
pip install onnx==1.12.0 onnxruntime==1.12.1 onnxruntime-extensions
# Prepare fp32 model
wget https://github.com/onnx/models/raw/main/vision/classification/resnet/model/resnet50-v1-12.onnx
# Start GUI
inc_bench
Quantization with Auto-coding API (Experimental)
from neural_coder import auto_quant
auto_quant(
code="https://github.com/huggingface/transformers/blob/v4.21-release/examples/pytorch/text-classification/run_glue.py",
args="--model_name_or_path albert-base-v2 \
--task_name sst2 \
--do_eval \
--output_dir result \
--overwrite_output_dir",
)
Intel® Neural Compressor supports systems based on Intel 64 architecture or compatible processors that are specifically optimized for the following CPUs:
- Intel Xeon Scalable processor (formerly Skylake, Cascade Lake, Cooper Lake, and Icelake)
- Future Intel Xeon Scalable processor (code name Sapphire Rapids)
- OS version: CentOS 8.4, Ubuntu 20.04
- Python version: 3.7, 3.8, 3.9, 3.10
Framework | TensorFlow | Intel TensorFlow | PyTorch | IPEX | ONNX Runtime | MXNet |
---|---|---|---|---|---|---|
Version | 2.9.1 2.8.2 2.7.3 | 2.9.1 2.8.0 2.7.0 | 1.12.0+cpu 1.11.0+cpu 1.10.0+cpu |
1.12.0 1.11.0 1.10.0 |
1.11.0 1.10.0 1.9.0 |
1.8.0 1.7.0 1.6.0 |
Note: Set the environment variable
TF_ENABLE_ONEDNN_OPTS=1
to enable oneDNN optimizations if you are using TensorFlow v2.6 to v2.8. oneDNN is the default for TensorFlow v2.9.
Intel® Neural Compressor validated 420+ examples for quantization with a performance speedup geomean of 2.2x and up to 4.2x on VNNI while minimizing accuracy loss. Over 30 pruning and knowledge distillation samples are also available. More details for validated models are available here.
- Neural Coder (Intel Neural Compressor Plug-in): One-Click, No-Code Solution (Pat's Keynote IntelON 2022) (Sep 2022)
- Alibaba Cloud and Intel Neural Compressor Deliver Better Productivity for PyTorch Users (Sep 2022)
- Efficient Text Classification with Intel Neural Compressor (Sep 2022)
- Dynamic Neural Architecture Search with Intel Neural Compressor (Sep 2022)
- Easy Quantization in PyTorch Using Fine-Grained FX (Sep 2022)
- One-Click Enabling of Intel Neural Compressor Features in PyTorch Scripts (Aug 2022)
- Deep learning inference optimization for Address Purification (Aug 2022)
View our full publication list.
- Release Information
- Contribution Guidelines
- Legal Information
- Security Policy
- Intel® Neural Compressor Website
We are actively hiring. Send your resume to [email protected] if you are interested in model compression techniques.