You are right, it’s in C backend. Or you can write your own cross entropy loss. You can use gather to extract the log probability of correct class label.

  
      github.com
  
  
    pytorch/pytorch/blob/master/torch/nn/functional.py#L559 29

                     "but got {}".format(p))


if p == 0 or not training:
    return input


alpha = -1.7580993408473766
keep_prob = 1 - p
# TODO avoid casting to byte after resize
noise = input.data.new().resize_(input.size())
noise.bernoulli_(p)
noise = Variable(noise.byte())


output = input.masked_fill(noise, alpha)


a = (keep_prob + alpha ** 2 * keep_prob * (1 - keep_prob)) ** (-0.5)
b = -a * alpha * (1 - keep_prob)


return output.mul_(a).add_(b)




def dropout2d(input, p=0.5, training=False, inplace=False):