- [2024/10/23] Quantized FP8 Llama-3.1 Instruct models available on Hugging Face for download: 8B, 70B, 405B
- [2024/9/10] Post-Training Quantization of LLMs with NVIDIA NeMo and TensorRT Model Optimizer
- [2024/8/28] Boosting Llama 3.1 405B Performance up to 44% with TensorRT Model Optimizer on NVIDIA H200 GPUs
- [2024/8/28] Up to 1.9X Higher Llama 3.1 Performance with Medusa
- [2024/08/15] New features in recent releases: Cache Diffusion, QLoRA workflow with NVIDIA NeMo, and more. Check out our blog for details.
- [2024/06/03] Model Optimizer now has an experimental feature to deploy to vLLM as part of our effort to support popular deployment frameworks. Check out the workflow here
- [2024/05/08] Announcement: Model Optimizer Now Formally Available to Further Accelerate GenAI Inference Performance
- [2024/03/27] Model Optimizer supercharges TensorRT-LLM to set MLPerf LLM inference records
- [2024/03/18] GTC Session: Optimize Generative AI Inference with Quantization in TensorRT-LLM and TensorRT
- [2024/03/07] Model Optimizer's 8-bit Post-Training Quantization enables TensorRT to accelerate Stable Diffusion to nearly 2x faster
- [2024/02/01] Speed up inference with Model Optimizer quantization techniques in TRT-LLM
- Model Optimizer Overview
- Installation
- Techniques
- Examples
- Support Matrix
- Benchmark
- Quantized Checkpoints
- Roadmap
- Release Notes
- Contributing
Minimizing inference costs presents a significant challenge as generative AI models continue to grow in complexity and size. The NVIDIA TensorRT Model Optimizer (referred to as Model Optimizer, or ModelOpt) is a library comprising state-of-the-art model optimization techniques including quantization, distillation, pruning, and sparsity to compress models. It accepts a torch or ONNX model as inputs and provides Python APIs for users to easily stack different model optimization techniques to produce an optimized quantized checkpoint. Seamlessly integrated within the NVIDIA AI software ecosystem, the quantized checkpoint generated from Model Optimizer is ready for deployment in downstream inference frameworks like TensorRT-LLM or TensorRT. ModelOpt is integrated with NVIDIA NeMo and Megatron-LM for training-in-the-loop optimization techniques. For enterprise users, the 8-bit quantization with Stable Diffusion is also available on NVIDIA NIM.
To use Model Optimizer with full dependencies (e.g. TensorRT-LLM deployment), we recommend using the provided docker image.
After installing the NVIDIA Container Toolkit, please run the following commands to build the Model Optimizer docker container which has all the necessary dependencies pre-installed for running the examples.
# Clone the ModelOpt repository
git clone https://github.com/NVIDIA/TensorRT-Model-Optimizer.git
cd TensorRT-Model-Optimizer
# Build the docker (will be tagged `docker.io/library/modelopt_examples:latest`)
# You may customize `docker/Dockerfile` to include or exclude certain dependencies you may or may not need.
./docker/build.sh
# Run the docker image
docker run --gpus all -it --shm-size 20g --rm docker.io/library/modelopt_examples:latest bash
# Check installation (inside the docker container)
python -c "import modelopt; print(modelopt.__version__)"
Alternatively, you can install it from NVIDIA PyPI without TRT-LLM etc.
pip install "nvidia-modelopt[all]" -U --extra-index-url https://pypi.nvidia.com
To install from source for local development, you can install it as follows:
pip install -e ".[all]" --extra-index-url https://pypi.nvidia.com
When installing from source, please make sure to re-run the install command everytime you pull new changes in the repository so dependencies are also updated.
See the installation guide for more details on alternate pre-built docker images or installation in a local environment.
NOTE: Unless specified otherwise, all example READMEs assume they are using the above ModelOpt docker image for running the examples. The example specific dependencies are required to be install separately from their respective requirements.txt
files if not using the ModelOpt's docker image.
Quantization is an effective model optimization technique for large models. Quantization with Model Optimizer can compress model size by 2x-4x, speeding up inference while preserving model quality. Model Optimizer enables highly performant quantization formats including FP8, INT8, INT4, etc and supports advanced algorithms such as SmoothQuant, AWQ, and Double Quantization with easy-to-use Python APIs. Both Post-training quantization (PTQ) and Quantization-aware training (QAT) are supported.
Knowledge Distillation allows for increasing the accuracy and/or convergence speed of a desired model architecture by using a more powerful model's learned features to guide a student model's objective function into imitating it.
Pruning is a technique to reduce the model size and accelerate the inference by removing unnecessary weights. Model Optimizer provides Python APIs to prune Linear and Conv layers, and Transformer attention heads, MLP, embedding hidden size and number of layers (depth).
Sparsity is a technique to further reduce the memory footprint of deep learning models and accelerate the inference. Model Optimizer Python APIs to apply weight sparsity to a given model. It also supports NVIDIA 2:4 sparsity pattern and various sparsification methods, such as NVIDIA ASP and SparseGPT.
Please see examples here.
- For LLM quantization, please refer to this support matrix.
- For VLM quantization, please refer to this support matrix.
- For Diffusion, Model Optimizer supports FLUX, Stable Diffusion 3, Stable Diffusion XL, SDXL-Turbo, and Stable Diffusion 2.1.
- For speculative decoding, please refer to this support matrix.
Please find the benchmarks at here.
Quantized checkpoints in Hugging Face model hub are ready for TensorRT-LLM and vLLM deployments. More models coming soon.
Please see our product roadmap.
Please see Model Optimizer Changelog here.
At the moment, we are not accepting external contributions. However, this will soon change with a focus on extensibility. We welcome any feedback and feature requests. Please open an issue if you have any suggestions or questions.