Solved by ptrblck in post #2 
              
              
                The to() operation is not an inplace operation for tensors, so you would need to reassign the result: 
targets = targets.to(torch.float32)
...