OVH Guides

Exporting a Torch model

Learn how to export a Torch model

Last updated 12th August, 2020.

Objective

Torch is a popular machine learning library supported by OVHcloud ML Serving. This tutorial will cover how to export a Torch trained model.

Requirements

  • A python environment with Torch (pytorch) installed

Save a simple model

Let\'s take a simple example of a Torch model to illustrate:

import torch

# Initialize model
model = torch.nn.Sequential(
    torch.nn.Linear(2, 2),
    torch.nn.Linear(2, 2),
)

# Train model ...

# Save model
with open('my_model.pt', 'wb') as file:
    torch.save(model, file)

Your model is now serialized on your local file system in the my_model.pt file.

Going further


These guides might also interest you...