I have an old model that I saved (complete model) in a .pth file. When I try to load it now, I get an exception from the unpickler, that the python module in which I defined the model cannot be found.
I was not aware that when saving full .pth models, the pickler only saves references to the documents that contain the definitions of the underlying python objects, and not the objects themselves. I refactored my codebase massively since then and can not reinstate the old version of the code, much less the former file directoy structure. I would have, however, the python object for the exact model.
Is there any way I can salvage my model? In particular I am only interested in the state_dict, i.e. the tensors that should still be in the .pth file. I tried looking at the source-code of torch.serialized, but I did not really grasp what is going on when models are saved/loaded and how I could get hold of the parameters.
As a side note, the whole saving/loading functionality with pytorch is in an unsatisfying situation, especially when working in teams on models and codebase. There are two options. One requires to save the model definitions including all used setting parameters separately from the state dict, the other requires to hold alot of legacy code that cannot be refactored. Is there no way to make it work in a way that pytorch models can be saved as they are and reused as they are?