Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

BUG: WSGI incompatibility, destroying downstream A.I. web apps based on Torch, TensorFlow, Jax, ... #26039

Closed
legel opened this issue Mar 15, 2024 · 5 comments
Labels

Comments

@legel
Copy link

legel commented Mar 15, 2024

Describe the issue:

WSGI and NumPy are not friends. Someone who understands both libraries should consider helping out what is probably hundreds to thousands of A.I. developers who'd love to deploy a standard Apache server with standard A.I. tools...

Reproduce the code example:

sudo systemctl start apache2
# ...with a Flask/Python web app, that imports numpy / torch / tensorflow / jax / ...

Error message:

[Fri Mar 15 17:54:35.669711 2024] [wsgi:error] [pid 896464:tid 140159483893312] /var/www/ecodash/venv/lib/python3.10/site-packages/pandas/__init__.py:14: UserWarning: NumPy was imported from a Python sub-interpreter but NumPy does not properly support sub-interpreters. This will likely work for most users but might cause hard to track down issues or subtle bugs. A common user of the rare sub-interpreter feature is wsgi which also allows single-interpreter mode.


### Python and NumPy Versions:

Python 3.10.12
NumPy 1.26.4

### Runtime Environment:

Venv on a Linux Machine

### Context for the issue:

When running an Apache web server, system just completely fucks up loading NumPy -- as well as **all** NumPy-dependent numerical processing libraries including Torch, TensorFlow, and JAX.  

Basically everyone developing an A.I. web app is facing this "rare" issue.
@legel legel added the 00 - Bug label Mar 15, 2024
@ngoldbaum
Copy link
Member

dupe of #24755, the main reason this hasn’t been done is it’s an enormous amount of work (at a minimum, a large scale refactor of numpy’s C code from static python types to heap types).

@ngoldbaum ngoldbaum closed this as not planned Won't fix, can't repro, duplicate, stale Mar 16, 2024
@legel
Copy link
Author

legel commented Mar 17, 2024

Given that there is not sufficient interest and resources to resolve this “the right way”, how might you recommend one proceeds to be able to effectively incorporate NumPy et al. in a web serving environment based on Apache etc.?

I’m not looking for anything fancy or special, just the most sensible basic workaround. I ask because maybe this is more obvious to you and mentioning notes here could potentially help others.

A few starting thoughts / hypotheses:

  • Virtual environments such as conda or docker may be possible to create and isolate from web serving environment and make callable with minimal nonsense
  • In the most extreme scenario, I figured it could be possible to write some kind of a server API running outside of the /var/www/[website]/venv … (possibly in its own virtual env like conda or even on a different machine…) that can basically process NumPY computations for users running Apache WSGI web apps

“Simplicity is ultimate sophistication”, let me know if any ideas come to mind.

@rkern
Copy link
Member

rkern commented Mar 17, 2024

The standard solution is to use Gunicorn/Uvicorn just behind your Apache/nginx frontend to manage the numpy-using worker processes.

@legel
Copy link
Author

legel commented Mar 18, 2024

Thank you!

@legel
Copy link
Author

legel commented Apr 5, 2024

Finally implemented this change, happy to say "it works!".
As well, I think with Gunicorn it's faster too.
Thanks again.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants