Error in training PyTorch classifier from the 60 minute blitz in GPU
I've started to learn pytorch with their official 60 minute blitz tutorial in a jupyter lab (using their .ipynb file, link to the tutorial), and have completed it successfully until the conversion and training of the classifier using the gpu. I think that I have managed to change the device for the net, inputs and labels according to these results:

net=net.to(device)
net.fc1.weight.type()


With output: 

'torch.cuda.FloatTensor'


And: 

inputs, labels = inputs.to(device), labels.to(device)
inputs.type(),labels.type()


With output:

('torch.cuda.FloatTensor', 'torch.cuda.LongTensor')


After running these cells, I ran the cell for training the model, containing this code:

for epoch in range(2):  # loop over the dataset multiple times

running_loss = 0.0
for i, data in enumerate(trainloader, 0):
    # get the inputs
    inputs, labels = data

    # zero the parameter gradients
    optimizer.zero_grad()

    # forward + backward + optimize
    outputs = net(inputs)
    loss = criterion(outputs, labels)
    loss.backward()
    optimizer.step()

    # print statistics
    running_loss += loss.item()
    if i % 2000 == 1999:    # print every 2000 mini-batches
        print('[%d, %5d] loss: %.3f' %
              (epoch + 1, i + 1, running_loss / 2000))
        running_loss = 0.0

print('Finished Training') 


And received this error:

RuntimeError                              Traceback (most recent call last)
&lt;ipython-input-55-fe85c778b0e6&gt; in &lt;module&gt;()
     10 
     11         # forward + backward + optimize
---&gt; 12         outputs = net(inputs)
     13         loss = criterion(outputs, labels)
     14         loss.backward()

~\Anaconda3\lib\site-packages\torch\nn\modules\module.py in __call__(self, 
*input, **kwargs)
    475             result = self._slow_forward(*input, **kwargs)
    476         else:
--&gt; 477             result = self.forward(*input, **kwargs)
    478         for hook in self._forward_hooks.values():
    479             hook_result = hook(self, input, result)

&lt;ipython-input-52-725d44154459&gt; in forward(self, x)
    14 
    15     def forward(self, x):
---&gt;16         x=self.conv1(x)
    17         x = self.pool(F.relu(x))
    18         x = self.pool(F.relu(self.conv2(x)))

~\Anaconda3\lib\site-packages\torch\nn\modules\module.py in __call__(self, 
*input, **kwargs)
    475             result = self._slow_forward(*input, **kwargs)
    476         else:
--&gt; 477             result = self.forward(*input, **kwargs)
    478         for hook in self._forward_hooks.values():
    479             hook_result = hook(self, input, result)

~\Anaconda3\lib\site-packages\torch\nn\modules\conv.py in forward(self, 
input)
    299     def forward(self, input):
    300         return F.conv2d(input, self.weight, self.bias, self.stride,
--&gt; 301                         self.padding, self.dilation, self.groups)
    302 
    303 

RuntimeError: Expected object of type torch.FloatTensor but found type 
torch.cuda.FloatTensor for argument #2 'weight' 


Why did I receive this error and how can I fix it? 

You also need to move your inputs and labels to GPU inside the training loop.

for i, data in enumerate(trainloader, 0):
    # get the inputs
    inputs, labels = data

    # move to GPU
    inputs = inputs.to(device)
    labels = labels.to(device)

    ...

