-
Notifications
You must be signed in to change notification settings - Fork 74k
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
Graph optimized using tf.contrib.tensorrt is not loadable with TF_GraphImportGraphDef #23853
Comments
Hello @yegord, Could you please link your application with trt_conversion.so and trt_engine_op_op_lib |
this is with respect to #23243 Where is the lib located, “trt_conversion.so” , can you please tell?
|
So there seem to be two issues here:
|
@asimshankar Excellent summary, thanks! @samikama So, I cherry-picked the patch enabling the shape function (4fbbeea). diff --git a/tensorflow/BUILD b/tensorflow/BUILD
index 9b62a50..254ad51 100644
--- a/tensorflow/BUILD
+++ b/tensorflow/BUILD
@@ -443,6 +443,9 @@ tf_cc_shared_object(
"//tensorflow/c:version_script.lds",
"//tensorflow/c/eager:c_api",
"//tensorflow/core:tensorflow",
+ "//tensorflow/contrib/tensorrt:trt_conversion",
+ "//tensorflow/contrib/tensorrt:trt_engine_op_op_lib",
+ "//tensorflow/contrib/tensorrt:trt_engine_op_kernel",
],
) (Somehow without As a result, I get the expected performance boost of around 10% against vanilla TensorFlow graph.
The application runs TF_SessionRun on the same session from two threads in parallel. |
@pooyadavoodi may have an idea for the crash problem. |
If you have a hypothesis — shoot, I will check it. |
@yegord I thought TF_SessionRun() is not thread-safe. |
Could you reduce |
@samikama : |
@yegord Could you provide a repro. We need to look into the kernel registration that you mentioned above. |
Does not look like an OOM, because reducing the input image size by a factor of many (6-fold or so) does not fix it.
Already there.
Reducing from I'll be back with a repro then. |
Please find the repro here: https://github.com/yegord/tf-trt-linking-and-data-race-example The error message that I personally observe is here: https://github.com/yegord/tf-trt-linking-and-data-race-example/blob/master/crash.txt Tensorflow version being used (v1.12 with two patches: uncomment the shape function and link tensorrt operation into libtensorflow.so): https://github.com/yegord/tensorflow/tree/issue-23853 TensorFlow is installed with The repro demonstrates two points. First, there must be a way to link for an external user to link against something from TensorFlow (without patching TensorFlow like I did) and be able to start using TensorRT operation. Second, parallel calls to TensorRT operations should not crash the process. |
As of the crash, it might happen because you seem call
And, as my coworker noticed, this is not thread-safe: https://docs.nvidia.com/deeplearning/sdk/tensorrt-best-practices/index.html#thread-safety |
@ yegord, |
I can reproduce the error and I added a mutex which did solve the problem. I'll make a fix soon. |
… of their operations are not thread safe. This fixed one of the issues mentioned in #23853 PiperOrigin-RevId: 228947504
… of their operations are not thread safe. This fixed one of the issues mentioned in tensorflow#23853 PiperOrigin-RevId: 228947504
1. the new calibration design. The current int8 calibration workflow depends on a global resouce manager singleton TRTResourceManager (in resources/trt_resource_manager.h). This has been: - violating the resource manager design: resource manager should be per-device - pollutes the BUILD dependencies, and makes the kernel implementation not able to be used in other language bindings (Issue #23853) 2. the custom backend offline mode, where we'll do the conversion during execution and provide an offline tool to get the serizlied engine PiperOrigin-RevId: 229654702
Apparently, there is also a data race leading to a crash during the parallel creation of multiple dynamic int8 engines. Could you have a look? The repro is here: https://github.com/yegord/tf-trt-linking-and-data-race-example/tree/crash-with-int8-engines The error message that I see: https://github.com/yegord/tf-trt-linking-and-data-race-example/blob/crash-with-int8-engines/crash.txt The TensorFlow version used is 1.12 with few patches from you: https://github.com/yegord/tensorflow/tree/issue-23853-2 Build instructions are as above: #23853 (comment) (I hope you do not mind that I pile up remotely related issues into a single ticket.) Thanks! |
Thanks for the repro @yegord, I'll try it and get back to you. |
…he trt grappler optimizer, op kernels, and ops. This library will be included in pip build, so users can use TF-TRT without building TF from source in C++. This solves an issue mention by #23853 (TF-TRT not loadable with TF_GraphImportGraphDef). PiperOrigin-RevId: 238140294
The original problem in this issue is fixed: if we install the latest nightly pip package, we should see the TF-TRT shared library in @yegord, to solve your linking problem, I have an example in https://github.com/aaroey/tensorflow/blob/issue_repros/test/fixed-issue23853/Makefile#L14. |
For the INT8 calibration problem, I believe it's fixed at HEAD. Here is a (fixed) repo for it: https://github.com/aaroey/tensorflow/blob/issue_repros/test/fixed-issue23853-int8/Makefile I'm closing this, feel free to let me know if there are any questions. Thanks. |
System information
Have I written custom code (as opposed to using a stock example script provided in TensorFlow): Yes.
OS Platform and Distribution (e.g., Linux Ubuntu 16.04): Linux Ubuntu 16.04
Mobile device (e.g. iPhone 8, Pixel 2, Samsung Galaxy) if the issue happens on mobile device:
TensorFlow installed from (source or binary): Source.
TensorFlow version (use command below): v1.12
Python version: 2.7.12
Bazel version (if compiling from source): 0.19.0
GCC/Compiler version (if compiling from source): 5.4.0
CUDA/cuDNN version: 9.0/7.0.5
GPU model and memory: 1080 Ti
Describe the current behavior
I optimize a TensorFlow graph with
, save the resulting graph, and try to load it in a C++ program using C API.
First, I call
and call
TF_GraphImportGraphDef
with the optimized graph.I get the following error:
Describe the expected behavior
The call to
TF_GraphImportGraphDef
must succeed.Code to reproduce the issue
It seems that the issue, although not in the bug tracker, should be already known to the authors: https://github.com/tensorflow/tensorflow/blob/v1.12.0/tensorflow/contrib/tensorrt/ops/trt_engine_op.cc#L46
However, I can make a minimal example to reproduce the problem on demand.
Other info / logs
It is a pain that a TRT-optimized graph cannot be used outside of python now.
I would be happy to know about a workaround, in case one exists.
The text was updated successfully, but these errors were encountered: