Deepcopy TypeError: can't pickle torch._C.Generator objects


I have a Policy class consisting of an lstm network and a cnn. During the training process I need to do a deepcopy. But when doing deepcopy(policy) I get the following error:

TypeError: can’t pickle torch._C.Generator objects

Couldnt find any helpful answer to this problem yet. Can anyone help?

1 Like

Have you solved this problem?
I face with the same problem.

Upstream issue: Make `torch.Generator` picklable · Issue #43672 · pytorch/pytorch · GitHub

If you post the entire definition of the class, maybe we can help out.

My guess is that you might have a self.torch_seed function call. Try to separate that call from the object you are pickling i.e. your Policy class.