|
13 | 13 | Requirements: |
14 | 14 |
|
15 | 15 | * NVIDIA GPU with FP8 support (Hopper or newer) |
16 | | -* ``nvidia-modelopt>=0.45.0`` that supports the Hugging Face quantization recipes |
| 16 | +* ``nvidia-modelopt`` that supports the Hugging Face quantization recipes |
17 | 17 | * ``transformers`` to load the ViT model |
18 | 18 | * ``torch-tensorrt>=2.13.0`` which converts attention to TRT IAttention Layer |
19 | 19 |
|
@@ -176,21 +176,22 @@ def calibration_loop(model): |
176 | 176 | for batch in calibration_dataloader: |
177 | 177 | model(batch.cuda()) |
178 | 178 |
|
179 | | - recipe = load_recipe("huggingface/vit/ptq/fp8") |
180 | | - quant_cfg = recipe.quantize.model_dump() |
181 | | - # You can also define your own quant_cfg to specify which layers to quantize, like this: |
182 | | - # quant_cfg = { |
183 | | - # "quant_cfg": { |
184 | | - # "*": {"enable": False}, |
185 | | - # "*weight_quantizer": {"num_bits": (4, 3), "axis": None}, |
186 | | - # "*input_quantizer": {"num_bits": (4, 3), "axis": None}, |
187 | | - # "*output_quantizer": {"enable": False}, |
188 | | - # "*[qkv]_bmm_quantizer": {"num_bits": (4, 3), "axis": None}, |
189 | | - # "*softmax_quantizer": {"num_bits": (4, 3), "axis": None}, |
190 | | - # "*bmm2_output_quantizer": {"num_bits": (4, 3), "axis": None}, |
191 | | - # }, |
192 | | - # "algorithm": "max", |
193 | | - # } |
| 179 | + # Define quant_cfg to specify which layers to quantize. |
| 180 | + quant_cfg = { |
| 181 | + "quant_cfg": { |
| 182 | + "*": {"enable": False}, |
| 183 | + "*weight_quantizer": {"num_bits": (4, 3), "axis": None}, |
| 184 | + "*input_quantizer": {"num_bits": (4, 3), "axis": None}, |
| 185 | + "*output_quantizer": {"enable": False}, |
| 186 | + "*[qkv]_bmm_quantizer": {"num_bits": (4, 3), "axis": None}, |
| 187 | + "*softmax_quantizer": {"num_bits": (4, 3), "axis": None}, |
| 188 | + "*bmm2_output_quantizer": {"num_bits": (4, 3), "axis": None}, |
| 189 | + }, |
| 190 | + "algorithm": "max", |
| 191 | + } |
| 192 | + # You can use the following recipe if you have nvidia-modelopt >= 0.46.0 |
| 193 | + # recipe = load_recipe("huggingface/vit/ptq/fp8") |
| 194 | + # quant_cfg = recipe.quantize.model_dump() |
194 | 195 |
|
195 | 196 | mtq.quantize(model, quant_cfg, forward_loop=calibration_loop) |
196 | 197 | return model |
|
0 commit comments