How to fix "Unknown IValue type for pickling: Device" in PyTorch 1.3?

I got a model trained with PyTorch 1.4. If I script and save this model with PyTorch 1.4, it will save successfully, but I need to script and save this model with PyTorch 1.3. When I save model with 1.3, I got error message:

RuntimeError: Unknown IValue type for pickling: Device (pushIValueImpl at /pytorch/torch/csrc/jit/pickler.cpp:125)

I want to know how to fix this Device issue. Thx.

It implies that somewhere in your model, you’re storing a device type and trying to serialize it (like self.foo = my_device). This is supported in 1.4 but not 1.3; if you want your model to work with 1.3, you’ll have to avoid storing references to devices.

2 Likes

Thx.
In my class, I have a

@property 
def device():...

After I delete this part, I can convert model successfully.