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

Patch nest_asyncio in notebooks only #520

Merged
merged 1 commit into from
Jan 11, 2024

Conversation

dzhulgakov
Copy link
Contributor

The logic to call nest_asyncio was added in 587f9ac presumably to make notebook interactions easier.

However, it's a bad practice to unconditionally call global python patches from library code.

It caused some issues with vLLM integration and was patched in #481

We ran into different issues when using Outlines in our codebase. The unittests started hanging on shutdown because of stray asyncio threads.

I propose to make the patch happen only when running inside IPython. According to https://stackoverflow.com/questions/15411967/how-can-i-check-if-code-is-executed-in-the-ipython-notebook it's an ok detention method for notebooks. Other proposed methods are too narrow and e.g. don't capture Colab.

However, even better fix might be to remove this patch all together and instead include it explicitly in the notebooks of choice. @rlouf - do you have more context on what was the original issue?

@rlouf
Copy link
Member

rlouf commented Jan 10, 2024

Thank you for opening a PR! It was indeed to make interaction with notebooks easier.

What’s your use case?

outlines/base.py Outdated
"Couldn't patch nest_asyncio because it's not installed. Running in the notebook might be have issues"
)
except ValueError as e:
print("Could not apply nest_asyncio:", e)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When is ValueError raised?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It was there from #481 . Presumably some vllm integration but I didn't run into it myself

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can remove it

@dzhulgakov
Copy link
Contributor Author

What’s your use case?

We're trying to use Outlines in some proprietary codebase (thank you for building it!). In one of the tests just importing outlines caused the test to hang at shutdown. The symptom is that threading.py _shutdown tries to join some threads. And there's a bunch of asyncio threads stuck in the process. I didn't debug it further, but the test uses asyncio and multiprocessing so it's kind of involved. Commenting out nest_asyncio or applying this PR solves the issue.

Btw, I verified that builtins.__IPYTHON__ trick works correctly when importing in colab.

@rlouf
Copy link
Member

rlouf commented Jan 11, 2024

Thank you for contributing!

@rlouf rlouf merged commit 2767eff into outlines-dev:main Jan 11, 2024
5 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants