bentoml / BentoML

The easiest way to serve AI apps and models - Build Model Inference APIs, Job queues, LLM apps, Multi-model pipelines, and more!
https://bentoml.com
Apache License 2.0
7.13k stars 791 forks source link

feature(grpc): protobuf backward compatibility layer #3039

Closed aarnphm closed 1 year ago

aarnphm commented 2 years ago

Feature request

protobuf > 4 introduces a lot of breaking changes, therefore to ease the transition, I propose to have two sets of generated service stubs.

We lazy load all of our stubs imports via import_generated_stubs. I believe we can do one more step here:

If protobuf >4, it should be able to use the newly generated stubs structure. Otherwise, it will, by default, use the stubs generated with protobuf<4

pb, services = import_generated_stubs()

One drawback is that users will still run into issues with protobuf error if some of the library other than bentoml still uses older generated stubs.

Motivation

No response

Other

No response

Srivathsan-V commented 2 years ago

Hi! Iam a newcomer to open source and would like to contribute on this issue. Could you please give me some insights into it?

aarnphm commented 2 years ago

Hi @Srivathsan-V, So recently protobuf>4 is a major release, which breaks all of the generated code for cases where library uses protobuf<4 (protobuf>=3.19).

Currently, BentoML generates proto stubs for our gRPC components using protobuf==3.19.6. This is fine since the majority of the library out there that uses protobuf will still be on protobuf 3 for the time being.

With that being said, if users are using protobuf >4, they wouldn't able to use gRPC features from BentoML.

So the idea here is to generate two sets of protofiles, one using protobuf==3.19.4, and the other using protobuf>4. BentoML can provide a compact layer that check for current protobuf version

from bentoml._internal.utils.pkg import get_pkg_version

if get_pkg_version("protobuf")[0] < 4:
    # import generated stubs for protobuf==3.19.6 here
else:
    # import generated stubs from protobuf>4 here

This is where we are currently handle the generated stubs. So the check would be from here.

Another good thing to note is that the generated stubs are currently under bentoml/grpc/v1alpha1/service_pb2.py If we introduce this compact layer, we might have to change our folder structure. But I'm open for suggestion on this as well.

If anything isn't clear, please let me know.