Hi,
I ran your code above from RuntimeError: tensor does not have a device? and it runs without any issue (two machines with current master).
Could you try upgrading to 1.4 that just came out to see if you still see this happening?
FYI the issue is hard to track from the error message because it happens during the second backward due to a function that run during the first backward (hence the weird stack trace from the anomaly mode).
The error messages means that some cpp code that expects a Tensor containing value was given an undefined Tensor (which represent a Tensor full of 0s for gradients).