As per the docs 19

In order to use CuDNN, the following must be satisfied:  targets  must be in concatenated format

and

the integer arguments must be of dtype  torch.int32

So I modified the sample code on the docs(referenced above) page to satisfy the above mentioned conditions 
ctc_loss = torch.nn.CTCLoss()
log_probs = torch.randn(50, 16, 20).log_softmax(2).detach().requires_grad_().cuda()
target_lengths = torch.randint(10,30,(16,), dtype=torch.int32).cuda()
targets = torch.randint(1, 20, (1, target_lengths.sum()), dtype=torch.int32).view(-1).cuda()
input_lengths = torch.full((16,), 50, dtype=torch.int32).cuda()
loss = ctc_loss(log_probs, targets, input_lengths, target_lengths)
loss.backward()

But this did not went well and the code threw this error.


RuntimeError                              Traceback (most recent call last)
 in 
5 input_lengths = torch.full((16,), 50, dtype=torch.int32).cuda()
6
----> 7 loss = ctc_loss(log_probs, targets, input_lengths, target_lengths)
8 loss.backward()
~/Documents/projects/rosetta/venv/lib/python3.6/site-packages/torch/nn/modules/module.py in call(self, *input, **kwargs)
475             result = self._slow_forward(*input, **kwargs)
476         else:
–> 477             result = self.forward(*input, **kwargs)
478         for hook in self._forward_hooks.values():
479             hook_result = hook(self, input, result)
~/Documents/projects/rosetta/venv/lib/python3.6/site-packages/torch/nn/modules/loss.py in forward(self, log_probs, targets, input_lengths, target_lengths)
1191
1192     def forward(self, log_probs, targets, input_lengths, target_lengths):
-> 1193         return F.ctc_loss(log_probs, targets, input_lengths, target_lengths, self.blank, self.reduction)
1194
1195 # TODO: L1HingeEmbeddingCriterion
~/Documents/projects/rosetta/venv/lib/python3.6/site-packages/torch/nn/functional.py in ctc_loss(log_probs, targets, input_lengths, target_lengths, blank, reduction)
1470         >>> loss.backward()
1471     “”"
-> 1472     return torch.ctc_loss(log_probs, targets, input_lengths, target_lengths, blank, _Reduction.get_enum(reduction))
1473
1474
RuntimeError: Expected tensor to have CPU Backend, but got tensor with CUDA Backend (while checking arguments for cudnn_ctc_loss)

So I modified the datatype to torch.long (which was more of a hunch than an informed decision).
ctc_loss = torch.nn.CTCLoss()
log_probs = torch.randn(50, 16, 20).log_softmax(2).detach().requires_grad_().cuda()
target_lengths = torch.randint(10,30,(16,), dtype=torch.long).cuda()
targets = torch.randint(1, 20, (1, target_lengths.sum()), dtype=torch.long).view(-1).cuda()
input_lengths = torch.full((16,), 50, dtype=torch.long).cuda()
loss = ctc_loss(log_probs, targets, input_lengths, target_lengths)
loss.backward()

And this worked effortlessly with the GPU. So is it that I have misunderstood something from the docs or something is missing in the docs?
@tom