diff --git a/.bazelversion b/.bazelversion index 712bd5a680..8cf6caf561 100644 --- a/.bazelversion +++ b/.bazelversion @@ -1 +1 @@ -3.3.1 \ No newline at end of file +3.4.1 \ No newline at end of file diff --git a/WORKSPACE b/WORKSPACE index 671f0c3e33..dbcbc3cf45 100644 --- a/WORKSPACE +++ b/WORKSPACE @@ -53,16 +53,16 @@ http_archive( name = "libtorch", build_file = "@//third_party/libtorch:BUILD", strip_prefix = "libtorch", - urls = ["https://download.pytorch.org/libtorch/cu102/libtorch-cxx11-abi-shared-with-deps-1.5.1.zip"], - sha256 = "cf0691493d05062fe3239cf76773bae4c5124f4b039050dbdd291c652af3ab2a" + urls = ["https://download.pytorch.org/libtorch/cu102/libtorch-cxx11-abi-shared-with-deps-1.6.0.zip"], + sha256 = "fded948bd2dbee625cee33ebbd4843a69496729389e0200a90fbb667cdaeeb69" ) http_archive( name = "libtorch_pre_cxx11_abi", build_file = "@//third_party/libtorch:BUILD", strip_prefix = "libtorch", - sha256 = "818977576572eadaf62c80434a25afe44dbaa32ebda3a0919e389dcbe74f8656", - urls = ["https://download.pytorch.org/libtorch/cu102/libtorch-shared-with-deps-1.5.1.zip"], + sha256 = "141bb229f4bbf905541096cf8705785e7b0c79e37ca1e5db9d372730b1b9abd7", + urls = ["https://download.pytorch.org/libtorch/cu102/libtorch-shared-with-deps-1.6.0.zip"], ) # Download these tarballs manually from the NVIDIA website diff --git a/core/conversion/InterfaceTypes.cpp b/core/conversion/InterfaceTypes.cpp index e9e07a33dd..de1a1d867b 100644 --- a/core/conversion/InterfaceTypes.cpp +++ b/core/conversion/InterfaceTypes.cpp @@ -8,7 +8,7 @@ namespace core { namespace conversion { GraphParams get_named_params(c10::ArrayRef inputs, - std::vector params) { + std::vector params) { GraphParams named_params; auto param_it = params.begin(); for (auto in : inputs) { @@ -18,10 +18,8 @@ GraphParams get_named_params(c10::ArrayRef inputs, ++param_it; } } - //ASSERT(named_params.size() == params.size); - if (named_params.size() != params.size()) { - LOG_ERROR("Graph parameter parsing failed"); - } + + TRTORCH_CHECK(named_params.size() == params.size(), "Graph parameter parsing failed, mismatched number of static parameters and IValues") return std::move(named_params); } diff --git a/core/conversion/conversion.cpp b/core/conversion/conversion.cpp index 1a3b9ba93f..12880052c6 100644 --- a/core/conversion/conversion.cpp +++ b/core/conversion/conversion.cpp @@ -165,10 +165,11 @@ void AddInputs(ConversionCtx* ctx, TRTORCH_CHECK(profile->isValid(), "Optimization profile is invalid, please check the input range provided (conversion.AddInputs)"); ctx->cfg->addOptimizationProfile(profile); - // TODO: Enable in TRT 7.1 - // if (ctx->op_precision == nvinfer1::DataType::kINT8) { - // ctx->cfg->setCalibrationProfile(profile); - // } +#if NV_TENSORRT_MAJOR > 7 || (NV_TENSORRT_MAJOR == 7 && NV_TENSORRT_MINOR >= 1) + if (ctx->op_precision == nvinfer1::DataType::kINT8) { + ctx->cfg->setCalibrationProfile(profile); + } +#endif } void MarkOutputs(ConversionCtx* ctx, at::ArrayRef outputs) { @@ -186,7 +187,7 @@ void MarkOutputs(ConversionCtx* ctx, at::ArrayRef outp void AddParamsToCtxValueMap(ConversionCtx* ctx, GraphParams& params) { for (auto p : params) { - ctx->evaluated_value_map[p.first] = torch::jit::IValue(p.second.clone()); + ctx->evaluated_value_map[p.first] = std::move(p.second); } } diff --git a/core/conversion/conversion.h b/core/conversion/conversion.h index 1c7a790025..7076957dd8 100644 --- a/core/conversion/conversion.h +++ b/core/conversion/conversion.h @@ -30,9 +30,11 @@ struct ConversionInfo { : input_ranges(std::move(input_ranges)), engine_settings(BuilderSettings()) {} }; -using GraphParams = std::map; +//TODO: REMOVE GRAPH AND PARAMS AND MOVE FULLY TO INLINED CONSTANTS -GraphParams get_named_params(c10::ArrayRef inputs, std::vector params); +using GraphParams = std::map; + +GraphParams get_named_params(c10::ArrayRef inputs, std::vector params); // Converts a already lowered block (blocks with no sub blocks) to // a serialized TensorRT engine that can be deserialized and run diff --git a/core/conversion/evaluators/BUILD b/core/conversion/evaluators/BUILD index cbc5318342..038408771d 100644 --- a/core/conversion/evaluators/BUILD +++ b/core/conversion/evaluators/BUILD @@ -16,7 +16,9 @@ cc_library( "NodeEvaluatorRegistry.cpp", "prim.cpp", "aten.cpp", - "eval_macros.h" + "eval_macros.h", + "eval_util.h", + "eval_util.cpp" ], deps = [ "//core/util:prelude", diff --git a/core/conversion/evaluators/eval_util.cpp b/core/conversion/evaluators/eval_util.cpp new file mode 100644 index 0000000000..486585f805 --- /dev/null +++ b/core/conversion/evaluators/eval_util.cpp @@ -0,0 +1,105 @@ +#include "ATen/core/ivalue.h" +#include "ATen/core/List.h" +#include "core/util/prelude.h" +#include "ATen/core/functional.h" + +namespace trtorch { +namespace core { +namespace conversion { +namespace evaluators { + +//TODO: Switch back to PyTorch canonical implimentation +c10::optional toIValue(const torch::jit::Value* v) { + if (v->node()->kind() != torch::jit::prim::Constant || v->type()->cast()) { + return c10::nullopt; + } + const torch::jit::Node* node = v->node(); + const c10::TypePtr& type = v->type(); + if (type->isSubtypeOf(c10::TensorType::get())) { + return node->t(c10::attr::value); + } else if (type->isSubtypeOf(c10::BoolType::get())) { + return (bool)node->i(c10::attr::value); + } else if ( + type->isSubtypeOf(c10::NumberType::get()) && + node->kindOf(c10::attr::value) == torch::jit::AttributeKind::i) { + return node->i(c10::attr::value); + } else if ( + type->isSubtypeOf(c10::NumberType::get()) && + node->kindOf(c10::attr::value) == torch::jit::AttributeKind::f) { + return node->f(c10::attr::value); + } else if (type->isSubtypeOf(c10::ListType::ofInts())) { + try { + const auto& is = node->is(c10::attr::value); + return is; + } catch (const std::exception& ex) { + const auto& ival = node->ival(c10::attr::value); + return ival; + } + } else if (type->isSubtypeOf(c10::ListType::ofFloats())) { + try { + const auto& fs = node->fs(c10::attr::value); + return fs; + } catch (const std::exception& ex) { + const auto& ival = node->ival(c10::attr::value); + return ival; + } + } else if (type->isSubtypeOf(c10::ListType::ofBools())) { + const auto bs = c10::fmap(node->is(c10::attr::value)); + return bs; + } else if (type->isSubtypeOf(c10::ListType::ofTensors())) { + try { + const auto& ts = node->ts(c10::attr::value); + return ts; + } catch (const std::exception& ex) { + const auto& ival = node->ival(c10::attr::value); + return ival; + } + } else if (type->isSubtypeOf(c10::ListType::ofStrings())) { + try { + const auto& ss = node->ss(c10::attr::value); + auto vals = c10::impl::GenericList(c10::StringType::get()); + for (const auto& str : ss) { + vals.push_back(str); + } + return vals; + } catch (const std::exception& ex) { + const auto& ival = node->ival(c10::attr::value); + return ival; + } + } else if ( + type->cast() && + node->kindOf(c10::attr::value) == torch::jit::AttributeKind::ival) { + const auto& list = node->ival(c10::attr::value); + TRTORCH_ASSERT(list.isList(), "Is not a list"); + return list; + } else if ( + type->cast() && + node->kindOf(c10::attr::value) == torch::jit::AttributeKind::ival) { + const auto& dict = node->ival(c10::attr::value); + TRTORCH_ASSERT(dict.isGenericDict(), "Is not a dict"); + return dict; + } else if ( + type->cast() && + node->kindOf(c10::attr::value) == torch::jit::AttributeKind::ival) { + const auto& tup = node->ival(c10::attr::value); + TRTORCH_ASSERT(tup.isTuple(), "Is not a tuple"); + return tup; + } else if (type == c10::StringType::get()) { + const auto& s = node->s(c10::attr::value); + return s; + } else if (type == c10::DeviceObjType::get()) { + auto d = c10::Device(node->s(c10::attr::value)); + return d; + } else if (node->mustBeNone()) { + return torch::jit::IValue(); + } else { + std::stringstream ss; + ss << "constant literal not supported for: " << type->str(); + throw std::runtime_error(ss.str()); + } +} + +} // namespace evaluators +} // namespace conversion +} // namespace core +} // namespace trtorch diff --git a/core/conversion/evaluators/eval_util.h b/core/conversion/evaluators/eval_util.h new file mode 100644 index 0000000000..1e31ddfe46 --- /dev/null +++ b/core/conversion/evaluators/eval_util.h @@ -0,0 +1,15 @@ +#pragma once + +#include "torch/csrc/jit/ir/ir.h" + +namespace trtorch { +namespace core { +namespace conversion { +namespace evaluators { + +c10::optional toIValue(const torch::jit::Value* v); + +} // namespace evaluators +} // namespace conversion +} // namespace core +} // namespace trtorch \ No newline at end of file diff --git a/core/conversion/evaluators/prim.cpp b/core/conversion/evaluators/prim.cpp index d40a33f4e7..385f6e0345 100644 --- a/core/conversion/evaluators/prim.cpp +++ b/core/conversion/evaluators/prim.cpp @@ -1,7 +1,7 @@ #include #include "torch/csrc/jit/ir/ir.h" -#include "torch/csrc/jit/ir/constants.h" +//#include "torch/csrc/jit/ir/constants.h" #include "ATen/core/functional.h" #include "ATen/core/ivalue.h" #include "ATen/core/List.h" @@ -11,6 +11,7 @@ #include "core/conversion/evaluators/evaluators.h" #include "core/conversion/evaluators/eval_macros.h" +#include "core/conversion/evaluators/eval_util.h" namespace trtorch { namespace core { @@ -25,7 +26,7 @@ auto prim_registrations = RegisterNodeEvaluators() if (n->output()->type()->kind() == at::FunctionType::Kind) { return {}; } - return torch::jit::toIValue(n->output()); + return evaluators::toIValue(n->output()); } }).evaluator({ torch::jit::prim::NumToTensor, diff --git a/core/lowering/lowering.cpp b/core/lowering/lowering.cpp index 3424a2ea97..eea21a265b 100644 --- a/core/lowering/lowering.cpp +++ b/core/lowering/lowering.cpp @@ -7,7 +7,6 @@ #include "torch/csrc/jit/passes/lower_graph.h" #include "torch/csrc/jit/passes/lower_tuples.h" #include "torch/csrc/jit/passes/peephole.h" -#include "torch/csrc/jit/passes/quantization.h" #include "core/util/prelude.h" #include "core/lowering/lowering.h" @@ -50,8 +49,7 @@ torch::jit::Module LowerModule(const torch::jit::script::Module& mod) { return mod_; } -std::pair, std::vector> Lower(const torch::jit::script::Module& mod, - std::string method_name) { +std::pair, std::vector> Lower(const torch::jit::script::Module& mod, std::string method_name) { auto lowered_mod = LowerModule(mod); auto g = lowered_mod.get_method(method_name).graph(); LOG_GRAPH(*g); @@ -62,10 +60,11 @@ std::pair, std::vector> Lower(con lowering::LowerGraph(g); //=[torch::jit::FoldConvBatchNorm2d(lowered_mod); LOG_GRAPH("LibTorch Lowering"); - auto graph_and_parameters = torch::jit::LowerGraph(*g, lowered_mod._ivalue()); + auto graph_and_ivalues = torch::jit::LowerGraph(*g, lowered_mod._ivalue()); // Is this necessary? lowering::LowerBlock(g->block()); - return graph_and_parameters; + + return graph_and_ivalues; } diff --git a/core/lowering/lowering.h b/core/lowering/lowering.h index 79f07cb5ec..e49780f7d8 100644 --- a/core/lowering/lowering.h +++ b/core/lowering/lowering.h @@ -9,8 +9,8 @@ namespace lowering { void LowerBlock(torch::jit::Block* b); void LowerGraph(std::shared_ptr& g); torch::jit::Module LowerModule(const torch::jit::script::Module& mod); -std::pair, std::vector> Lower(const torch::jit::script::Module& mod, - std::string method_name); +std::pair, std::vector> Lower(const torch::jit::script::Module& mod, + std::string method_name); } // namespace lowering } // namespace core diff --git a/cpp/api/include/trtorch/macros.h b/cpp/api/include/trtorch/macros.h index 508f7f49c3..5219d5d8fc 100644 --- a/cpp/api/include/trtorch/macros.h +++ b/cpp/api/include/trtorch/macros.h @@ -20,8 +20,8 @@ #define STR(x) XSTR(x) #define TRTORCH_MAJOR_VERSION 0 -#define TRTORCH_MINOR_VERSION 0 -#define TRTORCH_PATCH_VERSION 3 +#define TRTORCH_MINOR_VERSION 1 +#define TRTORCH_PATCH_VERSION 0 #define TRTORCH_VERSION STR(TRTORCH_MAJOR_VERSION) \ "." STR(TRTORCH_MINOR_VERSION) \ "." STR(TRTORCH_PATCH_VERSION) diff --git a/docker/Dockerfile.20.07 b/docker/Dockerfile.20.07 new file mode 100644 index 0000000000..7d9be4b453 --- /dev/null +++ b/docker/Dockerfile.20.07 @@ -0,0 +1,36 @@ +FROM nvcr.io/nvidia/pytorch:20.07-py3 + +RUN apt-get update && apt-get install curl gnupg && rm -rf /var/lib/apt/lists/* + +RUN curl https://bazel.build/bazel-release.pub.gpg | apt-key add - && \ + echo "deb [arch=amd64] https://storage.googleapis.com/bazel-apt stable jdk1.8" | tee /etc/apt/sources.list.d/bazel.list + +RUN apt-get update && apt-get install bazel-3.4.1 && rm -rf /var/lib/apt/lists/* +RUN ln -s /usr/bin/bazel-3.4.1 /usr/bin/bazel + +RUN pip install notebook + +COPY . /opt/trtorch +RUN rm /opt/trtorch/WORKSPACE +COPY ./docker/WORKSPACE.cu11.docker /opt/trtorch/WORKSPACE + +# Workaround for bazel expecting both static and shared versions, we only use shared libraries inside container +RUN cp /usr/lib/x86_64-linux-gnu/libnvinfer.so /usr/lib/x86_64-linux-gnu/libnvinfer_static.a + +WORKDIR /opt/trtorch +RUN bazel build //:libtrtorch --compilation_mode opt + +WORKDIR /opt/trtorch/py + +# Locale is not set by default +RUN apt-get update && apt-get install -y locales ninja-build && rm -rf /var/lib/apt/lists/* && locale-gen en_US.UTF-8 +ENV LANG en_US.UTF-8 +ENV LANGUAGE en_US:en +ENV LC_ALL en_US.UTF-8 +RUN python3 setup.py install --use-cxx11-abi + +RUN conda init bash + +ENV LD_LIBRARY_PATH /opt/conda/lib/python3.6/site-packages/torch/lib:$LD_LIBRARY_PATh + +WORKDIR /opt/trtorch/notebooks \ No newline at end of file diff --git a/docker/Dockerfile.docs b/docker/Dockerfile.docs index aece3b96b5..794f9c6d64 100644 --- a/docker/Dockerfile.docs +++ b/docker/Dockerfile.docs @@ -3,8 +3,8 @@ FROM nvcr.io/nvidia/tensorrt:20.03-py3 RUN curl https://bazel.build/bazel-release.pub.gpg | apt-key add - RUN echo "deb [arch=amd64] https://storage.googleapis.com/bazel-apt stable jdk1.8" | tee /etc/apt/sources.list.d/bazel.list -RUN apt update && apt install bazel-3.3.1 -RUN ln -s /usr/bin/bazel-3.3.1 /usr/bin/bazel +RUN apt update && apt install bazel-3.4.1 +RUN ln -s /usr/bin/bazel-3.4.1 /usr/bin/bazel COPY ./py/requirements.txt requirements.txt diff --git a/docker/WORKSPACE.cu11.docker b/docker/WORKSPACE.cu11.docker new file mode 100755 index 0000000000..dbe998f203 --- /dev/null +++ b/docker/WORKSPACE.cu11.docker @@ -0,0 +1,94 @@ +workspace(name = "TRTorch") + +load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive") +load("@bazel_tools//tools/build_defs/repo:git.bzl", "git_repository") + +git_repository( + name = "rules_python", + remote = "https://github.com/bazelbuild/rules_python.git", + commit = "4fcc24fd8a850bdab2ef2e078b1de337eea751a6", + shallow_since = "1589292086 -0400" +) + +load("@rules_python//python:repositories.bzl", "py_repositories") +py_repositories() + +load("@rules_python//python:pip.bzl", "pip_repositories", "pip3_import") +pip_repositories() + +http_archive( + name = "rules_pkg", + url = "https://github.com/bazelbuild/rules_pkg/releases/download/0.2.4/rules_pkg-0.2.4.tar.gz", + sha256 = "4ba8f4ab0ff85f2484287ab06c0d871dcb31cc54d439457d28fd4ae14b18450a", +) + +load("@rules_pkg//:deps.bzl", "rules_pkg_dependencies") +rules_pkg_dependencies() + +git_repository( + name = "googletest", + remote = "https://github.com/google/googletest", + commit = "703bd9caab50b139428cea1aaff9974ebee5742e", + shallow_since = "1570114335 -0400" +) + +# CUDA should be installed on the system locally +new_local_repository( + name = "cuda", + path = "/usr/local/cuda-11.0/", + build_file = "@//third_party/cuda:BUILD", +) + +new_local_repository( + name = "cublas", + path = "/usr", + build_file = "@//third_party/cublas:BUILD", +) + +#################################################################################### +# Locally installed dependencies (use in cases of custom dependencies or aarch64) +#################################################################################### + +new_local_repository( + name = "libtorch", + path = "/opt/conda/lib/python3.6/site-packages/torch", + build_file = "third_party/libtorch/BUILD" +) + +new_local_repository( + name = "libtorch_pre_cxx11_abi", + path = "/opt/conda/lib/python3.6/site-packages/torch", + build_file = "third_party/libtorch/BUILD" +) + +new_local_repository( + name = "cudnn", + path = "/usr/", + build_file = "@//third_party/cudnn/local:BUILD" +) + +new_local_repository( + name = "tensorrt", + path = "/usr/", + build_file = "@//third_party/tensorrt/local:BUILD" +) + +######################################################################### +# Testing Dependencies (optional - comment out on aarch64) +######################################################################### +pip3_import( + name = "trtorch_py_deps", + requirements = "//py:requirements.txt" +) + +load("@trtorch_py_deps//:requirements.bzl", "pip_install") +pip_install() + +pip3_import( + name = "py_test_deps", + requirements = "//tests/py:requirements.txt" +) + +load("@py_test_deps//:requirements.bzl", "pip_install") +pip_install() + diff --git a/docker/WORKSPACE.docker b/docker/WORKSPACE.docker index 9030af467b..25b5773226 100755 --- a/docker/WORKSPACE.docker +++ b/docker/WORKSPACE.docker @@ -53,16 +53,16 @@ http_archive( name = "libtorch", build_file = "@//third_party/libtorch:BUILD", strip_prefix = "libtorch", - urls = ["https://download.pytorch.org/libtorch/cu102/libtorch-cxx11-abi-shared-with-deps-1.5.1.zip"], - sha256 = "cf0691493d05062fe3239cf76773bae4c5124f4b039050dbdd291c652af3ab2a" + urls = ["https://download.pytorch.org/libtorch/cu102/libtorch-cxx11-abi-shared-with-deps-1.6.0.zip"], + sha256 = "fded948bd2dbee625cee33ebbd4843a69496729389e0200a90fbb667cdaeeb69" ) http_archive( name = "libtorch_pre_cxx11_abi", build_file = "@//third_party/libtorch:BUILD", strip_prefix = "libtorch", - sha256 = "818977576572eadaf62c80434a25afe44dbaa32ebda3a0919e389dcbe74f8656", - urls = ["https://download.pytorch.org/libtorch/cu102/libtorch-shared-with-deps-1.5.1.zip"], + sha256 = "141bb229f4bbf905541096cf8705785e7b0c79e37ca1e5db9d372730b1b9abd7", + urls = ["https://download.pytorch.org/libtorch/cu102/libtorch-shared-with-deps-1.6.0.zip"], ) #################################################################################### diff --git a/notebooks/Dockerfile.notebook b/notebooks/Dockerfile.notebook index 1ea91e6b18..55a118fae7 100644 --- a/notebooks/Dockerfile.notebook +++ b/notebooks/Dockerfile.notebook @@ -3,8 +3,8 @@ FROM nvcr.io/nvidia/tensorrt:20.03-py3 RUN curl https://bazel.build/bazel-release.pub.gpg | apt-key add - RUN echo "deb [arch=amd64] https://storage.googleapis.com/bazel-apt stable jdk1.8" | tee /etc/apt/sources.list.d/bazel.list -RUN apt update && apt install bazel-3.3.1 -RUN ln -s /usr/bin/bazel-3.3.1 /usr/bin/bazel +RUN apt update && apt install bazel-3.4.1 +RUN ln -s /usr/bin/bazel-3.4.1 /usr/bin/bazel RUN pip install pillow==4.3.0 RUN pip install torch==1.5.1 diff --git a/py/build_whl.sh b/py/build_whl.sh index 87a58feb05..aca11f4885 100755 --- a/py/build_whl.sh +++ b/py/build_whl.sh @@ -6,12 +6,6 @@ cd /workspace/TRTorch/py export CXX=g++ -build_py35() { - /opt/python/cp35-cp35m/bin/python -m pip install -r requirements.txt - /opt/python/cp35-cp35m/bin/python setup.py bdist_wheel - #auditwheel repair --plat manylinux2014_x86_64 -} - build_py36() { /opt/python/cp36-cp36m/bin/python -m pip install -r requirements.txt /opt/python/cp36-cp36m/bin/python setup.py bdist_wheel @@ -30,7 +24,6 @@ build_py38() { #auditwheel repair --plat manylinux2014_x86_64 } -build_py35 build_py36 build_py37 build_py38 \ No newline at end of file diff --git a/py/requirements.txt b/py/requirements.txt index 33c8f475c9..46e982e6b5 100644 --- a/py/requirements.txt +++ b/py/requirements.txt @@ -1 +1 @@ -torch==1.5.1 \ No newline at end of file +torch==1.6.0 \ No newline at end of file diff --git a/py/setup.py b/py/setup.py index d40a5cfc96..53f85dada1 100644 --- a/py/setup.py +++ b/py/setup.py @@ -16,7 +16,7 @@ dir_path = os.path.dirname(os.path.realpath(__file__)) -__version__ = '0.0.3' +__version__ = '0.1.0a0' CXX11_ABI = False @@ -158,7 +158,8 @@ def run(self): cpp_extension.CUDAExtension('trtorch._C', ['trtorch/csrc/trtorch_py.cpp'], library_dirs=[ - dir_path + '/trtorch/lib/' + (dir_path + '/trtorch/lib/'), + "/opt/conda/lib/python3.6/config-3.6m-x86_64-linux-gnu" ], libraries=[ "trtorch" @@ -176,7 +177,14 @@ def run(self): "-Wno-deprecated-declarations", "-Wl,--no-as-needed", "-ltrtorch", - "-Wl,-rpath,$ORIGIN/lib" + "-Wl,-rpath,$ORIGIN/lib", + "-lpthread", + "-ldl", + "-lutil", + "-lrt", + "-lm", + "-Xlinker", + "-export-dynamic" ] + (["-D_GLIBCXX_USE_CXX11_ABI=1"] if CXX11_ABI else ["-D_GLIBCXX_USE_CXX11_ABI=0"]), undef_macros=[ "NDEBUG" ] ) @@ -196,7 +204,7 @@ def run(self): long_description=long_description, ext_modules=ext_modules, install_requires=[ - 'torch==1.5.1', + 'torch==1.6.0', ], setup_requires=[], cmdclass={ @@ -210,7 +218,7 @@ def run(self): license="BSD", packages=find_packages(), classifiers=[ - "Development Status :: 3 - Alpha", + "Development Status :: 4 - Beta", "Environment :: GPU :: NVIDIA CUDA", "License :: OSI Approved :: BSD License", "Intended Audience :: Developers", @@ -224,7 +232,7 @@ def run(self): "Topic :: Software Development", "Topic :: Software Development :: Libraries" ], - python_requires='>=3.5', + python_requires='>=3.6', include_package_data=True, package_data={ 'trtorch': ['lib/*.so'], diff --git a/tests/core/converters/test_activation.cpp b/tests/core/converters/test_activation.cpp index 128c3895b1..c2b1046fd0 100644 --- a/tests/core/converters/test_activation.cpp +++ b/tests/core/converters/test_activation.cpp @@ -112,7 +112,7 @@ TEST(Converters, ATenHardTanhCustomRangeConvertsCorrectly) { TEST(Converters, ATenPReLUConvertsCorrectly) { const auto graph = R"IR( graph(%0 : Tensor, - %1 : Float(1)): + %1 : Float(1:1)): %3 : Tensor = aten::prelu(%0, %1) return (%3))IR"; @@ -135,7 +135,7 @@ TEST(Converters, ATenPReLUConvertsCorrectly) { TEST(Converters, ATenPReLUMultiChannelConvertsCorrectly) { const auto graph = R"IR( graph(%0 : Tensor, - %1 : Float(10)): + %1 : Float(10:1)): %3 : Tensor = aten::prelu(%0, %1) return (%3))IR"; diff --git a/tests/core/converters/test_batch_norm.cpp b/tests/core/converters/test_batch_norm.cpp index 727d7a17ea..7155fac642 100644 --- a/tests/core/converters/test_batch_norm.cpp +++ b/tests/core/converters/test_batch_norm.cpp @@ -7,10 +7,10 @@ TEST(Converters, ATenBatchNormConvertsCorrectly) { const auto graph = R"IR( graph(%0 : Tensor, - %1: Float(5), - %2: Float(5), - %3: Float(5), - %4: Float(5)): + %1: Float(5:1), + %2: Float(5:1), + %3: Float(5:1), + %4: Float(5:1)): %5 : bool = prim::Constant[value=0]() %6 : float = prim::Constant[value=1.0000000000000001e-05]() %7 : float = prim::Constant[value=0.10000000000000001]() diff --git a/tests/core/converters/test_concat.cpp b/tests/core/converters/test_concat.cpp index 359e15eadf..ecb7933845 100644 --- a/tests/core/converters/test_concat.cpp +++ b/tests/core/converters/test_concat.cpp @@ -31,7 +31,7 @@ TEST(Converters, ATenCatPureTensorConvertsCorrectly) { TEST(Converters, ATenCatDiffTensorConvertsCorrectly) { const auto graph = R"IR( graph(%0 : Tensor, - %1 : Float(5)): + %1 : Float(5:1)): %2 : Tensor[] = prim::ListConstruct(%0, %1) %3 : int = prim::Constant[value=0]() %4 : Tensor = aten::cat(%2, %3) diff --git a/tests/core/converters/test_conv_deconv.cpp b/tests/core/converters/test_conv_deconv.cpp index 2c633e4b29..94c4b1d330 100644 --- a/tests/core/converters/test_conv_deconv.cpp +++ b/tests/core/converters/test_conv_deconv.cpp @@ -39,8 +39,8 @@ void conv_test_helper(std::string graph_ir) { TEST(Converters, ATenConvolutionConvertsCorrectly) { const auto graph = R"IR( graph(%0 : Tensor, - %1 : Float(8, 3, 5, 5), - %2 : Float(8)): + %1 : Float(8:45, 3:15, 5:5, 5:1), + %2 : Float(8:1)): %3 : int = prim::Constant[value=1]() %4 : int = prim::Constant[value=0]() %5 : int = prim::Constant[value=1]() @@ -81,7 +81,7 @@ TEST(Converters, ATenConvolutionConvertsCorrectly) { TEST(Converters, ATenConvolutionNoBiasConvertsCorrectly) { const auto graph = R"IR( graph(%0 : Tensor, - %1 : Float(4, 1, 3, 3)): + %1 : Float(4:9, 1:9, 3:3, 3:1)): %2 : None = prim::Constant() %3 : int = prim::Constant[value=1]() %4 : int = prim::Constant[value=0]() @@ -120,8 +120,8 @@ TEST(Converters, ATenConvolutionNoBiasConvertsCorrectly) { TEST(Converters, ATenConvolutionWithStrideConvertsCorrectly) { const auto graph = R"IR( graph(%0 : Tensor, - %1 : Float(4, 3, 3, 3), - %2 : Float(4)): + %1 : Float(4:27, 3:9, 3:3, 3:1), + %2 : Float(4:1)): %3 : int = prim::Constant[value=3]() %4 : int = prim::Constant[value=0]() %5 : int = prim::Constant[value=1]() @@ -163,8 +163,8 @@ TEST(Converters, ATenConvolutionWithStrideConvertsCorrectly) { TEST(Converters, ATenConvolutionWithPaddingConvertsCorrectly) { const auto graph = R"IR( graph(%0 : Tensor, - %1 : Float(4, 3, 4, 4), - %2 : Float(4)): + %1 : Float(4:48, 3:16, 4:4, 4:1), + %2 : Float(4:1)): %3 : int = prim::Constant[value=1]() %4 : int = prim::Constant[value=2]() %5 : int = prim::Constant[value=1]() @@ -206,8 +206,8 @@ TEST(Converters, ATenConvolutionWithPaddingConvertsCorrectly) { TEST(Converters, ATenConvTransposeConvertsCorrectly) { const auto graph = R"IR( graph(%0 : Tensor, - %1 : Float(8, 3, 3, 3), - %2 : Float(8)): + %1 : Float(8:27, 3:9, 3:3, 3:1), + %2 : Float(8:1)): %3 : int = prim::Constant[value=1]() %4 : int = prim::Constant[value=0]() %5 : int = prim::Constant[value=1]() @@ -248,7 +248,7 @@ TEST(Converters, ATenConvTransposeConvertsCorrectly) { TEST(Converters, ATenConvTransposeNoBiasConvertsCorrectly) { const auto graph = R"IR( graph(%0 : Tensor, - %1 : Float(4, 1, 3, 3)): + %1 : Float(4:9, 1:9, 3:3, 3:1)): %2 : None = prim::Constant() %3 : int = prim::Constant[value=1]() %4 : int = prim::Constant[value=0]() @@ -287,8 +287,8 @@ TEST(Converters, ATenConvTransposeNoBiasConvertsCorrectly) { TEST(Converters, ATenConvTransposeWithStrideConvertsCorrectly) { const auto graph = R"IR( graph(%0 : Tensor, - %1 : Float(4, 3, 3, 3), - %2 : Float(4)): + %1 : Float(4:27, 3:9, 3:3, 3:1), + %2 : Float(4:1)): %3 : int = prim::Constant[value=3]() %4 : int = prim::Constant[value=0]() %5 : int = prim::Constant[value=1]() @@ -330,8 +330,8 @@ TEST(Converters, ATenConvTransposeWithStrideConvertsCorrectly) { TEST(Converters, ATenConvTransposeWithPaddingConvertsCorrectly) { const auto graph = R"IR( graph(%0 : Tensor, - %1 : Float(4, 3, 4, 4), - %2 : Float(4)): + %1 : Float(4:48, 3:16, 4:4, 4:1), + %2 : Float(4:1)): %3 : int = prim::Constant[value=1]() %4 : int = prim::Constant[value=2]() %5 : int = prim::Constant[value=1]() diff --git a/tests/core/converters/test_linear.cpp b/tests/core/converters/test_linear.cpp index c668c03e63..6bbe7ef597 100644 --- a/tests/core/converters/test_linear.cpp +++ b/tests/core/converters/test_linear.cpp @@ -7,7 +7,7 @@ TEST(Converters, ATenLinearNoBiasConvertsCorrectly) { const auto graph = R"IR( graph(%0 : Tensor, - %1 : Float(3, 2)): + %1 : Float(3:2, 2:1)): %2 : None = prim::Constant() %3 : Tensor = aten::linear(%0, %1, %2) return (%3))IR"; @@ -34,8 +34,8 @@ TEST(Converters, ATenLinearNoBiasConvertsCorrectly) { TEST(Converters, ATenLinearBiasConvertsCorrectly) { const auto graph = R"IR( graph(%0 : Tensor, - %1 : Float(2, 3), - %2 : Float(2)): + %1 : Float(2:3, 3:1), + %2 : Float(2:1)): %3 : Tensor = aten::linear(%0, %1, %2) return (%3))IR"; diff --git a/tests/core/converters/test_shuffle.cpp b/tests/core/converters/test_shuffle.cpp index 59f1ef4d32..537e229b0b 100644 --- a/tests/core/converters/test_shuffle.cpp +++ b/tests/core/converters/test_shuffle.cpp @@ -108,18 +108,21 @@ TEST(Converters, ATenPermuteConvertsCorrectly) { return (%3))IR"; auto g = std::make_shared(); - torch::jit::parseIR(graph, &*g); + torch::jit::parseIR(graph, &*g); - auto in = at::randint(0, 5, {2, 3, 2, 3}, {at::kCUDA}); - auto params = trtorch::core::conversion::get_named_params(g->inputs(), {}); - auto jit_results = trtorch::tests::util::RunGraph(g, params, {in}); + auto in = at::randint(0, 5, {2, 3, 2, 3}, {at::kCUDA}); + auto params = trtorch::core::conversion::get_named_params(g->inputs(), {}); - in = at::clone(in); - params = trtorch::core::conversion::get_named_params(g->inputs(), {}); - auto trt_results = trtorch::tests::util::RunGraphEngine(g, params, {in}); - auto trt = trt_results[0].reshape_as(jit_results[0]); + std::cout << "Running JIT" << std::endl; + auto jit_results = trtorch::tests::util::RunGraph(g, params, {in}); - ASSERT_TRUE(trtorch::tests::util::almostEqual(jit_results[0], trt, 2e-6)); + std::cout << "Running TRT" << std::endl; + in = at::clone(in); + params = trtorch::core::conversion::get_named_params(g->inputs(), {}); + auto trt_results = trtorch::tests::util::RunGraphEngine(g, params, {in}); + auto trt = trt_results[0].reshape_as(jit_results[0]); + + ASSERT_TRUE(trtorch::tests::util::almostEqual(jit_results[0], trt, 2e-6)); } TEST(Converters, ATenPermute3DConvertsCorrectly) { diff --git a/tests/core/converters/test_stack.cpp b/tests/core/converters/test_stack.cpp index 38cefd2993..590369a3a5 100755 --- a/tests/core/converters/test_stack.cpp +++ b/tests/core/converters/test_stack.cpp @@ -31,7 +31,7 @@ TEST(Converters, ATenStackPureTensorConvertsCorrectly) { TEST(Converters, ATenStackDiffTensorConvertsCorrectly) { const auto graph = R"IR( graph(%0 : Tensor, - %1 : Float(4, 4, 4)): + %1 : Float(4:16, 4:4, 4:1)): %2 : Tensor[] = prim::ListConstruct(%0, %1) %3 : int = prim::Constant[value=1]() %4 : Tensor = aten::stack(%2, %3) diff --git a/tests/py/requirements.txt b/tests/py/requirements.txt index 26cd815aec..ac6580af90 100644 --- a/tests/py/requirements.txt +++ b/tests/py/requirements.txt @@ -1 +1 @@ -torchvision==0.6.0 \ No newline at end of file +torchvision==0.7.0 \ No newline at end of file diff --git a/tests/util/run_graph.cpp b/tests/util/run_graph.cpp index e749eb1e87..e8f041a673 100644 --- a/tests/util/run_graph.cpp +++ b/tests/util/run_graph.cpp @@ -5,7 +5,7 @@ namespace trtorch { namespace tests { namespace util { -torch::jit::Stack CreateStack(std::vector&& list) { +torch::jit::Stack CreateStack(std::vector&& list) { return torch::jit::Stack( std::make_move_iterator(list.begin()), std::make_move_iterator(list.end())); @@ -16,15 +16,15 @@ std::vector RunGraph(std::shared_ptr& g, core::conversion::GraphParams& params, std::vector inputs) { LOG_DEBUG("Running JIT version"); - std::vector inputs_; + std::vector inputs_; for (auto in : inputs) { - inputs_.push_back(in.clone()); + inputs_.push_back(torch::jit::IValue(in.clone())); } for (auto* in : g->inputs()) { const auto iter = params.find(in); if (iter != params.end()) { - inputs_.push_back(iter->second.clone()); + inputs_.push_back(iter->second); } } diff --git a/third_party/tensorrt/local/BUILD b/third_party/tensorrt/local/BUILD index 3a9b8b2710..dfbe5a3c4a 100644 --- a/third_party/tensorrt/local/BUILD +++ b/third_party/tensorrt/local/BUILD @@ -67,6 +67,11 @@ cc_import( ":windows": "lib/nvinfer.dll", "//conditions:default": "lib/x86_64-linux-gnu/libnvinfer.so", }), + static_library = select({ + ":aarch64_linux": "lib/aarch64-linux-gnu/libnvinfer_static.a", + ":windows": "lib/nvinfer.lib", + "//conditions:default": "lib/x86_64-linux-gnu/libnvinfer_static.a" + }), visibility = ["//visibility:private"], )