Repository navigation
Studio LTX-2.5: keep a streamed denoiser partly resident per request - #16845
Conversation
…quest LTX-2.5 was outside the per-request residency fit (video_stream_residency) that Wan and HunyuanVideo-1.5 use on the group and streaming tiers, so on cards that stream its DiT (L4, A100 with GGUF, 16-24 GiB budgets) every forward copied all 48 blocks from the host while part of the card stayed idle. The fit is generic over offload groups and LTX-2.5 is a single-DiT family, so it is added by exact name. LTX-2.5's Gemma 4 encoder runs in a worker process on the same card and borrows free memory for an encode. Before an encode that is not a cache hit, the resident blocks it needs step aside (release_resident_groups): enough for the whole encoder when that makes it fit, else up to a streamed-encode floor; they are pinned back right after the encode. Placement only: the same weights and kernels run. Kill switches unchanged: UNSLOTH_VIDEO_DIT_RESIDENT=0 (no fit, nothing lent), UNSLOTH_VIDEO_DIT_RESIDENT_BLOCKS=0, UNSLOTH_VIDEO_DIT_RESIDENT_MEASURED=0.
|
@codex review |
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. |
|
@codex review |
|
Codex Review: Didn't find any major issues. Another round soon, please! 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". |
… a fixed 6 GiB floor Main's streamed encode (#16750) needs the resident embeddings, two layers and the 4 GiB encode margin, about 7 GiB for the real Gemma 4, so lending up to 6 GiB could leave the encode on the CPU. The worker now reports stream_need_mib in its ready message (None when it never streams: resident, not CUDA / XPU, kill switch, unstreamable layout) and the lend targets that. The server's room check now calls the worker's _encode_room_mib, so both sides compute room the same way. [skip ci]
|
@codex review |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 3322aa26a6
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
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".
| finally: | ||
| if restore is not None: | ||
| restore() |
There was a problem hiding this comment.
Wait for a cancelled encode to stop before restoring residency
When a user cancels during an encode that borrowed resident DiT memory, Ltx25TextEncoderClient._get() raises immediately without stopping the worker or waiting for its response. This finally consequently re-pins the DiT blocks while _encode_on() in the worker can still be using the borrowed GPU memory. On the memory-constrained cards where lending is needed, this can OOM the ongoing encoder or fail the re-pin, leaving the placement only partially restored. Drain the in-flight encode or terminate the worker before returning its borrowed memory to the denoiser.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Fixed in c73fba6: the client now tracks the in-flight request, and when an encode that borrowed resident blocks raises with the worker still computing (a cancel), the wrapper stops the worker before the restore pins the blocks back. The next encode restarts it. A worker that already answered, with embeds or an error, is kept. Covered by test_a_cancelled_encode_stops_the_busy_worker_and_a_finished_one_does_not.
…inning the blocks back A cancel returns from the client while the worker may still be computing the abandoned encode on the memory the denoiser lent it. The client now tracks the in-flight request; when an encode that borrowed resident blocks raises with the worker still busy, the wrapper stops the worker (the next encode restarts it) before the restore re-pins. A worker that answered, with embeds or an error, is kept. [skip ci]
|
@codex review |
|
Codex Review: Didn't find any major issues. What shall we delve into next? 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". |
What
LTX-2.5 was outside the per-request DiT residency fit (
video_stream_residency) that Wan, HunyuanVideo-1.5 and LTX-2 (#16787) use on thegroup/streamingtiers. On cards that stream the LTX-2.5 DiT (L4, 16-24 GiB budgets) every forward copied all 48 blocks from the host while part of the card stayed idle: 11.55 GiB of H2D per forward for GGUF Q4_K_M and 23.6 GiB for the INT8 DiT on an L4.ltx-2.5joinsRESIDENT_FAMILIES(exact name), so the leading blocks stay resident per request, sized from the measured request peak with the existing margin, and only the rest stream through the existing prefetch.video_ltx25.lend_resident_dit_for_encodestreams resident blocks again when that makes the encoder fit: the whole encoder if lending gets it there, else the worker's own layer-streamed need (stream_need_mib, reported in its ready message; Studio diffusion: stream the LTX-2.5 encoder, cache and trim FLUX.3 prompt encodes #16750's streamed encode), and pins them back right after the encode. The room check is the worker's_encode_room_mib, so both processes compute it the same way.Placement only: the same weights and kernels run. Kill switch: the existing
UNSLOTH_VIDEO_DIT_RESIDENT=0(also disables the lending).Numbers (Colab L4 24 GB, LTX-2.5 two-stage distilled 1280x704x121, GGUF Q4_K_M, 2 new prompts per arm, fresh process per arm, main 73984c4)
s/step is 18-20% lower (A/A within 1.3%); the fit kept 4006 MiB (15 groups) resident. Frames against main + #16804 on the same VM: bit-identical (16 of 16 frames, both prompts). Against main alone the frames differ only because main encodes the later prompts on the CPU (fixed separately by #16804; this branch's lending path also releases the server cache when blocks are resident).
Earlier A/B on main e2daf16 (with the then-open encoder changes): Q4_K_M 4.67 -> 3.86 s/step, INT8 2.13 -> 1.98, H2D per forward 11.55 -> 9.57 GiB (Q4) and 23.61 -> 21.88 GiB (INT8), frames bit-identical with and without the change and with the kill switch, no-op on an A100-40 (nothing streams there).
The lending path did not engage on these cards (the encoder already fit its streamed need once the server's cache was released); it is covered by CPU tests.
Tests
tests/test_video_stream_residency.py(ltx-2.5 applies on group / streaming, not on model offload or a custom name; fails on main) and new tests intests/test_video_ltx25.py: blocks are lent only when the encoder then fits whole or reaches the worker's streamed need, never for an encoder that cannot stream, a resident encoder or a non-CUDA device; the worker reports its streamed need only when it can stream; the encode wrapper lends before a cache miss, restores after it (also on failure) and skips cache hits; a cancelled encode stops a busy worker before the restore.test_video_ltx25.py+test_video_stream_residency.py: 164 passed, 7 failed, the same 7 test IDs that fail on main in this environment (two-stage i2v fakes, real-header converters).