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

[Feature Request] Support max concurrent workflow_instance.run() executions. #16215

Merged
merged 3 commits into from
Sep 25, 2024

Conversation

nerdai
Copy link
Contributor

@nerdai nerdai commented Sep 25, 2024

Description

Currently, a Workflow.run() call starts the contained _run_workflow() coro. As such, we can't use llama_index.core.async_utils in order to control the number of workflow_instance.run() calls to be made simultaneously.
You would need to do this for example if your Workflow makes an api call and has chance of getting rate limit errors.

Proposed design:

w = Workflow(num_concurrent_runs=5)

tasks = []
for _ in range(1000):
  tasks.append(w.run())
  
results = asyncio.gather(*tasks)

This PR makes use of asyncio.Semaphore to limit the number of workflow instance runs occurring simultaneously.

Type of Change

Please delete options that are not relevant.

  • New feature (non-breaking change which adds functionality)

How Has This Been Tested?

Please describe the tests that you ran to verify your changes. Provide instructions so we can reproduce. Please also list any relevant details for your test configuration

  • Added new unit/integration tests
  • I stared at the code and made sure it makes sense

@nerdai nerdai linked an issue Sep 25, 2024 that may be closed by this pull request
@dosubot dosubot bot added the size:M This PR changes 30-99 lines, ignoring generated files. label Sep 25, 2024
Copy link
Collaborator

@logan-markewich logan-markewich left a comment

Choose a reason for hiding this comment

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

Neat! This looks good to me

Can we add this to the docs in module_guides/worklows/index.md ?

@dosubot dosubot bot added the lgtm This PR has been approved by a maintainer label Sep 25, 2024
@nerdai nerdai force-pushed the nerdai/support-concurrent-workflow-runs branch from 1fbdcb5 to e01f639 Compare September 25, 2024 23:15
@nerdai nerdai enabled auto-merge (squash) September 25, 2024 23:18
@nerdai nerdai merged commit 8235129 into main Sep 25, 2024
10 checks passed
@nerdai nerdai deleted the nerdai/support-concurrent-workflow-runs branch September 25, 2024 23:21
raspawar pushed a commit to raspawar/llama_index that referenced this pull request Oct 7, 2024
…ecutions. (run-llama#16215)

* passing test

* add test for unbounded workflow

* dont await semaphore release
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
lgtm This PR has been approved by a maintainer size:M This PR changes 30-99 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Feature Request] Support concurrent Workflow .run()'s
2 participants