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

bug: Example of Diffusers not working properly #4029

Closed Rustin170506 closed 1 year ago

Rustin170506 commented 1 year ago

Describe the bug

I followed this document to try the bentoml. But I got an error when I requesting the API.

2023-07-09T12:50:52+0800 [ERROR] [api_server:stable-diffusion-21:7] Exception on /txt2img [POST] (trace=9ce85de98d9f14dc6460de87d68bb264,span=d3be66fffcf39617,sampled=0,service.name=stable-diffusion-21)
Traceback (most recent call last):
  File "/opt/homebrew/lib/python3.11/site-packages/bentoml/_internal/server/http_app.py", line 341, in api_func
    output = await api.func(*args)
             ^^^^^^^^^^^^^^^^^^^^^
  File "/Volumes/t7/code/bentoml/service.py", line 11, in txt2img
    kwargs = input_data.dict()
             ^^^^^^^^^^^^^^^
AttributeError: 'dict' object has no attribute 'dict'
```requested

### To reproduce

1. Install bentoml: `pip install bentoml`
2. Create the import_model.py
```python
import bentoml

bentoml.diffusers.import_model(
    "sd2.1",  # model tag in BentoML model store
    "stabilityai/stable-diffusion-2-1",  # huggingface model name
)
  1. Run pip3 install --upgrade diffusers transformers accelerate and python import_model.py
  2. Create the service.py
    
    import bentoml
    from bentoml.io import Image, JSON

bento_model = bentoml.diffusers.get("sd2.1:latest") sd21_runner = bento_model.to_runner(name="sd21-runner")

svc = bentoml.Service("stable-diffusion-21", runners=[sd21_runner])

@svc.api(input=JSON(), output=Image()) async def txt2img(input_data): kwargs = input_data.dict() res = await sd21_runner.async_run(**kwargs) images = res[0] return images[0]

5. Start the server: `bentoml serve service.py:svc`
6. Try it in Swagger UI with input:
```json
{
    "prompt": "A gopher"
}

Expected behavior

The server can handle this request and start creating the image with the prompt.

But I got an error:

2023-07-09T12:50:52+0800 [ERROR] [api_server:stable-diffusion-21:7] Exception on /txt2img [POST] (trace=9ce85de98d9f14dc6460de87d68bb264,span=d3be66fffcf39617,sampled=0,service.name=stable-diffusion-21)
Traceback (most recent call last):
  File "/opt/homebrew/lib/python3.11/site-packages/bentoml/_internal/server/http_app.py", line 341, in api_func
    output = await api.func(*args)
             ^^^^^^^^^^^^^^^^^^^^^
  File "/Volumes/t7/code/bentoml/service.py", line 11, in txt2img
    kwargs = input_data.dict()
             ^^^^^^^^^^^^^^^
AttributeError: 'dict' object has no attribute 'dict'

I also tried it with post man and it still is not work.

Environment

bentoml:

➜  bentoml bentoml -v
bentoml, version 1.0.23

python:

➜  bentoml python3 -V
Python 3.11.4

OS:

OS: macOS 13.4 22F66 arm64
Host: Mac14,3 
Kernel: 22.5.0
CPU: Apple M2 
GPU: Apple M2
Rustin170506 commented 1 year ago

Filed a pull request for it: https://github.com/bentoml/BentoML/pull/4030

I am not sure if am I on track, please let me know if you have any suggestions or ideas about it.