Tao Toolkit은 학습한 모델을 onnx format이나 TensorRT로 변환할 수 있는 util을 제공한다.
.trt or .engine (교환 가능), .etltPrecision은 낮지만 Performance를 높여주는 mode다. TensorRT는 INT8 mode로 생성 가능한데, quantization errors를 잡는데 도움을 줄 scale factor들이 포함된 cache file이 필요하다. 이 calibration cache는 export 명령어를 쓸 때 —data_type에 int8을 set해주면 된다. 이 때 생성된 calibration 정보들이 있으면 추후 inference를 할 때 이 작업을 skip할 수 있어 시간을 절약할 수 있다. cache를 만드는 작업은 Tensorfile과 모델의 사이즈에 따라 몇 분이나 소요될 수 있기 때문이다.
그렇다면 이 INT8 calibation cache는 어떻게 만들어야 하나?
먼저, training data의 최소 10-20% 정도를 랜덤으로 sampling 한다. data가 많을수록 int8 inference 결과가 fp32와 비슷해진다.
<aside> 💡 공식 문서에서는 최소 calibration data 개수를 batch_size * batches 로 권장하고 있다. 참고로 batch_size와 batches는 export 시 사용되는 argument명이다.
</aside>
sample notebook을 보면 이 작업에 대한 예제를 python 파일로 제공하고 있다.
[sample notebook 다운로드]
wget --content-disposition <https://api.ngc.nvidia.com/v2/resources/nvidia/tao/cv_samples/versions/v1.4.0/zip> -O cv_samples_v1.4.0.zip
unzip -u cv_samples_v1.4.0.zip -d ./cv_samples_v1.4.0 && rm -rf cv_samples_v1.4.0.zip && cd ./cv_samples_v1.4.0
calibration.bin은 INT8 mode로 inference를 돌릴 때 사용되는 파일이고 PF16/FP32 모드 inference는 훨씬 더 간단하다. train 후 바로 export를 실해하면 바로 encrypted TAO model(.etlt)로 변환된다.

이처럼 INT8 mode로 모델을 Export 하기 위해서는 추가 작업이 필요하기 때문에 export 명령어를 쓸 때도 추가 Argument를 set해주어야 한다.
이 Argument들에 대한 자세한 설명은 공식 Document를 참고한다.