Sorry that I am asking this again but I would need a confirmation before I try to switch to the nightly builds for the issue since they seem to be a bit unstable.
This is the code:-
@staticmethod
    def backward(ctx, grad_output):
         grad_label = grad_output.clone()
        num_ft = grad_output.shape[0]
        # grad_label.data.resize_(num_ft, 32, 41)
        lin_indices_3d, lin_indices_2d = ctx.saved_variables
        num_ind = lin_indices_3d.data[0]
        grad_label.data.view(num_ft, -1).index_copy_(1, lin_indices_2d.data[1:1 + num_ind],
                                                     torch.index_select(grad_output.data.contiguous().view(num_ft, -1),
                                                                        1, lin_indices_3d.data[1:1 + num_ind]))
        # raw_input('sdflkj')
        return grad_label, None, None, None


The error I get is:-
image1035×240 58.3 KB
The reference issue is:-

  
    
    
    CUDA Illegal Memory Access autograd
  
  
    While trying to implement a backward pass, I keep getting the error of CUDA Illegal Memory Access. 
@staticmethod
    def backward(ctx, grad_output):
         grad_label = grad_output.clone()
        num_ft = grad_output.shape[0]
        # grad_label.data.resize_(num_ft, 32, 41)
        lin_indices_3d, lin_indices_2d = ctx.saved_variables
        num_ind = lin_indices_3d.data[0]
        grad_label.data.view(num_ft, -1).index_copy_(1, lin_indices_2d.data[1:1 + num_ind],
                          …
  


One of the solutions I saw was:-

  
    
    
    Autograd failed after add max_pool1d layer autograd
  
  
    Thanks for the code snippet. 
Since it’s not reproducible with the last code, could you try to use: 
x= F.max_pool1d(x.transpose(1,2).contiguous(), kernel_size=x.size()[1])

and rerun the script, please? 
Also, which PyTorch version are you using? 
Make sure to update to the latest stable release, as Variables are deprecated since 0.4.
  


However, even after ensuring the input is contiguous I got the same error. I am still not sure about the actual reason for the error though