Repository navigation
Studio: queue /v1/videos while a video renders and batch waiting /v1/images/generations requests - #15613
Conversation
…images/generations requests
…s, and let Stop reach waiting image batches
Codex Review SummaryThis 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. |
|
Reached Codex review convergence at oobabooga#425 (Codex found no major issues on a610c84). |
Review + reproduction evidencePinned review: I reproduced a second video create and a burst of image requests through the /v1 API on the merge base
Conclusion: the video queue is real and works, including cancel and delete of queued clips after the fix. Image batching works correctly but showed no speedup here, so I would ship it off by default until it does. CI on the head still has to finish. |
…o later slot holders cannot starve it
…ixels stay reproducible [skip ci]
|
@codex review |
|
Codex Review: Something went wrong. Try again later by commenting “@codex review”. ℹ️ 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". |
|
@codex review |
|
Codex Review: Something went wrong. Try again later by commenting “@codex review”. ℹ️ 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". |
… queued jobs like an immediate start - A queued start now enters media_keepwarm.begin_request(VIDEO) / end_request, so an idle unload or auto-switch holding the admission gate sees it and cannot cancel an accepted clip. - The drainer treats an in-flight model load (loading_repo_ids) as busy, so a job polled mid-replacement keeps waiting instead of failing with "No video model loaded". - The family-specific shape, fps and conditioning checks are factored into _refuse_family_inputs and run before a busy create is queued, against the resident family or the resolved switch target, so an invalid clip gets the same 400 it would get when idle. - A queued job reports the resident model whenever the resident will render it (for example a named model with auto-switch off), not the requested name.
|
@codex review |
|
Codex Review: Something went wrong. Try again later by commenting “@codex review”. ℹ️ 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". |
…ued image-to-video canvas from its reference
|
@codex review |
|
Codex Review: Something went wrong. Try again later by commenting “@codex review”. ℹ️ 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". |
…erves, keep an engine Stop on a failed image batch final - A queued /v1/videos start rechecks its account in the same call that reserves the generation, so an account disabled during the admission or auto-switch waits never renders. - A Stop by id on a queued video whose start is in flight waits for the start to settle, then stops what it left, instead of answering 409 and letting it render. - A Stop acknowledged by the engine while a shared /v1/images call fails is reported as cancelled to every request in the batch, so none renders again alone.
…nresident target's size and seconds - A queued /v1/videos start checks its account again inside begin_generate, after the keyframes and references are prepared and right before the job is reserved, so a disable during that preparation never renders. - A queued job naming another downloaded model reports that model family's default size and duration, on its own frame lattice, instead of auto.
…eps the job queued
#15745) ## Summary `Repo tests (CPU, rest)` fails on main with three guard failures. It shows on every staging CI run of recent PRs (#15613, #15615, #15673 and others), whatever the PR changes: ``` tests/test_rendezvous_port_everywhere.py::test_distributed_tests_take_their_port_from_the_shared_helper tests/test_gc_skip_auto_dist_cells.py: _free_port does not use tests._rendezvous_port tests/test_gc_skip_auto_dist_gloo.py: _free_port does not use tests._rendezvous_port tests/test_source_read_encoding.py::test_checked_in_file_reads_name_an_encoding[5] tests/test_mamba_fused_lora_adapters.py:464: read_text() tests/test_source_read_encoding.py::test_checked_in_file_reads_name_an_encoding[13] tests/test_refresh_moved_layer_devices.py:81: read_text() ``` These tests landed around the same time as the guards that now catch them: - 570b9b8 added the two `gc_skip_auto_dist` gloo tests with their own `bind(("127.0.0.1", 0))` port picker. That is the ephemeral-range race that #15679 moved every distributed test off, which produces `EADDRINUSE`. - 986558e and 7f3c5a1 read checked-in source with the platform default encoding, which breaks on Windows once the file gains a non-ASCII byte. The guards are right in all three cases, so the tests change, not the guards. ## Change - `tests/test_gc_skip_auto_dist_cells.py`, `tests/test_gc_skip_auto_dist_gloo.py`: `_free_port()` delegates to `tests._rendezvous_port.free_port()`, the same three lines every other distributed test uses. The now-unused `import socket` is dropped. - `tests/test_mamba_fused_lora_adapters.py:464`, `tests/test_refresh_moved_layer_devices.py:81`: `read_text(encoding = "utf-8")`. ## Testing - `tests/test_source_read_encoding.py` + `tests/test_rendezvous_port_everywhere.py`: 3 failed on main, 22 passed with this change. - The four touched test files under `-n 4`: 43 passed, 4 skipped.
Follow-up to #14645 and #15344, which made the OpenAI fine-tuning API queue jobs while the GPU is busy and train compatible queued jobs together. This brings the same two behaviours to the image and video generation APIs.
A second
POST /v1/videoswhile a clip rendered was refused with a 409. OpenAI's API accepts it and reports the job asqueued, and clients written against it poll until it runs. Image requests that arrived while another image rendered each waited and then rendered one after another, even when they differed only in prompt and seed, although the diffusers engine can already render a list of prompts and seeds in one call.Videos:
POST /v1/videosqueues instead of refusingVideos get a queue rather than batching: a clip's activations already dominate the memory plan, so two clips in one forward would be refused on most hardware.
status: "queued"with thevideo_...id the clip keeps. Jobs start first in, first out, each as the account that created it and only while that account is still enabled, through the same path as an immediate create, so auto-switch, managed-account checks and every refusal still apply. The seed andcreated_atare kept, andsize,secondsandmodelread as an immediate start would report them. A managed account that may not use the loaded model gets the same 403 as on an immediate start.Queue hardening
media_keepwarm.begin_request/end_request), so an idle unload or auto-switch never cancels an accepted clip._refuse_family_inputs, shared with the immediate start) run before a job is queued: an invalidnum_framesor size gets the same 400 while busy as when idle.Images: waiting
/v1/images/generationsrequests render as one batchseedthat arrive while an image renders and match on everything but prompt andn(same account, model, size, steps, guidance and negative prompt). Once the generation they arrived behind ends, they render as one diffusers call, and each request gets back its own images. A request that finds the engine idle renders at once, as before, so nothing waits for more requests. A request with an explicitseedalways renders alone, so the same seed keeps giving the same pixels whatever else is waiting./v1request too large to batch) takes the slot next, the batch queues for the slot like any other request instead of waiting for the engine to go idle.seed,seed + 1, ..., each image with its own generator and its own recipe. The starting noise is the same, but pixels are not bit-identical to a lone render on GPU: batch-size-dependent kernel numerics move them slightly (measured indiffusion_batched.py: mean abs pixel delta about 2.5/255, LPIPS delta under 0.002). That is why seeded requests never batch. A tiny FLUX pipeline in fp32 on CPU gives identical 8-bit pixels batched and alone.UNSLOTH_STUDIO_IMAGE_BATCH_MAX(1turns batching off). A single request can already ask for 10 in one forward withn.Behavior boundaries
/v1changes. The Studio UI routes (/api/video/generate,/api/inference/images/generate) are unchanged, and a video started from the Video page still starts at once when the engine is free.generate_videotool still starts at once or gets the busy 409, which it reports to the model.queuedjob directly. The MCP code is unchanged.Validation
test_openai_videos_queue.py(18) andtest_openai_images_batching.py(16), driving the real routes over the realVideoBackendjob machinery and a fake diffusers engine. On main, all 18 video tests and 9 image tests fail; the 6 that pass check behaviour this PR keeps (an idle engine, sd.cpp and MLX) or the batching module directly. Besides the behaviour above, they cover deletes and concurrent creates racing the queue, a disabled account, a managed account without access to the loaded model, and a cancel or Stop reaching a batch.studio/backendtest files that import the video or inference routes pass with 8 workers, apart from hostCUDA error: device(s) busy or unavailablefailures andtest_preview_chat_waits_for_a_slow_checkpoint_load, which pass when run alone. The later commits were checked with the video, image, chat-tool and diffusion backend tests (1,077 passed).size, where Studio reports the loaded model's own size instead of the four Sora sizes, as the immediate-start path already does.ruff-unsloth0.6.9.post1),ruff checkat the CI pin and the duplicate-definition lint are clean.Not tested
Specs
Validated against the official OpenAPI spec. It is raw and machine-readable, so it is easy to grep or hand to an AI agent for review:
/videos,/videos/{video_id},/videos/{video_id}/content,/images/generations. Relevant schemas:VideoResource,VideoStatus,VideoListResource,DeletedVideoResource,ErrorResponse,CreateImageRequest,ImagesResponse, and theInferenceRateLimitedresponse for the 429. The file is large, so grep for a path or schema name rather than reading it whole.