Pytorch error - RuntimeError: "nll_loss_forward_reduce_cuda_kernel_2d_index" not implemented for 'Float'
I am getting an error very similar to this.
My error as below:
-----------------------------------------------------------------------
RuntimeError                              Traceback (most recent call last)
&lt;ipython-input-85-5a223a19e3f5&gt; in &lt;module&gt;


      8                                   save_run = 'Yes',
      9                                   return_progress_dict = 'Yes',
---&gt; 10                                   hide_text = 'No')

&lt;ipython-input-84-023bc49b2138&gt; in train_CNN(model, optimizer, train_dataloader, epochs, run_number, val_dataloader, save_run, return_progress_dict, hide_text)
     63             print(labels[0].dtype)
     64             print(&quot;------------&quot;)
---&gt; 65             loss = F.cross_entropy(probs, labels)
     66 
     67             total_loss += loss.item()

/usr/local/anaconda/lib/python3.6/site-packages/torch/nn/functional.py in cross_entropy(input, target, weight, size_average, ignore_index, reduce, reduction, label_smoothing)
   2844     if size_average is not None or reduce is not None:
   2845         reduction = _Reduction.legacy_get_string(size_average, reduce)
-&gt; 2846     return torch._C._nn.cross_entropy_loss(input, target, weight, _Reduction.get_enum(reduction), ignore_index, label_smoothing)
   2847 
   2848 

RuntimeError: &quot;nll_loss_forward_reduce_cuda_kernel_2d_index&quot; not implemented for 'Float'

I am making sure that both my labels and probs have same datatype - float
probs[0].dtype:
torch.float32
probs[0]:
tensor([-0.8244, -0.5771], device='cuda:0', grad_fn=&lt;SelectBackward0&gt;)
probs[0].dtype:
torch.float32
------------
labels:
tensor([0., 0., 0., 0., 0., 1., 0., 1., 0., 1., 1., 0., 0., 1., 1., 1., 1., 1.,
        0., 0., 1., 1., 0., 1., 0., 0., 0., 1., 0., 1., 1., 0., 0., 0., 0., 0.,
        0., 0., 1., 0., 0., 1., 1., 0., 1., 1., 1., 1., 1., 1., 0., 1., 0., 1.,
        1., 1., 0., 0., 1., 0., 1., 1., 1., 1., 0., 0., 1., 0., 1., 0., 1., 0.,
        0., 1., 1., 1., 0., 1., 1., 1., 0., 1., 0., 1., 0., 1., 0., 0., 1., 0.,
        1., 1., 1., 0., 0., 1., 1., 0., 0., 0., 0., 0., 1., 0., 1., 1., 1., 0.,
        1., 1., 1., 0., 1., 0., 0., 0., 0., 0., 1., 0., 1., 1., 1., 0., 0., 0.,
        0., 0., 0., 1., 0., 0., 0., 1., 1., 1., 1., 1., 1., 0., 1., 1., 0., 0.,
        1., 0., 0., 0., 1., 1.], device='cuda:0')
labels.dtype:
torch.float32
labels[0].dtype:
torch.float32
------------

My function is as below
def train_CNN(model, optimizer, train_dataloader, epochs, run_number, 
          val_dataloader=None, save_run=None, return_progress_dict = None, hide_text = None):
    
    # Tracking lowest validation loss
    lowest_val_loss = float('inf')
    if return_progress_dict == 'Yes':
        progress_dict = {run_number: {'Epoch':[], 'Avg_Training_Loss':[], 'Validation_Loss':[], 'Validation_Accuracy':[]} }

    # Start training loop
    if hide_text != &quot;Yes&quot;:
        print(&quot;Start training...\n&quot;)
        print(f&quot;{'Epoch':^7} | {'Train Loss':^12} | {'Val Loss':^10} | {'Val Acc':^9} | {'Elapsed':^9}&quot;)
        print(&quot;-&quot;*60)

    for epoch_i in range(epochs):
        # =======================================
        #               Training
        # =======================================

        # Tracking time and loss
        t0_epoch = time.time()
        total_loss = 0

        # Put the model into the training mode
        model.train()

        for step, batch in enumerate(train_dataloader):
            # Load batch to CPU
            data, labels = tuple(t.to(device) for t in batch)
            #labels = labels.type(torch.LongTensor)   #23Feb2022 casting to long as per https://stackoverflow.com/questions/69742930/runtimeerror-nll-loss-forward-reduce-cuda-kernel-2d-index-not-implemented-for
            #labels.to(device)

            # Zero out any previously calculated gradients
            optimizer.zero_grad()

            # Perform a forward pass. This will return logits.
            probs = model(data)

            # Compute loss and accumulate the loss values
            print(&quot;------------&quot;)
            print (&quot;probs[0].dtype:&quot;)
            print(probs[0].dtype)
            print (&quot;probs[0]:&quot;)
            print (probs[0])
            #print (probs)
            probs=probs.type(torch.cuda.FloatTensor)
              
            #probs=probs.type(torch.cuda.LongTensor)
            print (&quot;probs[0].dtype:&quot;)
            print(probs[0].dtype)
            print(&quot;------------&quot;)
            labels = labels.type(torch.cuda.FloatTensor)
            #labels=labels.type(torch.cuda.LongTensor)

            #labels = labels.type(torch.cuda.DoubleTensor)
            #x_cuda = Variable(x, requires_grad=True).cuda()
            
            print(&quot;labels:&quot;)
            print (labels)
            print(&quot;labels.dtype:&quot;)
            print (labels.dtype)
            print(&quot;labels[0].dtype:&quot;)
            print(labels[0].dtype)
            print(&quot;------------&quot;)  
            loss = F.cross_entropy(probs, labels)
            
            total_loss += loss.item()

            # Perform a backward pass to calculate gradients
            loss.backward()

            # Update parameters
            optimizer.step()

                

any suggestions? I will try to give a reproducible example soon
##########################update 1--------------------
I tried labels=labels.type(torch.cuda.LongTensor). Probs are still float32 and still getting the error RuntimeError: &quot;nll_loss_forward_reduce_cuda_kernel_2d_index&quot; not implemented for 'Int' 

labels should be of type torch.long and not torch.float32.
I think you just commented out the line that does this casting in your code.
