Hi! it’s not that argmax or max do not produce a correct result, but that the result they produce may not necessarily be consistent over different runs and different devices, and is not guaranteed to give you first/last values, even if that is what you want.
The implementation in the link above, though, is guaranteed to give you either the first or last argmax index.