If you are following the recommended way of storing the state_dicts only, you would have to store the model definition separately. I don’t think there is a clean way to store source code in Python without the danger of breaking it in several ways (but maybe you’ve seen something useful).