Hi,
I would like to keep the maximum value to be 1 and others to be 0 in a tensor. But the backward function does not produce gradient for the tensor.
I attached the example. Thanks!
import torch
x = torch.Tensor([[0, 1, 2, 3]]).requires_grad_()
b = (x==x.max(dim=1,keepdim=True)[0]).type(torch.FloatTensor).requires_grad_()
out = b.sum()
out.backward()
x.grad #why is there no grad for x?
b.grad