BentoML icon indicating copy to clipboard operation
BentoML copied to clipboard

bug: incorrectly rounded float output

Open KimToehler opened this issue 8 months ago • 1 comments

Describe the bug

When I retrieve a float number as output, it appears to be inaccurately rounded.

@svc.api(input=NumpyNdarray(), output=NumpyNdarray(dtype=np.float32))
async def predict(arr: np.ndarray) -> float:
    return np.round(25.1234, 2)

The response is:

  25.1200008392334

I haven't had the opportunity to review the code and identify the specific issue yet. I will provide an update to this ticket as soon as I can isolate the error.

To reproduce

Steps to reproduce the bug:

  1. build a bento with:
@svc.api(input=NumpyNdarray(), output=NumpyNdarray(dtype=np.float32))
async def predict(arr: np.ndarray) -> float:
    return np.round(25.1234, 2)
  1. serve it
  2. curl -X POST http://0.0.0.0:3000/predict -d '[0]'

Expected behavior

Get 25.12 returned

Environment

python: 3.11 bentoml: 1.1.9

KimToehler avatar Nov 17 '23 16:11 KimToehler