On what I could understand from your question, you want to apply softmax to non zero values in a tensor.
Assuming the name of the tensor to be a,  you can use,
a = a - torch.where(a > 0, torch.zeros_like(a), torch.ones_like(a) * float('inf'))
This will make every zero value -inf, applying softmax over which will give zero.