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('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

Did you find this guide useful?

Please feel free to give any suggestions in order to improve this documentation.

Whether your feedback is about images, content, or structure, please share it, so that we can improve it together.

Your support requests will not be processed via this form. To do this, please use the "Create a ticket" form.

Thank you. Your feedback has been received.

These guides might also interest you...

OVHcloud Community

Access your community space. Ask questions, search for information, post content, and interact with other OVHcloud Community members.

Discuss with the OVHcloud community