Skip to content

sort/argsort/topk: index order among tied values differs from upstream #33

Closed

Description

@b-re-w

Found by #13. sort returns the same values as upstream, but the order of indices among exactly tied values differs. Top-p sampling sorts probabilities, so at the boundary a tie decides whether a token is in the nucleus. This changes which tokens can be sampled, not just display order.

Done when

  • Measure upstream's cpu tie order for sort (stable=False and stable=True, ascending and descending, along every dim, f32/bf16/int), and for topk and argsort.
  • Our cpu kernels reproduce it exactly, as golden cases with tie-heavy inputs (all-equal, two-valued, ±0.0, NaN).
  • Nullified (replace with an unstable sort and see red). Gate green.

Activity

  1. b-re-w commented on Oct 16, 2026

    @b-re-w
    MemberAuthor

    Landed in develop via #82 (libc++ platforms); Linux/Windows order tracked in #81 (#92).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions