-
Notifications
You must be signed in to change notification settings - Fork 25.7k
Description
🐛 Describe the bug
I am testing gradients with torch.autograd.gradcheck.gradcheck. If I am setting the default device to my GPU with torch.set_default_tensor_type("torch.cuda.FloatTensor"), I get a device mismatch. The error only occurs in fast mode, not in slow mode. The problem comes from:
pytorch/torch/autograd/gradcheck.py
Lines 1785 to 1787 in 0f5e24b
| def _make_vectors(inp_tensors, outputs, *, use_forward_ad): | |
| # Use our own generator to avoid messing with the user's RNG state | |
| g_cpu = torch.Generator() |
It seems like the Generator is not given a device and uses the CPU. Similar issues also identified the Generator as the problem and solved it by simply passing "cuda" (e.g. here).
In gradcheck.py, however, one cannot access the generator, and it is also explicitly named "g_cpu". Is gradcheck in fast mode not meant to be run on GPU? Did I miss anything?
Versions
I am running version 1.12.1, but since the offending piece of code is still the same in the current main branch, it should still be an issue.
cc @ezyang @albanD @zou3519 @gqchen @pearu @nikitaved @soulitzer @lezcano @Varal7