OVH Guides

Exporting a Torch model

Learn how to export a Torch model

Last updated 12th August, 2020.


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


  • 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('', 'wb') as file:, file)

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

Going further

These guides might also interest you...