问题描述

在使用导出的TensorRT进行推理时,可能由于环境问题导致模型无法加载成功报错,主要有以下两种报错:

1
Error Code 1: Serialization (Serialization assertion plan->header.magicTag == rt::kPLAN_MAGIC_TAG failed.Trying to load an engine created with incompatible serialization version. Check that the engine was not created using safety runtime, same OS was used and version compatibility parameters were set accordingly.)
1
Myelin (Compiled against cuBLASLt 11.10.1.0 but running against cuBLASLt 11.5.1.0.)

以上两种报错都会导致模型加载失败,报错'NoneType' object has no attribute 'num_bindings'

解决方法

针对报错1,是由于导出环境与推理环境tensorrt的版本不一致导致的,需要在推理环境下重新导出,或者对齐导出时的环境版本。

针对报错2,是由于导出和推理环境加载了不同版本的cublaslt导致的,如果不是同一环境,首先检查tensorrty以及cuda、cudnn的版本是否一致。如果是在同一环境下报错,可能是由于系统中和pytorch安装的是不同版本的库导致的。可以在import torch前先import tensorrt,这样可能会加载到正确的库