Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the difference between .pt, .pth and .pwf extentions in PyTorch?

I have seen in some code examples, that people use .pwf as model file saving format. But in PyTorch documentation .pt and .pth are recommended. I used .pwf and worked fine for small 1->16->16 convolutional network.

My question is what is the difference between these formats? Why is .pwf extension not even recommended in PyTorch documentation and why do people still use it?

like image 369
Asil Avatar asked Nov 28 '19 20:11

Asil


3 Answers

There are no differences between the extensions that were listed: .pt, .pth, .pwf. One can use whatever extension (s)he wants. So, if you're using torch.save() for saving models, then it by default uses python pickle (pickle_module=pickle) to save the objects and some metadata. Thus, you have the liberty to choose the extension you want, as long as it doesn't cause collisions with any other standardized extensions.

Having said that, it is however not recommended to use .pth extension when checkpointing models because it collides with Python path (.pth) configuration files. Because of this, I myself use .pth.tar or .pt but not .pth, or any other extensions.


The standard way of checkpointing models in PyTorch is not finalized yet. Here is an open issue, as of this writing: Recommend a different file extension for models (.PTH is a special extension for Python) - issues/14864

It's been suggested by @soumith to use:

  • .pt for checkpointing models in pickle format
  • .ptc for checkpointing models in pytorch compiled (for JIT)
like image 195
kmario23 Avatar answered Oct 17 '22 21:10

kmario23


The file extension does not change anything in the saved file. The recommended extensions are just used in order to make everyone recognize that it actually is a model saved from pytorch. However, pytorch actually uses python built-in pickle module (https://docs.python.org/2/library/pickle.html)

like image 27
Paul Avatar answered Oct 17 '22 22:10

Paul


Just to extend upon @Paul answer, it is advised to use .pt extension because .pth is used by Python itself for site-packages and module path pointing (see this answer for more info and appropriate Python documentation).

like image 4
Szymon Maszke Avatar answered Oct 17 '22 20:10

Szymon Maszke