serving icon indicating copy to clipboard operation
serving copied to clipboard

How to add custom op in tensorflow serving ?

Open praveeny1986 opened this issue 8 years ago • 5 comments

Using tensorflow serving r1.6, I tried adding my custom op in tensorflow_serving/model_servers/BUILD here

SUPPORTED_TENSORFLOW_OPS = [
    "@org_tensorflow//tensorflow/contrib:contrib_kernels",
    "@org_tensorflow//tensorflow/contrib:contrib_ops_op_lib",
    "//tensorflow_serving/myop:myOp.so" #Added this line
]

And myOp/BUILD:

package(
    default_visibility = [
        "//tensorflow_serving:internal",
    ],
    features = ["-layering_check"],
)

cc_library(
    name = "myOp.so",
    visibility = ["//visibility:public"],
    srcs = [
            "myOp.cc",
            "myOp.h"
           ] ,
    copts = ["-std=c++11"],
    deps = ["@org_tensorflow//tensorflow/core:framework_headers_lib",
            "@org_tensorflow//tensorflow/core/util/ctc",
            "@org_tensorflow//third_party/eigen3",
    ],
)

But I get this error while launching tensorflow_model_server Loading servable: {name: myModel version: 1} failed: Not found: Op type not registered 'MyOp' in binary running on 43e23d7f1ad2. Make sure the Op and Kernel are registered in the binary running in this process.

myOp.cc has been implemented exactly like described in https://www.tensorflow.org/versions/r1.6/extend/adding_an_op with REGISTER_OP and REGISTER_KERNEL_BUILDER(Name("MyOp").Device(DEVICE_CPU), MyOpOp);

How can we add custom Op in tensorflow serving?

praveeny1986 avatar May 03 '18 04:05 praveeny1986

Be sure to specify alwayslink=1 in your myOp's cc_library rule. Otherwise the linker may be pruning it away.

chrisolston avatar May 03 '18 14:05 chrisolston

By adding alwayslink=1 , it worked !!

praveeny1986 avatar May 04 '18 14:05 praveeny1986

Should we need to build TFServing from scratch to load/add Custom Op? any alternate way possible?

sathyarr avatar Mar 18 '19 13:03 sathyarr

Should we need to build TFServing from scratch to load/add Custom Op? any alternate way possible?

Nope, it seems bazel will do the cache, so only build the Custom Op

andrew-sn avatar Apr 11 '19 07:04 andrew-sn

Should we need to build TFServing from scratch to load/add Custom Op? any alternate way possible?

Nope, it seems bazel will do the cache, so only build the Custom Op

Once TFServing is built from source, I could run tensorflow-serving with, bazel-bin/tensorflow_serving/model_servers/tensorflow_model_server

How could I use that custom built Tensorflow Serving in another PC?

sathyarr avatar Apr 12 '19 07:04 sathyarr