Skip to content

quantize onnx model with fp8, convert tensorrt engine failed #439

Closed

Description

@wanghuihhh

hi:
I quantize an onnx model with fp8 with TensorRT model optimizer, the quantized model is generated successfully.
But when I build trt engine with command:
trtexec --onnx=calib.onnx --saveEngine=model_fp8.eng --fp16 --fp8
I meet:

Image

and then I try to build engine according to #118 with command:
trtexec --onnx=calib.onnx --saveEngine=model_fp8.eng --stronglyTyped
I meet:

Image

And at the same time the performance is slower than model with fp16 version.

how to solve this problem.

Activity

  1. added
    bug
    on Oct 15, 2025
  2. wanghuihhh commented on Oct 15, 2025

    @wanghuihhh
    Author
    Image Why are the weights of conv converted to fp32?
  3. AnnaTrainingG commented on Oct 16, 2025

    @AnnaTrainingG

    tensorrt好像不支持直接量化fp8? 可以先用modelopt的autocast转成fp8 onnx,然后再用trtexec进行--stronglyTyped进行转换

  4. wanghuihhh commented on Oct 16, 2025

    @wanghuihhh
    Author

    tensorrt好像不支持直接量化fp8? 可以先用modelopt的autocast转成fp8 onnx,然后再用trtexec进行--stronglyTyped进行转换

    已经是用modelopt转换出fp8的onnx了

  5. cjluo-nv commented on Oct 30, 2025

    @cjluo-nv
    Collaborator

    Thanks @AnnaTrainingG . @wanghuihhh has your issue been resolved?

  6. ajrasane commented on Nov 6, 2025

    @ajrasane
    Contributor

    @wanghuihhh, @AnnaTrainingG could you please share the models and commands to reproduce this issue?

  7. wanghuihhh commented on Nov 7, 2025

    @wanghuihhh
    Author

    Thanks @AnnaTrainingG . @wanghuihhh has your issue been resolved?

    No, I still have this issue

  8. wanghuihhh commented on Nov 11, 2025

    @wanghuihhh
    Author

    @wanghuihhh, @AnnaTrainingG could you please share the models and commands to reproduce this issue?
    this is the url of origin model: https://autoai-oss-daily.oss-cn-hangzhou.aliyuncs.com/wanghui/openfile/model.onnx
    this is the url of model after calibrate: https://autoai-oss-daily.oss-cn-hangzhou.aliyuncs.com/wanghui/openfile/calib.onnx

    convert model to fp8 with command:
    python -m modelopt.onnx.quantization
    --onnx_path=model.onnx
    --quantize_mode=fp8
    --calibration_method=max
    --output_path=calib.onnx

    build trt engine with command:
    trtexec --onnx=calib.onnx --saveEngine=model_fp8.eng --stronglyTyped

  9. wanghuihhh commented on Nov 11, 2025

    @wanghuihhh
    Author

    @wanghuihhh, @AnnaTrainingG could you please share the models and commands to reproduce this issue?

    We discovered that the build error was caused by the model's output cast. Manually changing the cast output to float32 resolved the error, but the performance issue persisted compared to fp16 precision. After using Nsight System Profiler, we found that additional kernels appeared before and after the kernels calculated using fp8, causing the overall performance slowdown.

    Image Image fp8 Image fp16
  10. ajrasane commented on Jan 9, 2026

    @ajrasane
    Contributor

    Hello @wanghuihhh,
    Thanks for sharing the link for the model: https://autoai-oss-daily.oss-cn-hangzhou.aliyuncs.com/wanghui/openfile/model.onnx
    However I do not have access to this link. Could you please provide me with the access?
    In the mean time, could you also try setting the high_precision_dtype for FP32 and see if it works for your usecase?
    Another approach could be converting the model to fp16 with modelopt autocast and then quantizing the model with ONNX PTQ by setting the high precision dtype as FP32.
    If you have access to the original torch model, then you can also try out this example

  11. ajrasane commented on Mar 21, 2026

    @ajrasane
    Contributor

    Closing this as it seems to be resolved.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions