pytorch
device_error
ai_generated
true
RuntimeError: Expected all tensors to be on the same device
ID: pytorch/cuda-device-mismatch
85%Fix Rate
88%Confidence
3Evidence
2023-01-01First Seen
Version Compatibility
| Version | Status | Introduced | Deprecated | Notes |
|---|---|---|---|---|
| 2 | active | — | — | — |
Root Cause
Tensors on different devices (CPU vs GPU).
genericWorkarounds
-
92% success Use .to(device) consistently: tensor.to(model.device)
-
90% success Define device once and use throughout: device=torch.device("cuda:0")
Dead Ends
Common approaches that don't work:
-
Move everything to CPU
68% fail
Loses GPU acceleration
-
Use .cuda() without specifying device
72% fail
Wrong GPU in multi-GPU setup