일반적으로 모델을 저장할 때 학습 재개(resuming)를 위해 모델 파라미터 뿐만 아니라 optimizer, loss, epoch, scheduler등 다양한 정보를 함께 저장한다. 그래서 이러한 checkpoint는 모델만 저장할 때에 비해서 용량이 훨씬 커진다. 이럴때는 .tar 확장자를 사용한다. 나는 주로 .pth.tar를 사용한다.
To save multiple components, organize them in a dictionary and use torch.save() to serialize the dictionary. A common PyTorch convention is to save these checkpoints using the .tar file extension.
Serializie는 나중에 재사용을 위해 저장하기위한 포맷으로 바꾸는 것을 의미한다. inference에 사용하기 위해서는 그냥 deserializie한 뒤 쓰면 된다. 보통 빌드과정이 시간을 소요하기 때문에 매번 빌드하는 것을 피하기 위해 이 과정을 한다.
// code for serializing ICudaEngine
IHostMemory *serializedModel = engine->serialize();
// store model to disk
// <…>
serializedModel->destroy();
-
Deserialize code, The final argument is a plugin layer factory for applications using custom layers. For more information, see [Extending TensorRT With Custom Layers] 별거아니고, 마지막에 nullptr는 iplugin for custom layer인데 없다면 그냥 nullptr넣으면 된다.
의미 그대로 cudnn의 benchmark를 통해 최적의 backend 연산을 찾는 flag를 true로 하겠단 의미.
CNN에서 대부분의 연산을 차지하는 convolution의 경우, 아래 사진의(출처의 두번째 링크) 지원하는 연산 중 최적의 알고리즘을 찾아 적용한다.
cf) 확실한 것은 아니지만 아마 이 벤치마크는 모델이 상수처럼 작동할 때 최적의 연산을 찾을 수 있을 것이다. 예를 들어서 입력크기가 고정되어 모델이 static하게 작동한다면 이 flag가 유효하겠지만, 입력크기가 다양하거나 또는 dynamic한 연산이 모델의 fowarding에 포함된 경우는 큰 효과를 보지 못할 수도 있을 것같다.