Hi,
What is the content of m_alpha_beta and m_beta_alpha?
One case that could lead to this is if they contain entries that are equal within them
Indeed, the topk and the indices selected can be any of the elements when there is a tie.
Similarly, in your for-loop version, the max will select one element “at random” if there are multiple elements equal to the max.
As you saw, this does not change the output result at all as these values are the same.
But since these values come from different entries, the gradients (that flow back to these selected entries only) can be different!
Hope that helps!