RuntimeError: Unknown IValue type for pickling: Device (pushIValueImpl at /opt/conda/conda-bld/pytorch_1579022030672/work/torch/csrc/jit/pickler.cpp:132)

i get this error when i use torch.jit.script then torch.jit.save
: frame #0: c10::Error::Error(c10::SourceLocation, std::string const&) + 0x47 (0x7f37df3cb627 in /home/kencorp/miniconda3/lib/python3.7/site-packages/torch/lib/libc10.so)
frame #1: + 0x2f9d95d (0x7f37e258e95d in /home/kencorp/miniconda3/lib/python3.7/site-packages/torch/lib/libtorch.so)
frame #2: + 0x2f9dc3b (0x7f37e258ec3b in /home/kencorp/miniconda3/lib/python3.7/site-packages/torch/lib/libtorch.so)
frame #3: + 0x2f9d1ee (0x7f37e258e1ee in /home/kencorp/miniconda3/lib/python3.7/site-packages/torch/lib/libtorch.so)
frame #4: + 0x2f9dc5b (0x7f37e258ec5b in /home/kencorp/miniconda3/lib/python3.7/site-packages/torch/lib/libtorch.so)
frame #5: + 0x32bcdd9 (0x7f37e28addd9 in /home/kencorp/miniconda3/lib/python3.7/site-packages/torch/lib/libtorch.so)
frame #6: + 0x32c0bdd (0x7f37e28b1bdd in /home/kencorp/miniconda3/lib/python3.7/site-packages/torch/lib/libtorch.so)
frame #7: torch::jit::ExportModule(torch::jit::script::Module const&, std::string const&, std::unordered_map<std::string, std::string, std::hashstd::string, std::equal_tostd::string, std::allocator<std::pair<std::string const, std::string> > > const&, bool) + 0x19b (0x7f37e28aba5b in /home/kencorp/miniconda3/lib/python3.7/site-packages/torch/lib/libtorch.so)
frame #8: + 0x743dd2 (0x7f37e581cdd2 in /home/kencorp/miniconda3/lib/python3.7/site-packages/torch/lib/libtorch_python.so)
frame #9: + 0x26b876 (0x7f37e5344876 in /home/kencorp/miniconda3/lib/python3.7/site-packages/torch/lib/libtorch_python.so)

frame #29: __libc_start_main + 0xf0 (0x7f37f0fb1830 in /lib/x86_64-linux-gnu/libc.so.6)

Support for Device was added somewhat recently, are you on the latest version of PyTorch? If so, can you open an issue on GitHub with a repro?

import torch
torch.version
‘1.4.0’

I found a similar issue in 1.4.0, and upgrading to 1.8.1 fixes it. The release notes for 1.8.0 reference PR #46441 which

adds hashing for many other types including Tuple , bool , device by implementing generic hashing on IValue

I believe this is the improvement that resolved the root issue