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.14k stars 791 forks source link

log: debloat warning from client #3276

Closed aarnphm closed 1 year ago

aarnphm commented 1 year ago

Feature request

It would be nice if warning from client should only printed once.

Right now if user have multiple JSON IO with multiple pydantic schema and they use bentoml.client.Client, the warning from from_spec will be printed multiple times.

BentoML does not support loading pydantic models from URLs; output wil
l be a normal dictionary.
BentoML does not support loading JSON encoders from URLs; output will 
be a normal dictionary.
BentoML does not support loading pydantic models from URLs; output wil
l be a normal dictionary.
BentoML does not support loading JSON encoders from URLs; output will 
be a normal dictionary.
BentoML does not support loading JSON encoders from URLs; output will 
be a normal dictionary.
BentoML does not support loading JSON encoders from URLs; output will 
be a normal dictionary.
BentoML does not support loading pydantic models from URLs; output wil
l be a normal dictionary.
BentoML does not support loading JSON encoders from URLs; output will 
be a normal dictionary.
BentoML does not support loading JSON encoders from URLs; output will 
be a normal dictionary.
BentoML does not support loading JSON encoders from URLs; output will 
be a normal dictionary.

Motivation

Reproducer:

from __future__ import annotations

from pydantic import BaseModel

import bentoml

class IrisFeatures(BaseModel):
    sepal_len: float
    sepal_width: float
    petal_len: float
    petal_width: float

class IrisClassificationRequest(BaseModel):
    request_id: str
    iris_features: IrisFeatures

ex_jio = bentoml.io.JSON.from_sample(
    IrisFeatures(sepal_len=1.0, sepal_width=2.0, petal_len=3.0, petal_width=4.0)
)

@svc.api(input=ex_jio, output=ex_jio)
async def pred_json(input_json: dict[str, Any]) -> dict[str, Any] | BaseModel:
    return input_json

@svc.api(
    input=bentoml.io.JSON.from_sample(
        IrisClassificationRequest(
            request_id="1",
            iris_features=IrisFeatures(
                sepal_len=1.0, sepal_width=2.0, petal_len=3.0, petal_width=4.0
            ),
        )
    ),
    output=bentoml.io.PandasDataFrame(),
)
def vclassify(input_data: IrisClassificationRequest) -> pd.DataFrame:
    print("request_id:", input_data.request_id)
    input_df = pd.DataFrame([input_data.iris_features.dict()])
    return input_df

@svc.api(
    input=bentoml.io.Multipart(
        original=bentoml.io.Text.from_sample("adsfasdf"),
        arr=bentoml.io.NumpyNdarray.from_sample([1]),
    ),
    output=bentoml.io.JSON.from_sample({"original": "adsfasdf", "img": "hello"}),
)
async def pred_multipart(original: str, arr: NDArray[np.float16]) -> dict[str, str]:
    return {"original": original, "img": str(arr.tobytes())}

Other

No response

sauyon commented 1 year ago

Closing this one, I don't think it's important. Maybe we can include the relevant API in the log message, but fundamentally there really are that many warnings.

tomukmatthews commented 11 months ago

I'm finding this is causing a lot of log bloating as well to be honest

parano commented 11 months ago

Hi @tomukmatthews - this issue will be addressed in an upcoming new version of the IO Descriptor and client library: https://github.com/bentoml/BentoML/pull/4240, where we introduced a standard schema to create a much better API client experience

tomukmatthews commented 11 months ago

Hi @tomukmatthews - this issue will be addressed in an upcoming new version of the IO Descriptor and client library: #4240, where we introduced a standard schema to create a much better API client experience

Thanks this looks great, looking forward to it! 👏