TensorRT icon indicating copy to clipboard operation
TensorRT copied to clipboard

Error when converting the ONNX model to TensorRT

Open HK-little opened this issue 6 years ago • 25 comments

Description

Hi, I am trying to convert a Tensorflow model to TensorRT through onnx. Run command as bellow: trtexec --explicitBatch --workspace=2048 --onnx=trans11_dynamic.onnx --minShapes='input:0':1x1x128x1 --optShapes='input:0':1x16x128x1 --maxShapes='input:0':1x512x128x1 --saveEngine=trans11_dynamic.engine

error fragment: [10/30/2020-10:10:42] [V] [TRT] Tactic: 0 time 0.022096 [10/30/2020-10:10:42] [V] [TRT] Tactic: 1 time 0.027672 [10/30/2020-10:10:42] [V] [TRT] Fastest Tactic: 0 Time: 0.022096 [10/30/2020-10:10:42] [V] [TRT] --------------- Timing Runner: StatefulPartitionedCall/CarrierDetectNet2D/b13_ct/conv2d_transpose (CaskDeconvolution) [10/30/2020-10:10:42] [V] [TRT] CaskDeconvolution has no valid tactics for this config, skipping [10/30/2020-10:10:42] [V] [TRT] --------------- Timing Runner: StatefulPartitionedCall/CarrierDetectNet2D/b13_ct/conv2d_transpose (GemmDeconvolution) [10/30/2020-10:10:42] [F] [TRT] Assertion failed: cublasStatus == CUBLAS_STATUS_SUCCESS C:\source\rtSafe\cublas\cublasLtWrapper.cpp:279 Aborting... [10/30/2020-10:10:43] [V] [TRT] Builder timing cache: created 230 entries, 50 hit(s) [10/30/2020-10:10:43] [E] [TRT] C:\source\rtSafe\cublas\cublasLtWrapper.cpp (279) - Assertion Error in nvinfer1::CublasLtWrapper::getCublasLtHeuristic: 0 (cublasStatus == CUBLAS_STATUS_SUCCESS) [10/30/2020-10:10:43] [E] Engine creation failed [10/30/2020-10:10:43] [E] Engine set up failed &&&& FAILED TensorRT.trtexec # trtexec --explicitBatch --workspace=3072 --onnx=trans11_dynamic.onnx --minShapes='input:0':1x256x128x1 --optShapes='input:0':1x256x128x1 --maxShapes='input:0':1x256x128x1 --saveEngine=trans11_dynamic.engine --verbose

Environment

TensorRT Version: TensorRT-7.2.1.6.Windows10.x86_64.cuda-10.2.cudnn8.0 GPU Type: NVIDIA 2060 Nvidia Driver Version: 441.22 CUDA Version: 10.2 CUDNN Version: 8.0.3 Operating System + Version: window10 Python Version (if applicable): 3.7.6 TensorFlow Version (if applicable): 2.3.0

HK-little avatar Oct 30 '20 02:10 HK-little

Hey, I have similar issue when converting my custom ssd-mobilenet-v2-fn model to tensorrt engine. Successfully generated onnx file, but failed to convert onnx to tensorrt engine.

Beginning ONNX file parsing [TensorRT] ERROR: Parameter check failed at: …/builder/Network.cpp::addInput::671, condition: isValidDims(dims, hasImplicitBatchDimension()) Completed parsing of ONNX file Building an engine from file ssd_mobilenet_v2_coco_2018_03_29/model_edit.onnx; this may take a while… [TensorRT] ERROR: Network must have at least one output Completed creating Engine Traceback (most recent call last): File “onnx_runtime_pretrained.py”, line 87, in engine = get_engine(onnx_file_path, engine_file_path) File “onnx_runtime_pretrained.py”, line 82, in get_engine return build_engine() File “onnx_runtime_pretrained.py”, line 78, in build_engine f.write(engine.serialize()) AttributeError: ‘NoneType’ object has no attribute ‘serialize’

Did you see error like this?

1208overlord avatar Oct 30 '20 18:10 1208overlord

@HK-little I believe this is a known issue with cuBLAS LT 10.2. Could you try either upgrading your CUDA version, or disabling cuBLAS LT with --tacticSources=-cublasLt+cublas?

pranavm-nvidia avatar Oct 30 '20 19:10 pranavm-nvidia

Sorry, but could you please write the whole command to do it? I tried many things really.

def get_engine(onnx_file_path, engine_file_path=""): """Attempts to load a serialized engine if available, otherwise builds a new TensorRT engine and saves it.""" def build_engine(): flag = 1 << int(trt.NetworkDefinitionCreationFlag.EXPLICIT_BATCH) """Takes an ONNX file and creates a TensorRT engine to run inference with""" with trt.Builder(TRT_LOGGER) as builder, builder.create_network(flag) as network, trt.OnnxParser(network, TRT_LOGGER) as parser: builder.max_workspace_size = 1 << 28 # 256MiB builder.max_batch_size = 1 # Parse model file print('Loading ONNX file from path {}...'.format(onnx_file_path)) with open(onnx_file_path, 'rb') as model: print('Beginning ONNX file parsing') parser.parse(model.read()) print('Completed parsing of ONNX file') print('Building an engine from file {}; this may take a while...'.format(onnx_file_path)) engine = builder.build_cuda_engine(network) print("Completed creating Engine") with open(engine_file_path, "wb") as f: f.write(engine.serialize()) return engine()

return build_engine()

I used this script to convert.

1208overlord avatar Oct 30 '20 23:10 1208overlord

Sorry, but could you please write the whole command to do it? I tried many things really.

def get_engine(onnx_file_path, engine_file_path=""): """Attempts to load a serialized engine if available, otherwise builds a new TensorRT engine and saves it.""" def build_engine(): flag = 1 << int(trt.NetworkDefinitionCreationFlag.EXPLICIT_BATCH) """Takes an ONNX file and creates a TensorRT engine to run inference with""" with trt.Builder(TRT_LOGGER) as builder, builder.create_network(flag) as network, trt.OnnxParser(network, TRT_LOGGER) as parser: builder.max_workspace_size = 1 << 28 # 256MiB builder.max_batch_size = 1

Parse model file

print('Loading ONNX file from path {}...'.format(onnx_file_path)) with open(onnx_file_path, 'rb') as model: print('Beginning ONNX file parsing') parser.parse(model.read()) print('Completed parsing of ONNX file') print('Building an engine from file {}; this may take a while...'.format(onnx_file_path)) engine = builder.build_cuda_engine(network) print("Completed creating Engine") with open(engine_file_path, "wb") as f: f.write(engine.serialize()) return engine()

return build_engine()

I used this script to convert.

I just use 'trtexec' tool within tensorrt package. Run command as bellow:(model with dynamic input) trtexec --explicitBatch --workspace=2048 --onnx=trans11_dynamic.onnx --minShapes='input:0':1x1x128x1 --optShapes='input:0':1x16x128x1 --maxShapes='input:0':1x512x128x1 --saveEngine=trans11_dynamic.engine If you encounter conversion errors directly related to the network and you have no idea to solve, it's better to upload your model file。others may reproduce your problem with your model. my experience: a,make sure the deep learning framework generating onnx model install Onnx library consistent with tensorrt. b,use the latest version of tensorrt whenever possible.

HK-little avatar Oct 31 '20 03:10 HK-little

@HK-little I believe this is a known issue with cuBLAS LT 10.2. Could you try either upgrading your CUDA version, or disabling cuBLAS LT with --tacticSources=-cublasLt+cublas?

Thank you for your reply. I will try that.

HK-little avatar Oct 31 '20 03:10 HK-little

Thank you. https://we.tl/t-Co1TpD01yX This is original checkpoint and frozen model, onnx model I generated. Please help with my model.

1208overlord avatar Oct 31 '20 08:10 1208overlord

Hello, can you let me know how it works?

1208overlord avatar Nov 01 '20 09:11 1208overlord

@HK-little I believe this is a known issue with cuBLAS LT 10.2. Could you try either upgrading your CUDA version, or disabling cuBLAS LT with --tacticSources=-cublasLt+cublas?

Works out for me, brilliant

shroudie avatar Nov 02 '20 01:11 shroudie

Did you convert my model via tensorflow-onnx-tensorrt, surely? If then, can you guide how to run?

My questions:

Did you convert from my checkpoint? Did you convert from my onnx model? Did you try to test your final converted model(trt engine)? I would be so appreciate for your time for me.

And my model contains a lot of layers which not supported by tensorrt. How did you replace or fix them?

And can I try via colab on my side, following your guide?

1208overlord avatar Nov 02 '20 02:11 1208overlord

Hello, can you let me know how it works?

Sorry for the late reply due to weekend. online check your model:https://netron.app/ Abnormal output as bellow: name: num_detections:0 type: float32[unk__4100]
the shpae of num_detections:0 should be consistent with the shape of detection_scores:0.

HK-little avatar Nov 02 '20 03:11 HK-little

Sorry for taking your weekend time.. But if you agree, please help me. So, isn't it possible to convert my model for the current moment? Did you run my model or not? Please help me.

1208overlord avatar Nov 02 '20 03:11 1208overlord

Thank you. https://we.tl/t-Co1TpD01yX This is original checkpoint and frozen model, onnx model I generated. Please help with my model.

I'm just a rookie, you can publish new issue.

HK-little avatar Nov 02 '20 03:11 HK-little

It means you have no way to help me?

1208overlord avatar Nov 02 '20 03:11 1208overlord

It means you have no way to help me?

Actually, i know little about deeping learning and how to build a network. Sorry for helpless.

HK-little avatar Nov 02 '20 03:11 HK-little

@HK-little Could you help upgrade your cublas? This is a known issue. You can found "Patch 1" in https://developer.nvidia.com/cuda-10.2-download-archive?target_os=Linux&target_arch=x86_64&target_distro=Ubuntu&target_version=1804&target_type=runfilelocal

zhijial-nvidia avatar Nov 03 '20 03:11 zhijial-nvidia

@zhijial-nvidia can you help with my issue? https://we.tl/t-F6dV0Cuvrz This is my models. Can you try on that and help with my issue? It gives many errors. I want to have trt engine for my model.

1208overlord avatar Nov 03 '20 18:11 1208overlord

I got the exact same issue. I run this to generate the engine, but the inference output MSE is 0.24, which is unacceptable, with onnx output. trtexec --onnx=xxx.onnx --tacticSources=-cublasLt,+cublas --workspace=2048 --fp16 --saveEngine=xxx.engine

col-in-coding avatar Dec 03 '20 08:12 col-in-coding

I got the exact same issue. I run this to generate the engine, but the inference output MSE is 0.24, which is unacceptable, with onnx output. trtexec --onnx=xxx.onnx --tacticSources=-cublasLt,+cublas --workspace=2048 --fp16 --saveEngine=xxx.engine

I finally get the correct output, this solution works

col-in-coding avatar Dec 07 '20 07:12 col-in-coding

I have the same problem on Jetson Nano, --tacticSources=-cublasLt,+cublas doesnt work on Jetson and I can't install cuda 10.2 patch in Jetson.

jasseur2017 avatar Dec 10 '20 22:12 jasseur2017

Hello, can you let me know how it works?

Sorry for that,There are 2 patches available for cuda10.2 in Cuda Official website and the problem is solved after installed them.

HK-little avatar Dec 11 '20 01:12 HK-little