Skip to content

Fix reference implementation for TopK #6593

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 9 commits into from
Dec 31, 2024
Merged

Conversation

neNasko1
Copy link
Contributor

@neNasko1 neNasko1 commented Dec 20, 2024

Description

This PR fixes problems in the reference implementation of TopK in the following cases by rewriting the tiebreaker mechanism and unifying logic for all cases.

Motivation and Context

The ONNX documentation states:

Given two equivalent values, this operator uses the indices along the axis as a tiebreaker. That is, the element with the lower index will appear first.

This was not the case currently as the flip after the argsort changes the order of the same-valued elements.
Additionally the logic around 2d shaped inputs introduces a bug for unsigned inputs as the negation overflowed.

This mismatch between the reference implementation and onnxruntime was found by running the array-api test suite through ndonnx on both.

@neNasko1 neNasko1 requested review from a team as code owners December 20, 2024 19:07
Signed-off-by: neNasko1 <nasko119@gmail.com>
Signed-off-by: neNasko1 <nasko119@gmail.com>
Signed-off-by: neNasko1 <nasko119@gmail.com>
Signed-off-by: neNasko1 <nasko119@gmail.com>
@neNasko1 neNasko1 force-pushed the fix-topk branch 2 times, most recently from a27d2eb to 09e6c3c Compare December 20, 2024 19:16
Copy link

codecov bot commented Dec 26, 2024

Codecov Report

Attention: Patch coverage is 10.20408% with 44 lines in your changes missing coverage. Please review.

Project coverage is 57.35%. Comparing base (331233b) to head (47282b5).
Report is 1 commits behind head on main.

Files with missing lines Patch % Lines
onnx/backend/test/case/node/topk.py 0.00% 44 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #6593      +/-   ##
==========================================
- Coverage   57.40%   57.35%   -0.06%     
==========================================
  Files         507      507              
  Lines       31574    31609      +35     
  Branches     3062     3062              
==========================================
+ Hits        18126    18128       +2     
- Misses      12599    12633      +34     
+ Partials      849      848       -1     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@justinchuby justinchuby added the topic: operator Issues related to ONNX operators label Dec 30, 2024
@justinchuby justinchuby added this to the 1.18 milestone Dec 30, 2024
@justinchuby
Copy link
Member

Thanks! cc @xadupre

@justinchuby justinchuby added this pull request to the merge queue Dec 31, 2024
Merged via the queue into onnx:main with commit f6e51a9 Dec 31, 2024
34 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
topic: operator Issues related to ONNX operators
Projects
Status: Done
Development

Successfully merging this pull request may close these issues.

3 participants