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

26,332

Solution 1

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)

Solution 2

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)

Solution 3

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).

Share:
26,332

Related videos on Youtube

Asil
Author by

Asil

Updated on July 09, 2022

Comments

  • Asil
    Asil almost 2 years

    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?

    • Jimson James
      Jimson James over 2 years
      they are all pkl