diff --git a/bentoml/_internal/io_descriptors/numpy.py b/bentoml/_internal/io_descriptors/numpy.py index 151f1b53c5d..d860a6da376 100644 --- a/bentoml/_internal/io_descriptors/numpy.py +++ b/bentoml/_internal/io_descriptors/numpy.py @@ -223,7 +223,7 @@ def __init__( enforce_dtype: bool = False, shape: tuple[int, ...] | None = None, enforce_shape: bool = False, - packed: bool = True, + packed: bool = False, bytesorder: t.Literal["C", "F", "A", None] = None, ): if dtype is not None and not isinstance(dtype, np.dtype): @@ -441,6 +441,7 @@ async def to_grpc_response( Protobuf representation of given `np.ndarray` """ from ..utils.grpc import grpc_status_code + from ..configuration import get_debug_mode _NPTYPE_TO_DTYPE_STRING_MAP = { np.dtype(v): k for k, v in _DTYPE_TO_STRING_MAP.items() @@ -460,6 +461,10 @@ async def to_grpc_response( if self._packed: cnt.update({"bytes_contents": obj.tobytes(order=self._bytesorder)}) else: + if self._bytesorder: + logger.warning( + f"'bytesorder={self._bytesorder}' is ignored when 'packed={self._packed}'." + ) cnt.update({_DTYPE_TO_FIELD_MAP[dtype_string]: obj.tolist()}) if obj.ndim == 1: @@ -472,6 +477,8 @@ async def to_grpc_response( shape=tuple(obj.shape), array=service_pb2.Array(**cnt) ) ) + if get_debug_mode(): + logger.debug(f"Response proto: \n{resp}") return resp def generate_protobuf(self): diff --git a/bentoml/_internal/server/grpc/servicer.py b/bentoml/_internal/server/grpc/servicer.py index 5d0109333a7..5ff5977d760 100644 --- a/bentoml/_internal/server/grpc/servicer.py +++ b/bentoml/_internal/server/grpc/servicer.py @@ -3,6 +3,7 @@ import asyncio from typing import TYPE_CHECKING +import anyio from grpc import aio from bentoml.exceptions import UnprocessableEntity @@ -41,7 +42,7 @@ async def Infer( # type: ignore (no async types) if asyncio.iscoroutinefunction(api.func): output = await api.func(input) else: - output = api.func(input) + output = await anyio.to_thread.run_sync(api.func, input) return await api.output.to_grpc_response(output, context)