« Back to Glossary Index

A .pt file is a file extension commonly used in PyTorch to save models, tensors, or other data. In PyTorch, .pt and .pth are interchangeable extensions used to denote saved models or tensors.

Applications/Use Cases:

  • Saving Models: After training a model, you can save its state_dict (the model’s parameters) to a .pt file for later use.
  • Saving Tensors: Individual tensors can be saved to .pt files for later processing or analysis.
  • Saving Checkpoints: During training, you can save checkpoints to .pt files to resume training from a specific point.

Saving A Model:

import torch

# Assuming 'geek' is your PyTorch model
torch.save(model.state_dict(), 'geek.pt')

Loading A Model:

import torch

# Assuming 'geek' is your PyTorch model
model.load_state_dict(torch.load('geek.pt'))
model.eval()  # Set the model to evaluation mode
« Back to Glossary Index