Skip to content

add aten.topk implementation#2841

Merged
lanluo-nvidia merged 10 commits intomainfrom
lluo/aten.topk
May 24, 2024
Merged

add aten.topk implementation#2841
lanluo-nvidia merged 10 commits intomainfrom
lluo/aten.topk

Conversation

@lanluo-nvidia
Copy link
Collaborator

Description

Add aten.topk implementation

Type of change

Please delete options that are not relevant and/or add your own.

  • New feature (non-breaking change which adds functionality)

Checklist:

  • My code follows the style guidelines of this project (You can use the linters)
  • I have performed a self-review of my own code
  • I have commented my code, particularly in hard-to-understand areas and hacks
  • I have made corresponding changes to the documentation
  • I have added tests to verify my fix or my feature
  • New and existing unit tests pass locally with my changes
  • I have added the relevant labels to my PR in so that relevant reviewers are notified

@github-actions github-actions bot added component: tests Issues re: Tests component: conversion Issues re: Conversion stage component: converters Issues re: Specific op converters component: api [Python] Issues re: Python API component: dynamo Issues relating to the `torch.compile` or `torch._dynamo.export` paths labels May 16, 2024
@github-actions github-actions bot requested a review from peri044 May 16, 2024 00:15
@narendasan narendasan mentioned this pull request May 16, 2024
7 tasks
Copy link
Collaborator

@apbose apbose left a 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.

@lanluo-nvidia lanluo-nvidia merged commit 92575a0 into main May 24, 2024
)

# 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
Copy link
Collaborator

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?

Copy link
Collaborator

@apbose apbose May 24, 2024

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?

laikhtewari pushed a commit that referenced this pull request May 24, 2024
@lanluo-nvidia lanluo-nvidia deleted the lluo/aten.topk branch January 9, 2026 23:43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

cla signed component: api [Python] Issues re: Python API component: conversion Issues re: Conversion stage component: converters Issues re: Specific op converters component: dynamo Issues relating to the `torch.compile` or `torch._dynamo.export` paths component: tests Issues re: Tests

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants