← PyTorch learning path
PyTorch · Module 9 of 10

Saving, exporting and serving

Persist and deploy PyTorch models.

📖 Key ideas

  1. Save weights: torch.save(model.state_dict(), "model.pt").
  2. Load: model.load_state_dict(torch.load("model.pt")).
  3. Export: torch.export / ONNX for other runtimes.
  4. Serve with FastAPI, TorchServe or cloud endpoints.
  5. Mobile/edge: ExecuTorch.
💡 Real-life example: state_dict is the recipe card of learned numbers; the model class is the kitchen that uses it.
state_dictDictionary of model weights
ONNXOpen model exchange format
TorchServePyTorch model server
ExecuTorchOn-device PyTorch runtime