[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
|
|
||
| for i in range(0, len(args[0].checked_type.shape)): | ||
| begin = int(attrs.begin[i]) | ||
| end = ( |
There was a problem hiding this comment.
We need to take slice mode into account here also
| return False | ||
| return True | ||
|
|
||
| _register_external_dynamic_check_func("add", add_annotate_fn) |
There was a problem hiding this comment.
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.
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.
I see, can we make this function a decorator then?
There was a problem hiding this comment.
Thanks, I did that. Also tested its efficacy with test_dynamic_offload(). Can you please cross-verify the decorator usage?
| 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.
This line is the same as the previous code, can you change it back?
| class StridedSliceOpConverter : public TensorRTOpConverter { | ||
| public: | ||
| StridedSliceOpConverter() : TensorRTOpConverter({kTensor, kWeight, kWeight, kWeight}) {} | ||
| StridedSliceOpConverter() : TensorRTOpConverter({kTensor}) {} // , kWeight, kWeight, kWeight}) {} |
|
|
||
|
|
||
| def test_tensorrt_serialize(): | ||
| def test_tensorrt_serialize(data_shape=(1, 3, 224, 224), data_type="float32"): |
There was a problem hiding this comment.
I think it would be good to split this into test_tensorrt_serialize_graph_runtime and test_tensorrt_serialize_vm
| 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.
You can leave these in main
|
Thanks for the comments @trevor-m. |
| """TensorRT supported operators.""" | ||
| import logging | ||
| import numpy as np | ||
| import os |
| "nn.conv3d": ["NCDHW", "default"]} | ||
| ), | ||
| transform.FoldConstant(), | ||
| transform.InferType(), |
There was a problem hiding this comment.
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.
Please follow Python style for docstrings
|
|
||
| Parameters | ||
| ---------- | ||
| op_name: name of the op for debugging purposes only |
| _register_external_dynamic_check_func("nn.conv3d_transpose", conv3d_transpose_annotate_fn) | ||
|
|
||
|
|
||
|
|
There was a problem hiding this comment.
remove extra spaces everywhere
| test_tensorrt_serialize() | ||
|
|
||
| # Op tests | ||
| test_tensorrt_serialize_graph_runtime() |
There was a problem hiding this comment.
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.
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 |
| 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.
Lets move the args to variables inside the test. Same for the serialization tests
skip_codegen added for test_tensorrt::test_dynamic_offload
| test_pool3d() | ||
| test_conv3d_transpose() | ||
|
|
||
| def test_tensorrt_integration(): |
There was a problem hiding this comment.
We can remove this function - these tests will already be ran
There was a problem hiding this comment.
Thanks @trevor-m, sorry I missed that while importing the tests to pytest.
|
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