Skip to content

Commit

Permalink
fix: repeated contents field
Browse files Browse the repository at this point in the history
Signed-off-by: Aaron Pham <29749331+aarnphm@users.noreply.github.com>
  • Loading branch information
aarnphm committed Jul 26, 2022
1 parent 7cba0ac commit 1971b1b
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 105 deletions.
12 changes: 8 additions & 4 deletions bentoml/_internal/io_descriptors/numpy.py
Expand Up @@ -264,12 +264,14 @@ async def from_grpc_request(
a `numpy.ndarray` object. This can then be used
inside users defined logics.
"""
from bentoml.grpc.v1 import struct_pb2

from ..utils.grpc import proto_to_dict

logger.info([f for f in struct_pb2.ContentsProto.DESCRIPTOR.fields])
# from bentoml.grpc.v1 import struct_pb2
# logger.info([f for f in struct_pb2.ContentsProto.DESCRIPTOR.fields])
print(request.contents)
contents = proto_to_dict(request.contents)
print(contents)
raise RuntimeError
return np.frombuffer(contents)

async def to_grpc_response(
Expand All @@ -285,7 +287,9 @@ async def to_grpc_response(
`io_descriptor_pb2.Array`:
Protobuf representation of given `np.ndarray`
"""
pass
from bentoml.grpc.v1 import service_pb2

return service_pb2.InferenceResponse()

def generate_protobuf(self):
pass
Expand Down
9 changes: 7 additions & 2 deletions bentoml/_internal/utils/grpc/serializer.py
Expand Up @@ -3,13 +3,18 @@
import typing as t
from typing import TYPE_CHECKING

from ...utils.lazy_loader import LazyLoader

if TYPE_CHECKING:
from google.protobuf.message import Message
from google.protobuf.json_format import MessageToDict
else:
MessageToDict = LazyLoader(
"MessageToDict", globals(), "google.protobuf.json_format.MessageToDict"
)


def proto_to_dict(msg: Message, **kwargs: t.Any) -> dict[str, t.Any]:
from google.protobuf.json_format import MessageToDict

if "preserving_proto_field_name" not in kwargs:
kwargs.setdefault("preserving_proto_field_name", True)

Expand Down
106 changes: 7 additions & 99 deletions bentoml/grpc/v1/service.proto
Expand Up @@ -48,56 +48,10 @@ message ServerReadyResponse {
// Request for Inference.
message InferenceRequest {
// a given API route the rpc request is sent to.
string api_name = 14;
string api_version = 15;
string api_name = 1;
string api_version = 2;

// representation of the input value.
oneof contents {
// Serialized bytes contents.
bytes bytes_contents = 1;

// DT_HALF, DT_BFLOAT16
int32 half_contents = 10;

// DT_FLOAT.
float float_contents = 2;

// DT_DOUBLE.
double double_contents = 3;

// DT_INT32, DT_INT16, DT_UINT16, DT_INT8, DT_UINT8.
int32 int_contents = 4;

// DT_STRING
bytes string_contents = 5;

// DT_COMPLEX64.
float scomplex_contents = 6;

// DT_INT64
int64 int64_contents = 7;

// DT_BOOL
bool bool_contents = 8;

// DT_COMPLEX128
double dcomplex_contents = 9;

// DT_UINT32
uint32 uint32_contents = 11;

// DT_UINT64
uint64 uint64_contents = 12;

// Represents arbitrary Python data structures.
NoneValue none_contents = 50;
ListValue list_contents = 51;
TupleValue tuple_contents = 52;
DictValue dict_contents = 53;
NamedTupleValue namedtuple_contents = 54;

google.protobuf.Any any_contents = 55;
}
repeated bentoml.grpc.v1.ContentsProto contents = 3;

// The data contained in an input can be represented in
// "raw" bytes form or in the repeated type that matches the
Expand All @@ -119,7 +73,7 @@ message InferenceRequest {
// specific data type for a 16-bit float type.
//
// If this field is specified then contents must not be specified for any input tensor.
repeated bytes raw_bytes_contents = 13;
repeated bytes raw_bytes_contents = 4;

// dataframes_columns and dataframe_indices are used
// in conjunction with contents to represent a dataframe.
Expand All @@ -132,53 +86,7 @@ message InferenceRequest {
// Response from Inference.
message InferenceResponse {
// representation of the output value.
// representation of the input value.
oneof contents {
// Serialized bytes contents.
bytes bytes_contents = 1;

// DT_HALF, DT_BFLOAT16
int32 half_contents = 10;

// DT_FLOAT.
float float_contents = 2;

// DT_DOUBLE.
double double_contents = 3;

// DT_INT32, DT_INT16, DT_UINT16, DT_INT8, DT_UINT8.
int32 int_contents = 4;

// DT_STRING
bytes string_contents = 5;

// DT_COMPLEX64.
float scomplex_contents = 6;

// DT_INT64
int64 int64_contents = 7;

// DT_BOOL
bool bool_contents = 8;

// DT_COMPLEX128
double dcomplex_contents = 9;

// DT_UINT32
uint32 uint32_contents = 11;

// DT_UINT64
uint64 uint64_contents = 12;

// Represents arbitrary Python data structures.
NoneValue none_contents = 50;
ListValue list_contents = 51;
TupleValue tuple_contents = 52;
DictValue dict_contents = 53;
NamedTupleValue namedtuple_contents = 54;

google.protobuf.Any any_contents = 55;
}
repeated bentoml.grpc.v1.ContentsProto contents = 1;

// The data contained in an output can be represented in
// "raw" bytes form or in the repeated type that matches the
Expand All @@ -200,10 +108,10 @@ message InferenceResponse {
// specific data type for a 16-bit float type.
//
// If this field is specified then contents must not be specified for any input tensor.
repeated bytes raw_bytes_contents = 13;
repeated bytes raw_bytes_contents = 2;

// Sends a rpc status back to the client.
google.rpc.Status status = 14;
google.rpc.Status status = 3;

// the response should also include an error message type
oneof errors {
Expand Down

0 comments on commit 1971b1b

Please sign in to comment.