Skip to content

Commit fcbba50

Browse files
zewenli98lanluo-nvidia
authored andcommitted
fix modelopt version issue
1 parent afd540e commit fcbba50

1 file changed

Lines changed: 17 additions & 16 deletions

File tree

examples/dynamo/quantize_vit_fp8.py

Lines changed: 17 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
Requirements:
1414
1515
* 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
1717
* ``transformers`` to load the ViT model
1818
* ``torch-tensorrt>=2.13.0`` which converts attention to TRT IAttention Layer
1919
@@ -176,21 +176,22 @@ def calibration_loop(model):
176176
for batch in calibration_dataloader:
177177
model(batch.cuda())
178178

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()
194195

195196
mtq.quantize(model, quant_cfg, forward_loop=calibration_loop)
196197
return model

0 commit comments

Comments
 (0)