From c409cd5c730ef320b00fbef249fcc168f2d3e51d Mon Sep 17 00:00:00 2001 From: Charles Bensimon Date: Mon, 17 Jul 2023 18:57:14 +0200 Subject: [PATCH] Queue `max_size` defaults to Block's `max_threads` on ZeroGPU Spaces (#4937) * Queue max_size defaults to Block's max_threads on ZeroGPU Spaces * More readable ? * CHANGELOG --- CHANGELOG.md | 1 + gradio/blocks.py | 3 ++- gradio/utils.py | 4 ++++ 3 files changed, 7 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index c82cb3e5bba6..40e553360918 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -33,6 +33,7 @@ demo.launch() - Warning on mobile that if a user leaves the tab, websocket connection may break. On broken connection, tries to rejoin queue and displays error conveying connection broke. By [@aliabid94](https://github.com/aliabid94) in [PR 4742](https://github.com/gradio-app/gradio/pull/4742) - Remove blocking network calls made before the local URL gets printed - these slow down the display of the local URL, especially when no internet is available. [@aliabid94](https://github.com/aliabid94) in [PR 4905](https://github.com/gradio-app/gradio/pull/4905). - Pinned dependencies to major versions to reduce the likelihood of a broken `gradio` due to changes in downstream dependencies by [@abidlabs](https://github.com/abidlabs) in [PR 4885](https://github.com/gradio-app/gradio/pull/4885) +- Queue `max_size` defaults to parent Blocks `max_thread` when running on Spaces with ZeroGPU hardware. By [@cbensimon](https://github.com/cbensimon) in [PR 4937](https://github.com/gradio-app/gradio/pull/4937) ## Breaking Changes: diff --git a/gradio/blocks.py b/gradio/blocks.py index bfb2a8b875ac..cbf5547c697d 100644 --- a/gradio/blocks.py +++ b/gradio/blocks.py @@ -1619,11 +1619,12 @@ def queue( warn_deprecation( "The client_position_to_load_data parameter is deprecated." ) + max_size_default = self.max_threads if utils.is_zero_gpu_space() else None self._queue = queueing.Queue( live_updates=status_update_rate == "auto", concurrency_count=concurrency_count, update_intervals=status_update_rate if status_update_rate != "auto" else 1, - max_size=max_size, + max_size=max_size_default if max_size is None else max_size, blocks_dependencies=self.dependencies, ) self.config = self.get_config_file() diff --git a/gradio/utils.py b/gradio/utils.py index d2a6d95d585b..8a3005a47bfb 100644 --- a/gradio/utils.py +++ b/gradio/utils.py @@ -113,6 +113,10 @@ def get_space() -> str | None: return None +def is_zero_gpu_space() -> bool: + return os.getenv("SPACES_ZERO_GPU") == "true" + + def readme_to_html(article: str) -> str: try: response = requests.get(article, timeout=3)