Skip to content

[TRT][BYOC] handling dynamism in TensorRT to support OD models#6905

Merged
anijain2305 merged 12 commits into
apache:mainfrom
rohanmukh:trt_dev_mn
Nov 13, 2020
Merged

[TRT][BYOC] handling dynamism in TensorRT to support OD models#6905
anijain2305 merged 12 commits into
apache:mainfrom
rohanmukh:trt_dev_mn

Conversation

@rohanmukh

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

@trevor-m trevor-m left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Thanks @rohanmukh !

Comment thread python/tvm/relay/op/contrib/tensorrt.py Outdated

for i in range(0, len(args[0].checked_type.shape)):
begin = int(attrs.begin[i])
end = (

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

Comment thread python/tvm/relay/op/contrib/tensorrt.py Outdated
return False
return True

_register_external_dynamic_check_func("add", add_annotate_fn)

Copy link
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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?

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
Copy Markdown
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?

class StridedSliceOpConverter : public TensorRTOpConverter {
public:
StridedSliceOpConverter() : TensorRTOpConverter({kTensor, kWeight, kWeight, kWeight}) {}
StridedSliceOpConverter() : TensorRTOpConverter({kTensor}) {} // , kWeight, kWeight, kWeight}) {}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Remove comment

Comment thread tests/python/contrib/test_tensorrt.py Outdated


def test_tensorrt_serialize():
def test_tensorrt_serialize(data_shape=(1, 3, 224, 224), data_type="float32"):

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

Comment thread tests/python/contrib/test_tensorrt.py Outdated
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
Copy Markdown
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
Copy Markdown
Contributor Author

Thanks for the comments @trevor-m.

Comment thread python/tvm/relay/op/contrib/tensorrt.py Outdated
"""TensorRT supported operators."""
import logging
import numpy as np
import os

Copy link
Copy Markdown
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?

Comment thread python/tvm/relay/op/contrib/tensorrt.py Outdated
"nn.conv3d": ["NCDHW", "default"]}
),
transform.FoldConstant(),
transform.InferType(),

Copy link
Copy Markdown
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
Copy Markdown
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.

Comment thread python/tvm/relay/op/contrib/tensorrt.py Outdated

Parameters
----------
args: a TRT array of the arguments of the op

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

Comment thread python/tvm/relay/op/contrib/tensorrt.py Outdated

Parameters
----------
op_name: name of the op for debugging purposes only

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Same as above

Comment thread python/tvm/relay/op/contrib/tensorrt.py Outdated
_register_external_dynamic_check_func("nn.conv3d_transpose", conv3d_transpose_annotate_fn)



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

Comment thread python/tvm/relay/op/contrib/tensorrt.py
Comment thread tests/python/contrib/test_tensorrt.py Outdated
test_tensorrt_serialize()

# Op tests
test_tensorrt_serialize_graph_runtime()

Copy link
Copy Markdown
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.

Comment thread tests/python/contrib/test_tensorrt.py Outdated
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
Copy Markdown
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.

Comment thread tests/python/contrib/test_tensorrt.py Outdated
# 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
Copy Markdown
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

Comment thread tests/python/contrib/test_tensorrt.py Outdated
test_densenet121()


def test_dynamic_offload(data_shape=(1, 32, 8, 8), k_shape=(1, 32, 3, 3)):

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

@zhiics zhiics left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

LGTM

Comment thread tests/python/contrib/test_tensorrt.py Outdated
test_pool3d()
test_conv3d_transpose()

def test_tensorrt_integration():

Copy link
Copy Markdown
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
Copy Markdown
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.

@trevor-m trevor-m left a comment

Copy link
Copy Markdown
Contributor

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
Copy Markdown
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