-
Notifications
You must be signed in to change notification settings - Fork 364
Adding support for aten::topk #302
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
auto k = args[1].unwrapToInt(); | ||
auto dim = args[2].unwrapToInt(); | ||
auto largest = args[3].unwrapToBool(); | ||
// auto sorted = args[4].unwrapToBool(); # Currently unused |
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.
@inocsin What is the role of this argument and why don't we use it? I commented it out because it was throwing warnings
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.
torch.topk has an argument sorted = True which returns the top k elements in a sorted order (decreasing). By default it is true. Setting it False will result in random order of output top k elements which we can't support in TensorRT. TensorRT always returns the top "k" max or min elements depending on "largest" argument. Maybe we can add this detail as a comment to explain why we aren't using args[4]
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.
will this cause an issue to users? if they expect random does always giving them ordered matter? At the very least yeah there should be a comment/
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.
This won't cause an issue to users in my opinion. So far all usecases for this op have been gathering either top k largest elements or top k smallest elements, both of which are supported. We can revisit this if anyone requests such usecase.
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.
Code conforms to Python style guidelines
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.
There are some changes that do not conform to C++ style guidelines:
diff --git a/workspace/core/conversion/converters/impl/topk.cpp b/tmp/changes.txt
index 2addbdc..d052dd9 100644
--- a/workspace/core/conversion/converters/impl/topk.cpp
+++ b/tmp/changes.txt
@@ -25,11 +25,12 @@ auto topk_registrations TRTORCH_UNUSED = RegisterNodeConversionPatterns().patter
auto selfDim = util::toVec(self->getDimensions());
- //reduceAxes The reduction dimensions. The bit in position i of bitmask reduceAxes corresponds to explicit dimension i of the result.
- //E.g., the least significant bit corresponds to the first explicit dimension and the next to least significant bit corresponds to the second explicit dimension.
+ // reduceAxes The reduction dimensions. The bit in position i of bitmask reduceAxes corresponds to explicit
+ // dimension i of the result. E.g., the least significant bit corresponds to the first explicit dimension and the
+ // next to least significant bit corresponds to the second explicit dimension.
if (dim < 0) {
- dim = selfDim.size() + dim;
+ dim = selfDim.size() + dim;
}
uint32_t shiftDim = 1 << dim;
ERROR: Some files do not conform to style guidelines
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.
There are some changes that do not conform to C++ style guidelines:
diff --git a/workspace/core/conversion/converters/impl/topk.cpp b/tmp/changes.txt
index 2addbdc..d052dd9 100644
--- a/workspace/core/conversion/converters/impl/topk.cpp
+++ b/tmp/changes.txt
@@ -25,11 +25,12 @@ auto topk_registrations TRTORCH_UNUSED = RegisterNodeConversionPatterns().patter
auto selfDim = util::toVec(self->getDimensions());
- //reduceAxes The reduction dimensions. The bit in position i of bitmask reduceAxes corresponds to explicit dimension i of the result.
- //E.g., the least significant bit corresponds to the first explicit dimension and the next to least significant bit corresponds to the second explicit dimension.
+ // reduceAxes The reduction dimensions. The bit in position i of bitmask reduceAxes corresponds to explicit
+ // dimension i of the result. E.g., the least significant bit corresponds to the first explicit dimension and the
+ // next to least significant bit corresponds to the second explicit dimension.
if (dim < 0) {
- dim = selfDim.size() + dim;
+ dim = selfDim.size() + dim;
}
uint32_t shiftDim = 1 << dim;
ERROR: Some files do not conform to style guidelines
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.
Code conforms to Python style guidelines
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.
Code conforms to Python style guidelines
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.
Code conforms to C++ style guidelines
auto k = args[1].unwrapToInt(); | ||
auto dim = args[2].unwrapToInt(); | ||
auto largest = args[3].unwrapToBool(); | ||
// auto sorted = args[4].unwrapToBool(); # Currently unused |
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.
torch.topk has an argument sorted = True which returns the top k elements in a sorted order (decreasing). By default it is true. Setting it False will result in random order of output top k elements which we can't support in TensorRT. TensorRT always returns the top "k" max or min elements depending on "largest" argument. Maybe we can add this detail as a comment to explain why we aren't using args[4]
Signed-off-by: inocsin <[email protected]>
Signed-off-by: Naren Dasan <[email protected]> Signed-off-by: Naren Dasan <[email protected]>
Signed-off-by: Naren Dasan <[email protected]> Signed-off-by: Naren Dasan <[email protected]>
in TensorRT Signed-off-by: Naren Dasan <[email protected]> Signed-off-by: Naren Dasan <[email protected]>
Signed-off-by: Naren Dasan <[email protected]> Signed-off-by: Naren Dasan <[email protected]>
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.
Code conforms to Python style guidelines
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.
There are some changes that do not conform to C++ style guidelines:
diff --git a/workspace/core/conversion/converters/impl/topk.cpp b/tmp/changes.txt
index 9ca91a2..dcc83d2 100644
--- a/workspace/core/conversion/converters/impl/topk.cpp
+++ b/tmp/changes.txt
@@ -21,7 +21,8 @@ auto topk_registrations TRTORCH_UNUSED = RegisterNodeConversionPatterns().patter
auto k = args[1].unwrapToInt();
auto dim = args[2].unwrapToInt();
auto largest = args[3].unwrapToBool();
- LOG_DEBUG("Note: sorted argument is not used in TensorRT for aten::topk, results will depend on the value of largest");
+ LOG_DEBUG(
+ "Note: sorted argument is not used in TensorRT for aten::topk, results will depend on the value of largest");
// auto sorted = args[4].unwrapToBool(); # Currently unused
auto selfDim = util::toVec(self->getDimensions());
ERROR: Some files do not conform to style guidelines
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.
Code conforms to Python style guidelines
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.
Code conforms to C++ style guidelines
Description
Adds support for
aten::topk
Type of change
Please delete options that are not relevant and/or add your own.
Checklist: