Saving Pytorch Models independent of the source code

I have a question regarding model saving in PyTorch. Let’s say you run a series of experiments and change the code gradually during the project. However, if I save the model state_dict, I would need the exact source code to use the previous pre_trained models. Is there any good way to save a PyTorch model with just enough information to load it even when the source code changes (without the need to go back to the exact git commit that generated the network)? Tensorflow has this option and saves the model and the graph at the same time. I suppose this is possible with TorchScript, but sometimes TorchScript has limited functionality.

Yes, your assumption is correct and saving the scripted model would allow you to reload it afterwards without the need to keep the source code.
However, as you’ve also mentioned you might need to add some changes to make the model “scriptable”. Depending on this effort, storing the source code for each experiment might be easier and would allow you to apply further experiments to this particular model afterwards.