This example demonstrates how to optimize Large Language Models (LLMs) in ONNX format using NNCF weight compression API. The example applies 4/8-bit mixed-precision quantization to weights of Linear (Fully-connected) layers of TinyLlama/TinyLlama-1.1B-Chat-v1.0 model. This leads to a significant decrease in model footprint and performance improvement with OpenVINO Runtime.
Before running this example, ensure you have Python 3.10+ installed and set up your environment:
python3 -m venv nncf_env
source nncf_env/bin/activate # On Windows: nncf_env\Scripts\activate.batpython3 -m pip install ../../../../ -r requirements.txtTo run example:
python main.pyThis will automatically:
- Download the TinyLlama model and dataset
- Apply weight compression using NNCF
- Save the optimized model
The exported model uses ONNX opset version 21 by default. You can override this by specifying a different opset version when running the script. For example:
python main.py 14