MariosOreo:

ecause tensor doesm’t support the division operation in A / B form, so you can try to use torch.div_ or torch.div


No, PyTorch does use operator overloading and / should work correctly (equivalent) to div. E.g.,:
In [2]: a = torch.tensor([1., 2., 3.])                                          

In [3]: b = torch.tensor([2., 3., 4.])                                          

In [4]: a / b                                                                   
Out[4]: tensor([0.5000, 0.6667, 0.7500])

When I have unexpected zeros, I usually check first to make sure that everything has the correct type to avoid problems like
In [6]: a.long() / b.long()                                                     
Out[6]: tensor([0, 0, 0])

I am not sure if this is happening in the OP’s code though. I wonder what the lines
    result.copy_(result_.data)
    target_.copy_(target.data)

aim to accomplish though.
Maybe try to clean up the following
    if input.is_cuda:
        result = torch.cuda.FloatTensor(result_.size())
        target_ = torch.cuda.FloatTensor(target.size())
    else:
        result = torch.FloatTensor(result_.size())
        target_ = torch.FloatTensor(target.size())
    result.copy_(result_.data)
    target_.copy_(target.data)

by replacing it by a more straightforward implementation:
result = result.float().to(input.device)
target = target.float().to(input.device)