728x90
반응형

Pytorch 및 TensorFlow 등으로 생성된 deploy 모델의 배치 사이즈를 명시적으로 설정하여 TensorRT 모델을 변환 할 때

 

TensorRT 7 버전 부터 도입된 빌드 설정 값들 즉, Optimization Profiles  기능을 이용하여 모델을 변환하면

 

더욱 더 최적화 되어 변환 된다.

 

 

* Optimization Profiles : docs.nvidia.com/deeplearning/tensorrt/developer-guide/index.html#opt_profiles

 

Developer Guide :: NVIDIA Deep Learning TensorRT Documentation

To optimize your model for inference, TensorRT takes your network definition, performs optimizations including platform-specific optimizations, and generates the inference engine. This process is referred to as the build phase. The build phase can take con

docs.nvidia.com

 

* /usr/src/tensorrt/bin/trtexec --help 내용 참고

=== Build Options ===
  --maxBatch                  Set max batch size and build an implicit batch engine (default = 1)
  --explicitBatch             Use explicit batch sizes when building the engine (default = implicit)
  --minShapes=spec            Build with dynamic shapes using a profile with the min shapes provided
  --optShapes=spec            Build with dynamic shapes using a profile with the opt shapes provided
  --maxShapes=spec            Build with dynamic shapes using a profile with the max shapes provided
                              Note: if any of min/max/opt is missing, the profile will be completed using the shapes 
                                    provided and assuming that opt will be equal to max unless they are both specified;
                                    partially specified shapes are applied starting from the batch size;
                                    dynamic shapes imply explicit batch
                                    input names can be wrapped with single quotes (ex: 'Input:0')
                              Input shapes spec ::= Ishp[","spec]
                                           Ishp ::= name":"shape
                                          shape ::= N[["x"N]*"*"]

 

 

하지만 explict model 이 아닌 즉, Implicit model 을  enqueueV2 함수 들을 이용하여 변환 할 경우 아래와 같은 에러가 난다. 

 

Parameter check failed at: engine.cpp::enqueueV2::546, condition: !mEngine.hasImplicitBatchDimension()
Parameter check failed at: engine.cpp::enqueueV2::546, condition: !mEngine.hasImplicitBatchDimension()
Parameter check failed at: engine.cpp::enqueueV2::546, condition: !mEngine.hasImplicitBatchDimension()

 

 

 

 

 

TensorRT 7 버전은 동적 사이즈를 갖는 입력 값에 대해 배치 사이즈를 명시적으로 설정하여 사용하거나, 명시적으로 배치사이즈가 고정된 모델을 사용하여 모델을 변환 또는 추론 할 수 있다. 

(동적 사이즈를 갖는 모델을 허용하기 위해 Optimization Profiles 기능을 도입하였음, 더 유연한 편이라고 생각됨)

 

이전 버전에서는 동적 사이즈를 갖는 입력 값(Implicit model)을 허용하지 않고 Optimization Profiles 기능도 없기 때문에 동적 사이즈를 갖는 값을 사용할 수 없어서 항상 배치 사이즈가 고정된 모델만을 사용할 수 있다.

 

따라서 이전 버전에서는 배치사이즈가 고정된 모델만을 사용할 수 있으므로

모델이 동적 사이즈를 지원할 필요가 없다면 이전 버전에서 제공하는 함수들을 사용하여도 무방하다. 

 

하지만 최신 버전을 사용하는 것이 좋고,

TensorRT 7 버전에서 배치 사이즈 고정된 모델, 배치 사이즈 고정되지 않은 모델 둘 다 사용할 수 있으므로 TensorRT 7 를 권장한다. 단, 배치 사이즈가 고정되지 않은 모델 즉 동적 사이즈의 입력 값을 갖는 모델은 Optimization Profiles  과정이 필요하다. 

 

 

 

 

 

 

 

참고자료 : docs.nvidia.com/deeplearning/tensorrt/developer-guide/index.html#work_dynamic_shapes

 

Developer Guide :: NVIDIA Deep Learning TensorRT Documentation

To optimize your model for inference, TensorRT takes your network definition, performs optimizations including platform-specific optimizations, and generates the inference engine. This process is referred to as the build phase. The build phase can take con

docs.nvidia.com

 

728x90
반응형