Skip to content

[Feature] Async Context Manager Support for Settings #8197

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

Open
1 of 2 tasks
jd02904 opened this issue May 8, 2025 · 4 comments
Open
1 of 2 tasks

[Feature] Async Context Manager Support for Settings #8197

jd02904 opened this issue May 8, 2025 · 4 comments
Labels
enhancement New feature or request

Comments

@jd02904
Copy link

jd02904 commented May 8, 2025

What feature would you like to see?

It would be great to have the ability to use asyncify within dspy.settings.context(lm=model) by implementing an asynchronous version of the context manager. Currently seeing race conditions using asyncify with this context manager.

Would you like to contribute?

  • Yes, I'd like to help implement this.
  • No, I just want to request it.

Additional Context

No response

@jd02904 jd02904 added the enhancement New feature or request label May 8, 2025
@chenmoneygithub
Copy link
Collaborator

@jd02904 Thank for reporting the issue! This shouldn't be the case, could you share a reproducible code? Thank you!

@jd02904
Copy link
Author

jd02904 commented May 9, 2025

@chenmoneygithub I checked the source code and it seems the way DSPy handles race conditions on settings is through thread_local_overrides but thread-local storage would only work for threads, not coroutines (asyncify). So it would make sense for there to be a potential for race conditions on settings if two different coroutines write to it. Let me know if I am missing something.

Let me try to build a minimal reproducible example but might be tricky because this only happens in production with a high number of parallel requests.

@chenmoneygithub
Copy link
Collaborator

For some context - asyncify builds on top of the fake streaming, which essentially uses multithreading. Our code could indeed cause an issue on native async, and I am working on the fixes. My question was to clarify which path you are using.

@okhat
Copy link
Collaborator

okhat commented May 14, 2025

FYI -- fix from Chen at #8203

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

No branches or pull requests

3 participants