-
Notifications
You must be signed in to change notification settings - Fork 3.5k
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
[TRT][BYOC] handling dynamism in TensorRT to support OD models #6905
Conversation
refactoring test tensort code added comments to dynamic check wrapper log.warn changed to logger.info TRT codegen taking slice_mode into account TRT codegen to handle both stride_mode refactoring TRT codegen adding a test for dynamic offload [TRT] bug in codegen for slice_mode=end ctx determined from target in test + io test was missing
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.
Thanks @rohanmukh !
|
||
for i in range(0, len(args[0].checked_type.shape)): | ||
begin = int(attrs.begin[i]) | ||
end = ( |
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.
We need to take slice mode into account here also
@@ -715,6 +771,34 @@ def conv3d_transpose_annotate_fn(expr): # pylint: disable=unused-variable | |||
return False | |||
return True | |||
|
|||
_register_external_dynamic_check_func("add", add_annotate_fn) |
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.
I'm not sure if using the wrapper is better than adding a call to check_dynamism to each annotator. With the previous method, the annotator is all in one place with the decorator. Now, we have to remember to call register down here after writing the functions.
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 it also not lead to the same issue, that we have to remember to check for check_dynamism in each of the annotator?
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.
I see, can we make this function a decorator then?
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.
Thanks, I did that. Also tested its efficacy with test_dynamic_offload(). Can you please cross-verify the decorator usage?
@@ -133,26 +133,34 @@ class TensorRTJSONSerializer : public backend::contrib::JSONSerializer { | |||
auto process_slice_index = [](Integer x, int default_value, int dim_value) { | |||
if (!x.defined()) return default_value; | |||
int value = x.as<IntImmNode>()->value; | |||
if (value < 0) value += dim_value; | |||
value = (value < 0 ) ? dim_value + value : value; |
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 line is the same as the previous code, can you change it back?
@@ -944,7 +944,7 @@ class ReduceOpConverter : public TensorRTOpConverter { | |||
#if TRT_VERSION_GE(5, 1, 5) | |||
class StridedSliceOpConverter : public TensorRTOpConverter { | |||
public: | |||
StridedSliceOpConverter() : TensorRTOpConverter({kTensor, kWeight, kWeight, kWeight}) {} | |||
StridedSliceOpConverter() : TensorRTOpConverter({kTensor}) {} // , kWeight, kWeight, kWeight}) {} |
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.
Remove comment
|
||
|
||
def test_tensorrt_serialize(): | ||
def test_tensorrt_serialize(data_shape=(1, 3, 224, 224), data_type="float32"): |
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.
I think it would be good to split this into test_tensorrt_serialize_graph_runtime
and test_tensorrt_serialize_vm
@@ -841,6 +906,39 @@ def get_graph( | |||
run_and_verify_func(get_graph(strides=(2, 2, 2))) | |||
run_and_verify_func(get_graph(strides=(2, 2, 2), output_padding=(1, 1, 1))) | |||
|
|||
def test_tensorrt_ops(): |
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.
You can leave these in main
Thanks for the comments @trevor-m. |
@@ -18,11 +18,12 @@ | |||
"""TensorRT supported operators.""" | |||
import logging | |||
import numpy as np | |||
import os |
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.
Do we need this?
), | ||
transform.FoldConstant(), | ||
transform.InferType(), |
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.
Do we need this?
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.
Thanks for pointing, we don't, was used for debugging purposes only.
|
||
Parameters | ||
---------- | ||
args: a TRT array of the arguments of the op |
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.
Please follow Python style for docstrings
|
||
Parameters | ||
---------- | ||
op_name: name of the op for debugging purposes only |
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.
Same as above
_register_external_dynamic_check_func("nn.conv3d_transpose", conv3d_transpose_annotate_fn) | ||
|
||
|
||
|
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.
remove extra spaces everywhere
test_tensorrt_serialize() | ||
|
||
# Op tests | ||
test_tensorrt_serialize_graph_runtime() |
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.
you can remove all these test_xx and just use pytest.main([__file__])
because pytest is used for testing.
def save_vm(code, lib): | ||
# save and load the code and lib file. | ||
lib.export_library("path_lib.so") | ||
with open("path_code.ro", "wb") as fo: |
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.
its probably better to use tmp dir because you sometimes may not have write permission at the current dir.
# Get the expected relay graph and compare | ||
mod_exp = get_expected() | ||
tvm.ir.assert_structural_equal(mod_trt, mod_exp, map_free_vars=True) | ||
return |
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.
Don't need this return
test_densenet121() | ||
|
||
|
||
def test_dynamic_offload(data_shape=(1, 32, 8, 8), k_shape=(1, 32, 3, 3)): |
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.
Lets move the args to variables inside the test. Same for the serialization tests
skip_codegen added for test_tensorrt::test_dynamic_offload
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.
LGTM
test_pool3d() | ||
test_conv3d_transpose() | ||
|
||
def test_tensorrt_integration(): |
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.
We can remove this function - these tests will already be ran
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.
Thanks @trevor-m, sorry I missed that while importing the tests to pytest.
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.
Thanks!
Thanks @rohanmukh @zhiics @trevor-m This is merged |
…e#6905) * handling dynamism in TensorRT to support OD models refactoring test tensort code added comments to dynamic check wrapper log.warn changed to logger.info TRT codegen taking slice_mode into account TRT codegen to handle both stride_mode refactoring TRT codegen adding a test for dynamic offload [TRT] bug in codegen for slice_mode=end ctx determined from target in test + io test was missing * Addressed the formatting/refactoring comments * Addressed comment in TRT codegen Lint formatting * Lint error * using slice_mode during strided slice registration in tensorrt.py * removed a few blank lines * addressing cli comment on elif-return * Added decorator for tensorrt functions with dynamism check skip_codegen added for test_tensorrt::test_dynamic_offload * addressed comments in PR + black linting * resolved import error in test_tensorrt * import mxnet location changed to pass CI * test_integration removed as components were run by pytest anyway
…e#6905) * handling dynamism in TensorRT to support OD models refactoring test tensort code added comments to dynamic check wrapper log.warn changed to logger.info TRT codegen taking slice_mode into account TRT codegen to handle both stride_mode refactoring TRT codegen adding a test for dynamic offload [TRT] bug in codegen for slice_mode=end ctx determined from target in test + io test was missing * Addressed the formatting/refactoring comments * Addressed comment in TRT codegen Lint formatting * Lint error * using slice_mode during strided slice registration in tensorrt.py * removed a few blank lines * addressing cli comment on elif-return * Added decorator for tensorrt functions with dynamism check skip_codegen added for test_tensorrt::test_dynamic_offload * addressed comments in PR + black linting * resolved import error in test_tensorrt * import mxnet location changed to pass CI * test_integration removed as components were run by pytest anyway
…e#6905) * handling dynamism in TensorRT to support OD models refactoring test tensort code added comments to dynamic check wrapper log.warn changed to logger.info TRT codegen taking slice_mode into account TRT codegen to handle both stride_mode refactoring TRT codegen adding a test for dynamic offload [TRT] bug in codegen for slice_mode=end ctx determined from target in test + io test was missing * Addressed the formatting/refactoring comments * Addressed comment in TRT codegen Lint formatting * Lint error * using slice_mode during strided slice registration in tensorrt.py * removed a few blank lines * addressing cli comment on elif-return * Added decorator for tensorrt functions with dynamism check skip_codegen added for test_tensorrt::test_dynamic_offload * addressed comments in PR + black linting * resolved import error in test_tensorrt * import mxnet location changed to pass CI * test_integration removed as components were run by pytest anyway
refactoring test tensort code
added comments to dynamic check wrapper
log.warn changed to logger.info
TRT codegen taking slice_mode into account
TRT codegen to handle both types of stride_mode
refactoring TRT codegen
adding a test for dynamic offload
[TRT] bug in codegen for slice_mode=end
ctx determined from target in test + io test was missing