serving icon indicating copy to clipboard operation
serving copied to clipboard

Unable to compile Protobuf for Golang

Open 1dustycy opened this issue 5 years ago • 13 comments

OS Platform: MacOS 10.14.5 On TF-Serving r1.14

I've checked other closed issues regarding this topic but still not able to find a clear solution.

I tried: protoc -I ./ -I ../tensorflow/ \ betterchen@Yangs-MacBook-Pro --go_out=plugins=grpc:$GOPATH/src/github.com/lejiskin/tf_server_be/protos \ tensorflow_serving/apis/prediction_service.proto

The generated pb makes import cycle error and is not useful at all.

Please clarify this issue.

It's better to create an official document of "How to build a Golang gRPC client for TF-Serving"

Thanks

1dustycy avatar May 30 '19 06:05 1dustycy

@betterchen Its a duplicate of issue #634. But thank you for opening this thread as the issue has not been resolved. Will take a look at the issue.

gowthamkpr avatar May 30 '19 17:05 gowthamkpr

@betterchen we're looking into seeing why we don't run into this problem internally and what the fix would look like. Thank you for reporting this.

peddybeats avatar Jun 13 '19 17:06 peddybeats

Cheers @unclepeddy

1dustycy avatar Jun 24 '19 09:06 1dustycy

I believe using protoc orthogonal to bazel is not the correct way of going about this - the correct way would be to add a go_proto_library for every serving_proto_libraryand let bazel compile golibs during build.

Something like

serving_proto_library(
    name = "model_proto",
    srcs = ["model.proto"],
    cc_api_version = 2,
    deps = [
        "@protobuf_archive//:cc_wkt_protos",
    ],
)

go_proto_library(
    name = "model_go_proto",
    importpath = "github.com/tensorflow/tensorflow_serving/apis:model_proto",
    proto = ":model_proto",
    deps = [
        "@protobuf_archive//:cc_wkt_protos", ## Needs to be the golib version of this proto
    ],
)

Which runs into 2 issues that I haven't been able to resolve:

  • Currently, proto_library rules don't build ProtoInfo objects, which is needed by go_proto_library (even though it's not documented?)
  • What if the dependent protos don't export golibs?

peddybeats avatar Aug 15 '19 17:08 peddybeats

Hello!

Is there any workaround for this issue or we have to wait for a bugfix?

Thanks.

jplu avatar Aug 19 '19 14:08 jplu

I wrote a script to generate TF Serving gRPC interfaces for Go, but it would be nice if we could run protoc directly without jumping through these hoops.

mxk avatar Aug 27 '19 15:08 mxk

Changing this to FR - TF Serving needs to expose the appropriate build target for Golang.

christisg avatar Sep 10 '19 17:09 christisg

@mxk do you have one for TensorFlow 2? I can compile for TensorFlow 1 fine

jose-airspace avatar Jan 03 '20 20:01 jose-airspace

@jose-airspace No, I haven't tried doing anything with TensorFlow 2 yet.

mxk avatar Jan 03 '20 21:01 mxk

If anyone else runs into this issue, I found what seems to be a simple workaround (specifically on r1.15 branch)

The issue is that tensorflow_serving/apis/prediction_log.proto needs a LogMetadata from tensorflow_serving/core/logging.proto, which itself needs a ModelSpec from tensorflow_serving/apis/model.proto. The dependency from tensorflow_serving/apis -> tensorflow_serving/core -> tensorflow_serving/apis makes Go fail.

I did a grep -r "logging.proto" to verify that it only gets imported by apis/prediction_log.proto. This meant I could just move logging.proto from the core/ directory into the apis/ directory and change the import in prediction_log.proto to import it from the new location (i.e. import "tensorflow_serving/apis/logging.proto";)

Not sure what effects this might have on any of the actual TFS code, but it seems to be fine if all you want to do is have access to the TFS protos from within GoLang

blepfo avatar Jul 09 '20 00:07 blepfo

@blepfo Do you have a repo you can share on how you got tensorflow serving working with golang grpc client?

mgyong avatar Jul 12 '20 01:07 mgyong

Has anybody got a recent version working with grpc and golang? None of the workarounds here seem to work anymore.

Also, its been nearly 3 years and this issue is still open :flushed:

grantstephens avatar Dec 07 '21 11:12 grantstephens

@grantstephens

Hi, I stored required protobuf files and scripts to get proto files for TF-Serving 2.7 APIs in this repository. And I wrote a sample client code with golang for TensorFlow Serving 2.7 in this link. I hope these repositories can help you.

jeongukjae avatar Dec 29 '21 08:12 jeongukjae

@grantstephens

Hi, I stored required protobuf files and scripts to get proto files for TF-Serving 2.7 APIs in this repository. And I wrote a sample client code with golang for TensorFlow Serving 2.7 in this link. I hope these repositories can help you.

Hello, I've been following your article but I haven't managed to compile tensorflow_serving for version 2.8.2 as you didn't explain how to use babel to properly compile them. Could you explain how you managed to do this?

RegaliaXYZ avatar Mar 17 '23 09:03 RegaliaXYZ

@1dustycy,

You can find community build Golang packages for TF Serving Client here and here as mentioned in above comment.

Please let us know if this issue can be closed. Thank you!

singhniraj08 avatar May 18 '23 08:05 singhniraj08

@1dustycy,

You can find community build Golang packages for TF Serving Client here and here as mentioned in above comment.

Please let us know if this issue can be closed. Thank you!

I haven't tried to build the client for a while. But I think this issue has kept opening long enough and the quoted reply seems resolved the problem. I'm closing this. Thanks everyone.

1dustycy avatar May 18 '23 09:05 1dustycy