Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Quantization model deploy on GPU #318

Closed
MyraBaba opened this issue Oct 3, 2022 · 16 comments
Closed

Quantization model deploy on GPU #318

MyraBaba opened this issue Oct 3, 2022 · 16 comments
Assignees

Comments

@MyraBaba
Copy link

MyraBaba commented Oct 3, 2022

I have below error. model downloaded from your exported ones:

with cache or without cache enabled same error.

python3 infer.py --model yolov7-w6-end2end-ort-nms.onnx --image /data/Videos/hiv00131/hiv00131/00000480.png --device gpu --use_trt True
[INFO] fastdeploy/backends/tensorrt/trt_backend.cc(540)::CreateTrtEngineFromOnnx Detect serialized TensorRT Engine file in yolotrt.cache, will load it directly.
[INFO] fastdeploy/backends/tensorrt/trt_backend.cc(106)::LoadTrtCache Build TensorRT Engine from cache file: yolotrt.cache with shape range information as below,
[INFO] fastdeploy/backends/tensorrt/trt_backend.cc(109)::LoadTrtCache Input name: images, shape=[1, 3, 640, 640], min=[1, 3, 640, 640], max=[1, 3, 640, 640]

[INFO] fastdeploy/fastdeploy_runtime.cc(270)::Init Runtime initialized with Backend::TRT in device Device::GPU.
[ERROR] fastdeploy/backends/tensorrt/trt_backend.cc(384)::AllocateOutputsBuffer Cannot find output: num_dets of tensorrt network from the original model.
Aborted (core dumped)

@DefTruth
Copy link
Collaborator

DefTruth commented Oct 4, 2022

Please check the docs of YOLOv7End2EndORT:

This class does not support TRT backend. To support TRT::EfficientNMS_TRT op, you should use YOLOv7End2EndTRT, please refer to:

export yolov7 with trt nms (let max-wh be None):

wget https://github.com/WongKinYiu/yolov7/releases/download/v0.1/yolov7.pt

# Export onnx format file with TRT_NMS (Tips: corresponding to YOLOv7 release v0.1 code)
python export.py --weights yolov7.pt --grid --end2end --simplify --topk-all 100 --iou-thres 0.65 --conf-thres 0.35 --img-size 640 640
# The command to export other models is similar Replace yolov7.pt with yolov7x.pt yolov7-d6.pt yolov7-w6.pt ...
# When using YOLOv7End2EndTRT, you only need to provide the onnx file, no need to transfer the trt file, and it will be automatically converted during inference

or download from vision/detection/yolov7end2end_trt .

@DefTruth DefTruth self-assigned this Oct 4, 2022
@MyraBaba
Copy link
Author

MyraBaba commented Oct 4, 2022

@DefTruth Thanks I noticed the problem.

Another interesting thing that I quantize of the exported to onnx (small object detection / visdrone paddle) and its succesfully QUint8 and inferencin.

Problem is qunatized onnx much more slower than the orignal fp32.. 10 times.

Meanwhile I will give a shot to int8 chip (hailo-8)
To export onnx some converter asks for calibration images as in
weights=https://paddledet.bj.bcebos.com/models/ppyoloe_crn_l_80e_sliced_visdrone_640_025.pdparams

How can I quantize with calibration ? weights=https://paddledet.bj.bcebos.com/models/ppyoloe_crn_l_80e_sliced_visdrone_640_025.pdparams

Best

@jiangjiajun
Copy link
Collaborator

@DefTruth Thanks I noticed the problem.

Another interesting thing that I quantize of the exported to onnx (small object detection / visdrone paddle) and its succesfully QUint8 and inferencin.

Problem is qunatized onnx much more slower than the orignal fp32.. 10 times.

Meanwhile I will give a shot to int8 chip (hailo-8) To export onnx some converter asks for calibration images as in weights=https://paddledet.bj.bcebos.com/models/ppyoloe_crn_l_80e_sliced_visdrone_640_025.pdparams

How can I quantize with calibration ? weights=https://paddledet.bj.bcebos.com/models/ppyoloe_crn_l_80e_sliced_visdrone_640_025.pdparams

Best

Inference with CPU or GPU while you use the quantized onnx model?

@MyraBaba
Copy link
Author

@jiangjiajun inferencing with GPU 2080Ti

@jiangjiajun
Copy link
Collaborator

Which tool you are using to quantize your onnx model?

@MyraBaba
Copy link
Author

@jiangjiajun
onnx:


`from onnxruntime.quantization import quantize_dynamic, QuantType

model_fp32 = '/Users/tulpar/Project/devPaddleDetection/sliced_visdrone.onnx'
model_quant = '/Users/tulpar/Project/devPaddleDetection/88quant_sliced_visdrone.onnx'
# quantized_model = quantize_dynamic(model_fp32, model_quant)
_quantized_model = quantize_dynamic(model_fp32 , model_quant , weight_type=QuantType.QUInt8)
`

@jiangjiajun
Copy link
Collaborator

This quant tool is not supported by TensorRT now, Refer this doc https://onnxruntime.ai/docs/performance/quantization.html#quantization-on-gpu

@jiangjiajun jiangjiajun changed the title Cannot find output: num_dets of tensorrt network from the original model. Quantization model deploy on GPU Oct 10, 2022
@yunyaoXYY
Copy link
Collaborator

@jiangjiajun onnx:


`from onnxruntime.quantization import quantize_dynamic, QuantType

model_fp32 = '/Users/tulpar/Project/devPaddleDetection/sliced_visdrone.onnx'
model_quant = '/Users/tulpar/Project/devPaddleDetection/88quant_sliced_visdrone.onnx'
# quantized_model = quantize_dynamic(model_fp32, model_quant)
_quantized_model = quantize_dynamic(model_fp32 , model_quant , weight_type=QuantType.QUInt8)
`

Hi, FastDeploy will provide the tools to quantize model, which could suit deployment on FastDeploy better. See current tutorials as : https://github.com/PaddlePaddle/FastDeploy/tree/develop/tools/quantization. And we will release the examples about how to deploy INT8 models (YOLO series) on FastDeploy in tow days.

What model do you want to quantize and deploy on FastDeploy? We would give you supports.

@MyraBaba
Copy link
Author

@jiangjiajun

The model is : https://paddledet.bj.bcebos.com/models/ppyoloe_crn_l_80e_sliced_visdrone_640_025.pdparams

We have a competition for a huge project for object detection as in above model exactly. But we need to achieve 100fps minimum on the Xavier NX at 640x480 px.

Accuracy is perfect for above model. Neet to speed up and achive the performance.

This is why I tried to quantize int8.

I tried cpp inference 👍
./main --model_dir=/data/dProjects/devPaddleDetection/output_inference/ppyoloe_crn_l_80e_sliced_visdrone_640_025 --video_file=/data/RTSP_oz/20221010_14_30:00_rtsp029.mp4 --device=gpu --run_mode=trt_int8 --batch_size=8 --output_dir=/data/int8.mp4

But not much speedup . Only 40millisec on the 2080 rtx Ti

@yunyaoXYY
Copy link
Collaborator

@jiangjiajun

The model is : https://paddledet.bj.bcebos.com/models/ppyoloe_crn_l_80e_sliced_visdrone_640_025.pdparams

We have a competition for a huge project for object detection as in above model exactly. But we need to achieve 100fps minimum on the Xavier NX at 640x480 px.

Accuracy is perfect for above model. Neet to speed up and achive the performance.

This is why I tried to quantize int8.

I tried cpp inference 👍 ./main --model_dir=/data/dProjects/devPaddleDetection/output_inference/ppyoloe_crn_l_80e_sliced_visdrone_640_025 --video_file=/data/RTSP_oz/20221010_14_30:00_rtsp029.mp4 --device=gpu --run_mode=trt_int8 --batch_size=8 --output_dir=/data/int8.mp4

But not much speedup . Only 40millisec on the 2080 rtx Ti

We have tried to quantize ppyoloe_crn_l_300e_coco, and it works well on FastDeploy.
Maybe we could help you, how about join our Slack channel for further support? link: https://fastdeployworkspace.slack.com/ssb/redirect

@MyraBaba
Copy link
Author

@yunyaoXYY
I will join.

any speed improvement.

@MyraBaba
Copy link
Author

@yunyaoXYY did you tried ppyoloe_crn_l_80e_sliced_visdrone_640_025 ? any speedup ?

@MyraBaba
Copy link
Author

@yunyaoXYY I need and invitation to join Slack

@yunyaoXYY
Copy link
Collaborator

@yunyaoXYY I need and invitation to join Slack

HI, please try this.

https://join.slack.com/t/fastdeployworkspace/shared_invite/zt-1hm4rrdqs-RZEm6_EAanuwEVZ8EJsG~g

@MyraBaba
Copy link
Author

MyraBaba commented Oct 11, 2022 via email

@jiangjiajun
Copy link
Collaborator

此ISSUE由于一年未更新,将会关闭处理,如有需要,可再次更新打开。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants