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

Decrease latency: do not run pre and postprocess in threadpool #7796

Merged
merged 4 commits into from
Mar 22, 2024

Conversation

freddyaboulton
Copy link
Collaborator

Description

In #7327, we run pre-post process in a separate threadpool to not block the event loop in the event a component has an expensive processing function. This introduces some latency for most demos so it's not worth it. We still process the gallery images in parallel so will prevent prevent the issue with galleries from #7327 from coming up again. In the attached gif, we process 30 images of 1.6 mb (left panel) and 1 mb (right panel) and the latency is minimal and the event loop is not blocked.

do_not_run_threadpool

🎯 PRs Should Target Issues

Before your create a PR, please check to see if there is an existing issue for this change. If not, please create an issue before you create this PR, unless the fix is very small.

Not adhering to this guideline will result in the PR being closed.

Tests

  1. PRs will only be merged if tests pass on CI. To run the tests locally, please set up your Gradio environment locally and run the tests: bash scripts/run_all_tests.sh

  2. You may need to run the linters: bash scripts/format_backend.sh and bash scripts/format_frontend.sh

@freddyaboulton freddyaboulton added the v: patch A change that requires a patch release label Mar 22, 2024
@gradio-pr-bot
Copy link
Collaborator

gradio-pr-bot commented Mar 22, 2024

🪼 branch checks and previews

Name Status URL
Spaces ready! Spaces preview
Website ready! Website preview
🦄 Changes detected! Details

Install Gradio from this PR

pip install https://gradio-builds.s3.amazonaws.com/df11e7333b404489399cfc36a0a3903b3163df2b/gradio-4.22.0-py3-none-any.whl

Install Gradio Python Client from this PR

pip install "gradio-client @ git+https://github.com/gradio-app/gradio@df11e7333b404489399cfc36a0a3903b3163df2b#subdirectory=client/python"

@gradio-pr-bot
Copy link
Collaborator

gradio-pr-bot commented Mar 22, 2024

🦄 change detected

This Pull Request includes changes to the following packages.

Package Version
gradio patch
  • Maintainers can select this checkbox to manually select packages to update.

With the following changelog entry.

Decrease latency: do not run pre and postprocess in threadpool

Maintainers or the PR author can modify the PR title to modify this entry.

Something isn't right?

  • Maintainers can change the version label to modify the version bump.
  • If the bot has failed to detect any changes, or if this pull request needs to update multiple packages to different versions or requires a more comprehensive changelog entry, maintainers can update the changelog file directly.

@abidlabs
Copy link
Member

So just to understand, we still postprocess gallery images in separate parallel threads due to this change in #7327 :

image

However, the general case, we do not run self.postprocess() in a separate threadpool?

I tested this out with images of different sizes and didn't notice a significant difference compared to main using the original repro with the gallery images. So this should be good!

@freddyaboulton
Copy link
Collaborator Author

However, the general case, we do not run self.postprocess() in a separate threadpool?

Yes!

@freddyaboulton
Copy link
Collaborator Author

Thanks for the review @abidlabs !

@freddyaboulton freddyaboulton merged commit aad209f into main Mar 22, 2024
7 checks passed
@freddyaboulton freddyaboulton deleted the do-not-run-pre-post-process-threadpool branch March 22, 2024 19:38
@pngwn pngwn mentioned this pull request Mar 22, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
v: patch A change that requires a patch release
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants