Skip to content

ZeroGPU native support - #13316

Draft
cbensimon wants to merge 34 commits into
mainfrom
queue-multiprocess
Draft

ZeroGPU native support#13316
cbensimon wants to merge 34 commits into
mainfrom
queue-multiprocess

Conversation

@cbensimon

@cbensimon cbensimon commented Apr 22, 2026

Copy link
Copy Markdown
Collaborator

Note

Medium Risk
Touches core request execution/queueing paths (context propagation, multiprocessing-safe progress/log emission) and adds a new middleware integration path, which could affect event handling and streaming behavior on Spaces.

Overview
Adds native Hugging Face Spaces ZeroGPU support via a new gradio/zerogpu.py that conditionally installs spaces.zero.ZeroGPUMiddleware, including custom exception mapping, log emission, disconnect detection, and worker contextualization.

Refactors queued execution to capture and propagate contextvars from /queue/join through route_utils.call_process_api and Blocks.process_api/call_function, covering sync/async and generator functions (including SyncToAsyncIterator), and adds queue-side RPC plumbing for progress/log messages when events run in child processes.

Removes the previous spaces.gradio_auto_wrap behavior, tweaks ZeroGPU detection (SPACES_ZERO_GPU accepts "1"), makes server start timeout configurable via GRADIO_START_TIMEOUT, updates test deps to include spaces, and adds tests ensuring request context propagation and cancellation behavior.

Reviewed by Cursor Bugbot for commit 76cc566. Bugbot is set up for automated code reviews on this repo. Configure here.

@gradio-pr-bot

gradio-pr-bot commented Apr 22, 2026

Copy link
Copy Markdown
Collaborator

🪼 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://huggingface.co/buckets/gradio/pypi-previews/resolve/7dfee1b9bed972badc5abd3b6466849d9b9e1f1e/gradio-6.18.0-py3-none-any.whl

Install Gradio Python Client from this PR

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

Import Gradio JS Client from this PR via CDN

import { Client } from "https://huggingface.co/buckets/gradio/npm-previews/resolve/7dfee1b9bed972badc5abd3b6466849d9b9e1f1e/browser.js";

@gradio-pr-bot

gradio-pr-bot commented Apr 22, 2026

Copy link
Copy Markdown
Collaborator

🦄 change detected

This Pull Request includes changes to the following packages.

Package Version
gradio minor

  • ZeroGPU native support

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.

@freddyaboulton

Copy link
Copy Markdown
Contributor

This approach looks good to me @cbensimon

@cbensimon

Copy link
Copy Markdown
Collaborator Author

This approach looks good to me @cbensimon

For context I am working on sibling PR:

I'll add the ZeroGPUMiddleware registration part once ready on spaces side

PS: spaces will still contain a gradio "compat mode" that registers the middleware + patches Gradio queue for older Gradio versions

Keeping you updated!

@cbensimon cbensimon changed the title feat(queue): multiprocessing support ZeroGPU native support May 4, 2026
@cbensimon
cbensimon marked this pull request as ready for review May 4, 2026 16:12
Comment thread gradio/queueing.py
Comment thread gradio/context.py
Comment thread gradio/queueing.py Outdated
@cbensimon
cbensimon requested a review from freddyaboulton May 4, 2026 17:39

@freddyaboulton freddyaboulton left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Code looks good @cbensimon ! Tried to test myself with spaces 0.50.0 dev version but the spaces image is hardcoding version 0.48

Comment thread scripts/create_test_requirements.sh Outdated
Comment thread gradio/context.py
Comment thread gradio/utils.py Outdated
Comment thread gradio/blocks.py Outdated
Comment thread gradio/queueing.py
Comment thread gradio/routes.py Outdated
Comment thread gradio/context.py
Comment thread gradio/blocks.py Outdated
Comment thread gradio/blocks.py Outdated
Comment thread gradio/blocks.py

@cursor cursor Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Cursor Bugbot has reviewed your changes and found 1 potential issue.

Fix All in Cursor

❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.

Reviewed by Cursor Bugbot for commit 43dde93. Configure here.

Comment thread gradio/blocks.py
@cbensimon
cbensimon marked this pull request as draft May 20, 2026 10:10
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.

3 participants