Thank you @albanD for your reply. So If i had some learnable weights (W) before the softmax operation as follows:
_, idx = torch.max(softmax(A.W.B))
desired_element = matrix[idx]

Then gradients won’t flow through W?