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

[BYOC][TensorRT] Make TRT runtime robust to empty or weird subgraphs #7581

Merged
merged 2 commits into from
Mar 4, 2021

Conversation

trevor-m
Copy link
Contributor

@trevor-m trevor-m commented Mar 3, 2021

TensorRT doesn't allow a graph to use the same nodes as both an input and output, nor does it allow an output to be marked as an output multiple times.

It seems there are still some corners cases where the partitioning can make these subgraphs which would cause TRT to crash at runtime during graph build. This PR will prevent the crash and allow the model to execute properly. I think it's good to have this in place in case there are more issues with partitioning we aren't aware of yet.

I will make a separate PR to fix the partitioning bug I have found.

@trevor-m trevor-m changed the title [TRT] Make TRT runtime robust to empty or weird subgraphs [BYOC][TensorRT] Make TRT runtime robust to empty or weird subgraphs Mar 3, 2021
@comaniac
Copy link
Contributor

comaniac commented Mar 3, 2021

Thanks for the fix. Is it possbile to add a test case?

@trevor-m
Copy link
Contributor Author

trevor-m commented Mar 3, 2021

Thanks @comaniac just added one

Test output before fix

ubuntu@ip-172-31-15-219:/data/neo-ai-tvm/build$ python3 -m pytest ../tests/python/contrib/test_tensorrt.py -sk test_empty
enabled targets: llvm -device=arm_cpu; nvptx; llvm; cuda
pytest marker: 
====================================================================== test session starts =======================================================================
platform linux -- Python 3.6.6, pytest-6.1.2, py-1.9.0, pluggy-0.13.1
rootdir: /data/neo-ai-tvm, configfile: pytest.ini
plugins: arraydiff-0.2, cov-2.10.1, openfiles-0.3.0, remotedata-0.3.2, doctestplus-0.1.3
collected 49 items / 48 deselected / 1 selected                                                                                                                  

../tests/python/contrib/test_tensorrt.py [21:52:03] /data/neo-ai-tvm/src/runtime/contrib/tensorrt/tensorrt_logger.h:51: ERROR: Tensor tensorrt_output_0 cannot be both input and output
[21:52:03] /data/neo-ai-tvm/src/runtime/contrib/tensorrt/tensorrt_logger.h:51: ERROR: Network must have at least one output
[21:52:03] /data/neo-ai-tvm/src/runtime/contrib/tensorrt/tensorrt_logger.h:51: ERROR: Network validation failed.
Segmentation fault (core dumped)

With fix:

ubuntu@ip-172-31-15-219:/data/neo-ai-tvm/build$ python3 -m pytest ../tests/python/contrib/test_tensorrt.py -sk test_empty
enabled targets: cuda; nvptx; llvm -device=arm_cpu; llvm
pytest marker: 
====================================================================== test session starts =======================================================================
platform linux -- Python 3.6.6, pytest-6.1.2, py-1.9.0, pluggy-0.13.1
rootdir: /data/neo-ai-tvm, configfile: pytest.ini
plugins: arraydiff-0.2, cov-2.10.1, openfiles-0.3.0, remotedata-0.3.2, doctestplus-0.1.3
collected 49 items / 48 deselected / 1 selected                                                                                                                  

../tests/python/contrib/test_tensorrt.py [21:52:25] /data/neo-ai-tvm/src/runtime/contrib/tensorrt/tensorrt_builder.cc:106: tensorrt_output_0 is both an input and an output.
[21:52:26] /data/neo-ai-tvm/src/runtime/contrib/tensorrt/tensorrt_logger.h:54: WARNING: Current optimization profile is: 0. Please ensure there are no enqueued operations pending in this context prior to switching profiles
.

================================================================ 1 passed, 48 deselected in 3.05s ================================================================

Copy link
Contributor

@comaniac comaniac left a comment

Choose a reason for hiding this comment

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

LGTM

@comaniac comaniac self-assigned this Mar 3, 2021
@comaniac comaniac merged commit 3fbb0a3 into apache:main Mar 4, 2021
@comaniac
Copy link
Contributor

comaniac commented Mar 4, 2021

Thanks @trevor-m

trevor-m pushed a commit to trevor-m/tvm that referenced this pull request May 6, 2021
…pache#7581)

* Prevent TRT runtime crash for duplicate inputs and outputs

* Add empty subgraph unit test
trevor-m pushed a commit to neo-ai/tvm that referenced this pull request May 11, 2021
…pache#7581)

* Prevent TRT runtime crash for duplicate inputs and outputs

* Add empty subgraph unit test
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.

2 participants