Parth_Dethaliya:

There is requirement to threshold a tensor and it is necessary for the gradients to flow while .backward() pass with autograd.


So thresholding (setting small values to 0) is different to counting the number of exceeding values. Which do you need?
Also, counting values has a discrete result (1, 2, 3). An infinitesimal change to a value (usually) doesn’t change how many are above this threshold, so the function isn’t differentiable…
Best regards
Thomas