-
Notifications
You must be signed in to change notification settings - Fork 365
add aten.topk implementation #2841
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
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good to me! Pending on CI.
get_axes_for_reduce_op(get_positive_dim(dim, len(input.shape))), | ||
) | ||
|
||
# TensorRT ITopKLayer does not have a sorted flag, it is always returning the sorted topk elements | ||
# so here no matter sorted is True or False the returned the topk Tensor object is always sorted |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@narendasan If TRT doesn't have sorted
flag, the outputs of TRT and pytorch might be different. e.g.,
>>> x
tensor([ 1.2096, -0.0950, 0.7965, -0.0960, 0.7188, -1.5562])
>>> torch.ops.aten.topk.default(x, 4, sorted=False)
(tensor([ 0.7188, 1.2096, 0.7965, -0.0950]), tensor([4, 0, 2, 1]))
>>> torch.ops.aten.topk.default(x, 4, sorted=True)
(tensor([ 1.2096, 0.7965, 0.7188, -0.0950]), tensor([0, 2, 4, 1]))
Is the current implementation acceptable?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yeah thats a valid point, and I was also wondering this in the test cases-
In the above you mentioned that topk in TRT returns sorted by default. So was curious if there was a mismatch in the test cases where sorted=False.
Looks like in the test cases, the default flag from torch matches the TRT sorted output.
I missed this point in the next review. @lanluo-nvidia you have more insights?
Description
Add aten.topk implementation
Type of change
Please delete options that are not relevant and/or add your own.
Checklist: