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

Add async support to Module class #1988

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

younes-io
Copy link

@younes-io younes-io commented Dec 25, 2024

This PR adds native async support to DSPy's Module class, making it easier to work with async operations. Instead of using asyncify, you can now write async modules naturally:

  • Added aforward method for async implementations
  • Detection of async arguments
  • Works with both sync and async code
  • Tested with different async patterns

Please, let me know your feedback on this initial async implementation..

Should fix #1975 (WIP)

@younes-io younes-io changed the title Add async support to Module class Add async support to Module class Dec 25, 2024
@okhat okhat requested a review from CyrusNuevoDia December 25, 2024 20:25
@okhat
Copy link
Collaborator

okhat commented Dec 25, 2024

Thanks a lot @younes-io ! Tagging @CyrusNuevoDia , the async expert here :D

@CyrusNuevoDia
Copy link
Collaborator

Thanks @younes-io this is great!

2 questions --

  1. Can this directly use an Async LM instead of a sync LM?
  2. Can you test this with the sync optimizers?

Comment on lines +66 to +70
for k, v in kwargs.items():
if is_async_arg(v):
async_kwargs[k] = await v
else:
async_kwargs[k] = v
Copy link
Collaborator

@CyrusNuevoDia CyrusNuevoDia Dec 25, 2024

Choose a reason for hiding this comment

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

Can you make this use gather so they resolve concurrently?

@younes-io
Copy link
Author

younes-io commented Dec 25, 2024

Thanks @younes-io this is great!

2 questions --

  1. Can this directly use an Async LM instead of a sync LM?
  2. Can you test this with the sync optimizers?

Thank you for looking into this..

The short answer would be:

1 - Not yet (working on it)
2 - Yes, it should work but I need to write tests for this

This commit is just the first step.. I'm trying to do this step by step and write tests to avoid regressions because it could get tricky

@itay1542 itay1542 mentioned this pull request Jan 1, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Better async support
3 participants