Skip to content
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

Merged
merged 12 commits into from
Nov 13, 2020

Conversation

rohanmukh
Copy link
Contributor

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

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
@rohanmukh
Copy link
Contributor Author

Copy link
Contributor

@trevor-m trevor-m left a 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 = (
Copy link
Contributor

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)
Copy link
Contributor

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.

Copy link
Contributor Author

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?

Copy link
Contributor

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?

Copy link
Contributor Author

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;
Copy link
Contributor

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}) {}
Copy link
Contributor

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"):
Copy link
Contributor

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():
Copy link
Contributor

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

@rohanmukh
Copy link
Contributor Author

Thanks for the comments @trevor-m.

@@ -18,11 +18,12 @@
"""TensorRT supported operators."""
import logging
import numpy as np
import os
Copy link
Contributor

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(),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we need this?

Copy link
Contributor Author

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
Copy link
Contributor

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
Copy link
Contributor

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)



Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

remove extra spaces everywhere

python/tvm/relay/op/contrib/tensorrt.py Show resolved Hide resolved
test_tensorrt_serialize()

# Op tests
test_tensorrt_serialize_graph_runtime()
Copy link
Member

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:
Copy link
Member

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
Copy link
Contributor

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)):
Copy link
Contributor

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

Copy link
Member

@zhiics zhiics left a 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():
Copy link
Contributor

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

Copy link
Contributor Author

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.

Copy link
Contributor

@trevor-m trevor-m left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks!

@anijain2305 anijain2305 merged commit b4f99e5 into apache:main Nov 13, 2020
@anijain2305
Copy link
Contributor

Thanks @rohanmukh @zhiics @trevor-m This is merged

trevor-m pushed a commit to trevor-m/tvm that referenced this pull request Dec 2, 2020
…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
trevor-m pushed a commit to trevor-m/tvm that referenced this pull request Dec 4, 2020
…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
trevor-m pushed a commit to neo-ai/tvm that referenced this pull request Dec 4, 2020
…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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants