Skip to content

Commit

Permalink
feat: Add functionality for tests to use precompiled libraries
Browse files Browse the repository at this point in the history
Signed-off-by: Dheeraj Peri <[email protected]>
  • Loading branch information
peri044 committed Oct 12, 2021
1 parent 9860f85 commit b5c324a
Show file tree
Hide file tree
Showing 11 changed files with 44 additions and 20 deletions.
7 changes: 7 additions & 0 deletions WORKSPACE
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,13 @@ git_repository(
shallow_since = "1570114335 -0400",
)

# External dependency for trtorch if you already have precompiled binaries.
# This is currently used in pytorch NGC container CI testing.
local_repository(
name = "trtorch",
path = "/opt/pytorch/trtorch"
)

# CUDA should be installed on the system locally
new_local_repository(
name = "cuda",
Expand Down
7 changes: 7 additions & 0 deletions tests/BUILD
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
config_setting(
name = "ci_build_testing",
values = {
"define": "trtorch_src=pre_built"
}
)

test_suite(
name = "tests",
tests = [
Expand Down
29 changes: 28 additions & 1 deletion tests/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,37 @@ The goal of Converter tests are to tests individual converters againsts specific

Module tests are designed to test the compiler against common network architectures and verify the integration of converters together into a single engine.

In addition to the above, we have lowering tests (`//core/lowering`) which test the functionality of lowering passes and partitioning tests (`//core/partitioning `) which test different cases of torch fallback on test networks.

You can run the whole test suite with bazel. But be aware you may exhaust GPU memory (this may be seen as a cuDNN initialization error) running them naively, you therefore may need to limit the number of concurrent tests. Also because the inputs to tests are random it may make sense to run tests a few times.

Here are some settings that work well the current test suite on a TITAN V.
Here are some settings that we usually test with:

```
bazel test //tests --compilation_mode=dbg --test_output=errors --jobs=4 --runs_per_test=5
```

`--runs_per_test` is optional and can be performed to check if numerical issues in outputs persist across multiple runs.

`--jobs=4` is useful and is sometimes required to prevent too many processes to use GPU memory and cause CUDA out of memory issues.

### Testing using pre-built TRTorch library

Currently, the default strategy when we run all the tests (`bazel test //tests`) is to build the testing scripts along with the full TRTorch library (`libtrtorch.so`) from scratch. This can lead to increased testing time and might not be needed incase you already have a pre-built TRTorch library that you want to link against.

In order to **not** build the entire TRTorch library and only build the test scripts, please use the following command.

```
bazel test //tests --compilation_mode=dbg --test_output=summary --define trtorch_src=pre_built --jobs 2
```

The flag `--define trtorch_src=pre_built` signals bazel to use pre-compiled library as an external dependency for tests. The pre-compiled library path is defined as a `local_repository` rule in root `WORKSPACE` file (`https://github.com/NVIDIA/TRTorch/blob/master/WORKSPACE`).

```
# External dependency for trtorch if you already have precompiled binaries.
# This is currently used in pytorch NGC container CI testing.
local_repository(
name = "trtorch",
path = "/opt/pytorch/trtorch"
)
```
1 change: 0 additions & 1 deletion tests/core/conversion/converters/converter_test.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ def converter_test(name, visibility = None):
visibility = visibility,
deps = [
"//tests/util",
"//core",
"@googletest//:gtest_main",
] + select({
":use_pre_cxx11_abi": ["@libtorch_pre_cxx11_abi//:libtorch"],
Expand Down
1 change: 0 additions & 1 deletion tests/core/conversion/evaluators/evaluator_test.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ def evaluator_test(name, visibility = None):
visibility = visibility,
deps = [
"//tests/util",
"//core",
"@googletest//:gtest_main",
] + select({
":use_pre_cxx11_abi": ["@libtorch_pre_cxx11_abi//:libtorch"],
Expand Down
1 change: 0 additions & 1 deletion tests/core/lowering/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ cc_test(
srcs = ["test_module_fallback_passes.cpp"],
deps = [
"//tests/util",
"//core",
"@googletest//:gtest_main",
] + select({
":use_pre_cxx11_abi": ["@libtorch_pre_cxx11_abi//:libtorch"],
Expand Down
1 change: 0 additions & 1 deletion tests/core/lowering/lowering_test.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ def lowering_test(name, visibility = None):
visibility = visibility,
deps = [
"//tests/util",
"//core",
"@googletest//:gtest_main",
] + select({
":use_pre_cxx11_abi": ["@libtorch_pre_cxx11_abi//:libtorch"],
Expand Down
4 changes: 1 addition & 3 deletions tests/core/partitioning/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@ cc_test(
srcs = ["test_fallback_graph_output.cpp"],
deps = [
"//tests/util",
"//core",
"@googletest//:gtest_main",
] + select({
":use_pre_cxx11_abi": ["@libtorch_pre_cxx11_abi//:libtorch"],
Expand All @@ -51,7 +50,6 @@ cc_test(
srcs = ["test_conditionals.cpp"],
deps = [
"//tests/util",
"//core",
"@googletest//:gtest_main",
] + select({
":use_pre_cxx11_abi": ["@libtorch_pre_cxx11_abi//:libtorch"],
Expand All @@ -72,4 +70,4 @@ test_suite(
":test_fallback_graph_output",
":test_conditionals"
]
)
)
1 change: 0 additions & 1 deletion tests/core/partitioning/partitioning_test.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ def partitioning_test(name, visibility=None):
visibility = visibility,
deps = [
"//tests/util",
"//core",
"@googletest//:gtest_main",
] + select({
":use_pre_cxx11_abi": ["@libtorch_pre_cxx11_abi//:libtorch"],
Expand Down
3 changes: 0 additions & 3 deletions tests/cpp/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,6 @@ cc_test(
"//tests/modules:jit_models",
],
deps = [
"//cpp:trtorch",
"//tests/util",
"@googletest//:gtest_main",
] + select({
Expand Down Expand Up @@ -102,7 +101,6 @@ cc_test(
"//tests/modules:jit_models",
],
deps = [
"//cpp:trtorch",
"//tests/util",
"@googletest//:gtest_main",
] + select({
Expand Down Expand Up @@ -137,7 +135,6 @@ cc_library(
name = "cpp_api_test",
hdrs = ["cpp_api_test.h"],
deps = [
"//cpp:trtorch",
"//tests/util",
"@googletest//:gtest_main",
] + select({
Expand Down
9 changes: 1 addition & 8 deletions tests/util/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,6 @@ config_setting(
},
)

config_setting(
name = "ci_build_testing",
values = {
"define": "trtorch_src=pre_built"
}
)

cc_library(
name = "util",
srcs = [
Expand All @@ -38,7 +31,7 @@ cc_library(
"@libtorch//:caffe2",
],
}) + select({
":ci_build_testing": [
"//tests:ci_build_testing": [
"@trtorch//:trtorch",
"@trtorch//:trtorch_core_hdrs"
],
Expand Down

0 comments on commit b5c324a

Please sign in to comment.