RuntimeError: tensor does not have a device - which tensor?

Getting the following error. How do I find out which tensor autograd is complaining about ?

torch/autograd/", line 251, in backward
Variable._execution_engine.run_backward( # Calls into the C++ engine to run the backward pass
RuntimeError: tensor does not have a device

Please post a minimum executable snippet that reproduces this error.

That is lot of extra work and time. PyTorch autograd should have , and if not need to add additional logging. Is there any debug/trace capability in autograd ? To me, not reporting the tensor looks like a bug in autograd.

Here are few tricks that helped me figure out the issue. It is often not possible to create a small reproducer, hence debugging/tracing logs are invaluable tools.

  3. with autograd.detect_anomaly():