Issue loading .pt ScriptModule in older torch

Hello. I have created a PyTorch Model to perform pupil segmentation, and I managed to saved it as a ScriptModule under torch 2.0.0 (current version). But I would like to use it in a bigger project, where we are developping under torch 1.10.0. And it appeared that my .pt file cannot be loaded using torch::jit::load() (in C++) or torch.jit.load() (in python) with torch 1.10.0.
Does someone know what could be the difference in ScriptModule between these two versions that could explain this loading problem ?
Thanks !

This is expected since PyTorch is not forward compatible.
Saving a model in a new version and trying to load it in an older one could break as it’s not a supported use case.
PyTorch is backwards comaptible, i.e. saving a model in an older PyTorch release should allow you to load it in a new release.

1 Like

Thanks ! I managed to find a solution for this problem. I’m not sure it is very clean but it provides a great result. I saved my torch 2.0.0 model to onnx format, and then I downgraded all my python environment to versions compatible with torch 1.10.0. In this environment I managed to convert my onnx model back to a torch model, and saved it as a torch 1.10.0 compatible ScriptModule.