Repository navigation
Studio: queued image generations wait on their own pool, not the default executor - #17108
Merged
Merged
Conversation
…ult executor A generation request runs backend.generate in a worker thread that then waits for the engine's one-render slot. On the default executor, a few queued renders held every worker, so image status, gallery and chat streaming calls queued behind the active render. Run the three image generate dispatches on a dedicated pool with the same context copy as asyncio.to_thread. UNSLOTH_DIFFUSION_GENERATE_EXECUTOR=0 restores asyncio.to_thread.
Codex Review Summary: ✅ CompletedThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
[skip ci]
Member
Author
|
@codex review |
|
Codex Review: Didn't find any major issues. 👍 Reviewed commit: ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
If Codex has suggestions, it will comment; otherwise it will react with 👍. Codex can also answer questions or update the PR. Try commenting "@codex address that feedback". |
shimmyshimmer
pushed a commit
to shimmyshimmer/unsloth-staging-4
that referenced
this pull request
Nov 9, 2026
…#17188) Follow-up to unslothai#17108. ## What happened unslothai#17108 moved queued image renders off the default asyncio executor onto their own `image-generate` pool, because a render waits for the one-render slot inside its thread and a few queued renders could hold every default worker, stalling status reads and everything else that uses `asyncio.to_thread`. The Detailer pass in the same route was left on `asyncio.to_thread`. `_run_detailer` hands `backend.generate` to the Detailer, and each crop inpaint is a synchronous generate call that waits on the same render slot. So a few Detailer requests queued behind a render still filled the default executor. A reviewer reproduced it with the route's dispatch expression: four Detailer workers blocked on a held slot exhausted a four-worker default executor and a status read timed out after 0.2 s, while the same work dispatched through `_image_generate_in_thread` left the read responsive. ## Fix Dispatch `_run_detailer` through `_image_generate_in_thread`, like the primary render. The caller's context is still copied (account access), and the existing `UNSLOTH_DIFFUSION_GENERATE_EXECUTOR=0` switch restores `asyncio.to_thread` for both. ## Tests `studio/backend/tests/test_image_generate_executor.py::test_detailer_inpaints_wait_on_the_image_pool` reads how the route awaits `_run_detailer`: it fails on main (`asyncio.to_thread`) and passes here. The existing saturation, context and kill switch tests in that file still pass (5 passed).
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
An image generation request runs
backend.generatethroughasyncio.to_thread. Inside that worker thread, the engine then waits for its one-render slot (_generation_slot, polling_generate_lock.acquire(timeout = 0.1)).Every queued render therefore holds a worker of the default executor for the whole time it waits. That executor is the one image status, gallery, chat streaming and most other routes use through
asyncio.to_thread. With as many queued renders as the executor has workers (min(32, cpus + 4)), those calls stall until the active render ends.Changes
image-generatepool (32 workers) instead of the default executor:asyncio.to_threaddoes, so account scope and progress context reach the render unchanged.UNSLOTH_DIFFUSION_GENERATE_EXECUTOR=0restoresasyncio.to_thread.Evidence (CPU)
tests/test_image_generate_executor.pyuses a default executor of 4 workers, 4 queued renders behind a held slot, then one default-executor read (a status call):asyncio.to_thread(main, and the kill switch)image-generateThe image route suites (
test_diffusion_routes,test_openai_image_generation,test_openai_images_batching,test_openai_images_generations_route,test_openai_multi_image_route,test_generate_image_tool,test_liveness_reports_inference_active,test_diffusion_detailer) give 413 passed, 8 skipped on both main and this branch.