Which format is better for pytorch saved model

(Milton Wong) #1

Hi, all,

I know that .pth and .pkl are both used for the save format for pytorch serializing model. What are the difference for these two formats? Which one is better in terms of efficiency in loading and saving model?



(Pavel Surmenok) #2

Two ways:

  1. Using generic “pickle” serization library allows you to save any Python object into a file. Usually files have “pkl” extension.
  2. Using PyTorch own serialization mechanism you can create a file which typically has “pth” extension.

PyTorch built-in serialization is a recommended approach, according to PyTorch documentation.
I don’t know what is difference in performance between these two. One thing I noticed is that “pth” files are compressed using tar compression algorithm, so they should take less space on disk.

1 Like


Take the smaller one. I tested creating .pth and .pkl files and found out that .pth can grow in size when you save the model more than once. To get the first type you use save() and second you use export() of the learner.