TypeError: can't pickle objects

Hello, getting the “TypeError: can’t pickle X objects” error. As has been posted many times before this is in fact because I am running torch.save(net, PATH) and not torch.save(net.state_dict(), PATH). However, my understanding is that state_dict() just to fill in values so you have to initialize a network with the same architecture to load a state_dict() to it. My application incorporates modifying the architecture after initialization so if that is how it works I can not use state_dict for my saving. Everything was working in pytorch 0.2, I have now updated and working with 0.4. I was wondering if there was any advice on how to track down what exactly is the problem with my object that can’t be pickled. or possibly something that changed between versions that might cause this to no longer work.

If it helps my object is class myObject(torch.autograd.Function). It has a forward and backward and also fills in and keeps track of a few values.


I have the same problem, do you have solved the problem? if so, please give me a help! thanks!

I believe I eventually decided pytorch didn’t like the concept of pickling torch.autograd.functions. I ended up making a function that saved the variables from the class, deleted them all then pickled and upon load created new class objects and filled in the values.