tensorflow: Bug: Op type not registered 'BlockLSTM' in binary

Describe the problem

I want to load and run a single tensorflow model within another C++ project. To do this, I defined the tensorflow_all library in tensorflow/BUILD which should include all the necessary dependencies. (Details below)

When loading the tensorflow model via the C++ API (LoadSavedModel), the following runtime error occurs:

2017-07-28 13:36:41.875493: I tensorflow/cc/saved_model/loader.cc:284] Loading SavedModel: fail. Took 43550 microseconds.
terminate called after throwing an instance of 'std::runtime_error'
  what():  Not found: Op type not registered 'BlockLSTM' in binary running on myMachine. 
  Make sure the Op and Kernel are registered in the binary running in this process.

I found that the BlockLSTM Op is registered in tensorflow/contrib/rnn/ops/lstm_ops.cc. However, I could not find a way to include the operation BlockLSTM in my C++ library tensorflow_all.

Bear with me if this is actually not a bug (or even a feature request). I am still getting started with tensorflow.

Since my implementation is part of another larger project, it is currently difficult for me to give an easy to reproduce example. However, if this is necessary, I will do it as soon as I find the time.

System information

  • Have I written custom code (as opposed to using a stock example script provided in TensorFlow):

    Yes, a colleague of mine trained a tensorflow graph which uses the BlockLSTM Op from tensorflow/contrib/rnn/ using the python API.

    As mentioned before, I added code to the tensorflow/BUILD to create a library tensorflow_all. This library is used to load the graph externally.

    cc_binary(
    	name = "libtensorflow_all.so",
    	linkshared = 1,
    	linkopts = ["-Wl,--version-script=tensorflow/tf_version_script.lds"],
    	deps = [
    		"//tensorflow/cc:cc_ops",
    		"//tensorflow/cc:client_session",
    		"//tensorflow/cc/saved_model:loader",
    		"//tensorflow/cc/saved_model:tag_constants",
    		"//tensorflow/core:all_kernels",
    		"//tensorflow/core:framework_internal",
    		"//tensorflow/core:tensorflow",
    		"//tensorflow/contrib:contrib_kernels",
    		"//tensorflow/contrib:contrib_ops_op_lib",
    	],
    )
    

    I was hoping that BlockLSTM was included in "//tensorflow/contrib:contrib_ops_op_lib", but that appears not to be the case.

  • OS Platform and Distribution (e.g., Linux Ubuntu 16.04): Ubuntu 16.04.2 LTS

  • TensorFlow installed from (source or binary): source

  • TensorFlow version: Master branch (commit bb88ec7ecc4dc7ba72548a5115fb86e20b14de5b)

  • Python version: 3.5

  • Bazel version (if compiling from source): 0.4.5

  • CUDA/cuDNN version: 5.1

  • GPU model and memory: GeForce GTX 980, 4GB

  • Exact command to reproduce: Sorry. Not that easy to reproduce.

About this issue

  • Original URL
  • State: closed
  • Created 7 years ago
  • Comments: 19 (13 by maintainers)

Most upvoted comments

It works for me with the following changes (also for gru_ops_kernels).

--- a/tensorflow/contrib/rnn/BUILD
+++ b/tensorflow/contrib/rnn/BUILD
@@ -326,6 +326,8 @@ tf_kernel_library(
     srcs = [
         "kernels/blas_gemm.cc",
         "kernels/blas_gemm.h",
+        "kernels/gru_ops.h",
+        "ops/gru_ops.cc",
     ],
     gpu_srcs = [
         "kernels/blas_gemm.h",
@@ -344,6 +346,8 @@ tf_kernel_library(
     srcs = [
         "kernels/blas_gemm.cc",
         "kernels/blas_gemm.h",
+        "kernels/lstm_ops.h",
+        "ops/lstm_ops.cc",
     ],
     gpu_srcs = [
         "kernels/blas_gemm.h",

And adding "//tensorflow/contrib/rnn:gru_ops_kernels" and/or "//tensorflow/contrib/rnn:lstm_ops_kernels" to the deps of the respective binary.

(using r1.3)

@dkurt You could try adding

from tensorflow.contrib.rnn import *

to freeze_graph.py.

@pks hi, I used your method to add operation “BlockLSTM” and compile successfully, but loading the model in c++ doesn’t seem to work, have you ever been in this situation? Look forward to your reply!