Thank you. I will definitely look into torchscript eventually. For now, I just save the code of my model building function as a string (obtains with the inspect module). When loading, I use exec. This is probably not a really clean way to serialize a function but it works for my needs. The dill package might be a better way. I also realized my question is really specific to the way I work, where each revision only defines one version of the model.