Tensor for argument #2 ‘mat1’ is on CPU, but expected it to be on GPU (while checking arguments for addmm)
Both the model and the input data need to be moved to the device
model=NonLinearRegression().to(device)#Moudle
for batch_idx,(data,target) in enumerate(train_loader):
data,target=data.to(device),target.to(device)
...
for data,target in val_loader:
data,target=data.to(device),target.to(device)
...
Read More:
- How to Solve RuntimeError: Expected all tensors to be on the same device, but found at least two devices, cpu
- Pytorch directly creates a tensor on the GPU error [How to Solve]
- [Solved] ValueError: Error when checking input: expected conv2d_input to have 4 dimensions
- [Solved] Pytorch Error: RuntimeError: expected scalar type Double but found Float
- RuntimeError: stack expects each tensor to be equal size, but got [x] at entry 0 and [x] at entry 1
- [Solved] RuntimeError: mat1 and mat2 shapes cannot be multiplied
- Normalize error: TypeError: Input tensor should be a float tensor…
- RuntimeError: stack expects each tensor to be equal size [How to Solve]
- [Solved] Error: [email protected]: wrong number of arguments (given 1, expected 0)
- [Solved] Pytorch Tensor to numpy error: RuntimeError: Can‘t call numpy() on Tensor that requires grad.报错
- [Solved] Runtime error: expected scalar type Float but found Double
- [Solved] TypeError: xx takes 1 positional argument but 4 were given
- [Solved] RuntimeError: The size of tensor a (4) must match the size of tensor b (3) at non-singleton dim
- [Solved] RuntimeError: expected scalar type Long but found Float
- Pytorch Error: runtimeerror: expected scalar type double but found float
- [Solved] Vite build & Flask Error: Failed to load module script. Strict MIME type checking is enforced
- [Solved] RuntimeError: gather(): Expected dtype int64 for index
- [Solved] main.py: error: the following arguments are required:
- [Solved] Python Error: positional argument follows keyword argument