iterative / mlem

🐶 A tool to package, serve, and deploy any ML model on any platform. Archived to be resurrected one day🤞
https://mlem.ai
Apache License 2.0
716 stars 44 forks source link

Error not shown when request via streamlit fails #523

Open aguschin opened 1 year ago

aguschin commented 1 year ago
    When request via streamlit fails, it prints something like
HTTPError: 500 Server Error: Internal Server Error for url: http://0.0.0.0:8080/predict
Traceback:
File "/Users/aguschin/.local/share/virtualenvs/mlem-Utz6DvOn/lib/python3.9/site-packages/streamlit/runtime/scriptrunner/script_runner.py", line 564, in _run_script
    exec(code, module.__dict__)
File "/private/var/folders/tv/l60j0x050p536g3bh8g2w1n80000gn/T/mlem_streamlit_script_v6wsv2qt/script.py", line 64, in <module>
    response = getattr(client, method_name)(
File "/Users/aguschin/Git/iterative/mlem/mlem/runtime/client.py", line 153, in __call__
    out = self.call_method(self.name, data, return_raw)
File "/Users/aguschin/Git/iterative/mlem/mlem/runtime/client.py", line 201, in _call_method
    ret.raise_for_status()
File "/Users/aguschin/.local/share/virtualenvs/mlem-Utz6DvOn/lib/python3.9/site-packages/requests/models.py", line 1021, in raise_for_status
    raise HTTPError(http_error_msg, response=self)

but underneath, FastAPI fails with a different error. This is strange, maybe we eventually will need to either redirect failures, or use MLEM model directly instead of forwarding this to FastAPI, which seems more reasonable to me. For now should work though :)

Originally posted by @aguschin in https://github.com/iterative/mlem/issues/512#issuecomment-1344452928

aguschin commented 1 year ago

Hit this again with CV blog post. It happened that for some png images the service https://mlem-cv.fly.dev worked. Turned out the problem is with the image shapes. Png images that have 0 shape of 4, fails to be processed by the model. E.g.

image

Unfortunately, the real error can be only found out when you use FastAPI or inspect model manually:

image
mike0sv commented 1 year ago

We can add an optional shape field to TorchImageSerializer and use it. Or maybe more specific drop_alpha boolean flag?

mike0sv commented 1 year ago

It's a separate issue though, nothing to do with streamlit or fastapi