OpenXLA PR #49368: Why Raw Float Comparisons Corrupted GPU TopK
OpenXLA PR #49368 fixes a specialized GPU TopK kernel whose comparator did not implement the ordering promised by the source operation. The old comparator was: return lhs.key == rhs.key ? lhs.idx < rhs.idx : lhs.key > rhs.key; For ordinary finite values, this usually behaves like a descending stable sort. For NaNs, neither equality nor greater-than establishes an order. For signed zero, equality removes the distinction between +0 and -0 . That was enough to make the bespoke GPU kernel disagree with XLA’s sort-based TopK path. The same HLO operation could therefore produce different values and indices depending on whether its shape crossed the threshold for the optimized kernel. The patch bitcasts float32 and bfloat16 keys to unsigned integers, transforms those bits into a monotonic total-order key, and compares the integer keys instead. One shape boundary changed the meaning of TopK XLA has more than one way to implement TopK. For smaller or unsupported configurations, it can ...