You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
[OMNIML-2244] enable fp8 and int8 ONNX export (#594)
## What does this PR do?
**Type of change:**
Example update
**Overview:**
- Support ONNX export for fp8 and int8 precisions
- Added utility functions to check for fp8 and int8 quantization (will
be used in ONNXExporter)
- Fixed a bug in evaluation API for high batch sizes
- Added function to replace zeros from scales to smallest positive value
in fp16
## Usage
<!-- You can potentially add a usage example below. -->
```python
python torch_quant_to_onnx.py \
--quantize_mode fp8/int8 \
--onnx_save_path <onnx_path>
```
## Testing
Validated the accuracy and latency of int8 and fp8 models:
| Metric | INT8 | FP8 |
|--------|------|-----|
| Top1 Accuracy | 84.584% | 85.062% |
| Top5 Accuracy | 97.3% | 97.534% |
| Inference Latency | 8.4825 ms | 8.15096 ms |
## Before your PR is "*Ready for review*"
<!-- If you haven't finished some of the above items you can still open
`Draft` PR. -->
- **Make sure you read and follow [Contributor
guidelines](https://github.com/NVIDIA/TensorRT-Model-Optimizer/blob/main/CONTRIBUTING.md)**
and your commits are signed.
- **Is this change backward compatible?**: Yes
- **Did you write any new necessary tests?**: No
- **Did you add or update any necessary documentation?**: Yes
- **Did you update
[Changelog](https://github.com/NVIDIA/TensorRT-Model-Optimizer/blob/main/CHANGELOG.rst)?**:
No
---------
Signed-off-by: ajrasane <131806219+ajrasane@users.noreply.github.com>
Copy file name to clipboardExpand all lines: examples/onnx_ptq/README.md
+5-5Lines changed: 5 additions & 5 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -13,7 +13,7 @@ Model Optimizer enables highly performant quantization formats including NVFP4,
13
13
| Pre-Requisites | Required & optional packages to use this technique |[Link](#pre-requisites)||
14
14
| Getting Started | Learn how to optimize your models using PTQ to reduce precision and improve inference efficiency |[Link](#getting-started)|[docs](https://nvidia.github.io/TensorRT-Model-Optimizer/guides/_onnx_quantization.html)|
15
15
| Support Matrix | View the ONNX export supported LLM models |[Link](#onnx-export-supported-llm-models)||
16
-
| PyTorch to ONNX | Example scripts demonstrating how to quantize with PyTorch and then convert to ONNX |[Link](#torch-quantization-to-onnx-example-for-mxfp8-int4-or-nvfp4-precision)||
16
+
| PyTorch to ONNX | Example scripts demonstrating how to quantize with PyTorch and then convert to ONNX |[Link](#torch-quantization-to-onnx-export-example)||
17
17
| Advanced Features | Examples demonstrating use advanced ONNX quantization features |[Link](#advanced-features)||
18
18
| Pre-Quantized Checkpoints | Ready to deploy Hugging Face pre-quantized checkpoints |[Link](#pre-quantized-checkpoints)||
19
19
| Resources | Extra links to relevant resources |[Link](#resources)||
@@ -80,7 +80,7 @@ python image_prep.py \
80
80
81
81
The model can be quantized as an FP8, INT8 or INT4 model using either the CLI or Python API. For FP8 and INT8 quantization, you have a choice between `max` and `entropy` calibration algorithms. For INT4 quantization, [awq_clip](https://arxiv.org/abs/2306.00978) or [rtn_dq](https://ar5iv.labs.arxiv.org/html/2301.12017) algorithms can be chosen.
82
82
83
-
> *For NVFP4 and MXFP8 ONNX, see the [PyTorch to ONNX section](#torch-quantization-to-onnx-example-for-mxfp8-int4-or-nvfp4-precision).*
83
+
> *For NVFP4 and MXFP8 ONNX, see the [PyTorch to ONNX section](#torch-quantization-to-onnx-export-example).*
84
84
85
85
> *Minimum opset requirements: int8 (13+), fp8 (21+), int4 (21+). ModelOpt will automatically upgrade lower opset versions to meet these requirements.*
86
86
@@ -129,9 +129,9 @@ The top5 accuracy of the model is <accuracy score between 0-100%>
129
129
Inference latency of the model is <X> ms
130
130
```
131
131
132
-
## Torch quantization to ONNX example for MXFP8, INT4 or NVFP4 precision
132
+
## Torch quantization to ONNX export example
133
133
134
-
This example demonstrates how to quantize a [timm](https://github.com/huggingface/pytorch-image-models) vision model using MXFP8, INT4 or NVFP4 precision formats, and then export it to ONNX. The script leverages the ModelOpt toolkit for both quantization and ONNX export.
134
+
This example demonstrates how to quantize a [timm](https://github.com/huggingface/pytorch-image-models) vision model for various precision formats followed by export to ONNX. The script leverages the ModelOpt toolkit for both quantization and ONNX export.
135
135
136
136
> *Opset 20 is used to export the torch models to ONNX.*
137
137
@@ -148,7 +148,7 @@ This example demonstrates how to quantize a [timm](https://github.com/huggingfac
148
148
```bash
149
149
python torch_quant_to_onnx.py \
150
150
--timm_model_name=vit_base_patch16_224 \
151
-
--quantize_mode=<mxfp8|nvfp4|int4_awq> \
151
+
--quantize_mode=<fp8|mxfp8|int8|nvfp4|int4_awq> \
152
152
--onnx_save_path=<path to save the exported ONNX model>
0 commit comments