Repository navigation
Studio video: keep a streamed LTX-2 denoiser partly resident per request (21% faster per step) - #16787
Merged
Conversation
LTX-2 was left out of the per-request residency fit that Wan and HunyuanVideo-1.5 use on the group and streaming tiers, so a bf16 LTX-2 DiT streamed every block every step with most of the card idle. The fit is generic over offload groups, and LTX-2 is a single-DiT family, so it is added by exact name (ltx-2 covers 2.0 to 2.3; ltx-2.5 stays out). Kill switches unchanged: UNSLOTH_VIDEO_DIT_RESIDENT=0, UNSLOTH_VIDEO_DIT_RESIDENT_BLOCKS=0, UNSLOTH_VIDEO_DIT_RESIDENT_MEASURED=0.
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. |
Member
Author
|
@codex review |
|
Codex Review: Didn't find any major issues. More of your lovely PRs 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". |
Penguinjanator
pushed a commit
to Penguinjanator/unsloth
that referenced
this pull request
Nov 6, 2026
…nslothai#16845) ## What LTX-2.5 was outside the per-request DiT residency fit (`video_stream_residency`) that Wan, HunyuanVideo-1.5 and LTX-2 (unslothai#16787) use on the `group` / `streaming` tiers. 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. 1. `ltx-2.5` joins `RESIDENT_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. 2. LTX-2.5's Gemma 4 encoder runs in a worker process on the same card. Before an encode that is not a cache hit, `video_ltx25.lend_resident_dit_for_encode` streams 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; unslothai#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. 3. A cancelled encode that borrowed blocks stops the worker before they are pinned back (it may still be computing on the lent memory); the next encode restarts it. 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) | arm | s/step | denoise s per new prompt | encode s per new prompt | |---|---|---|---| | main | 4.68-4.70 | 85.2 / 85.2 | 227.4 / 231.4 (CPU) | | this PR, arm 1 | **3.82-3.84** | **76.2 / 76.3** | 81.3 / 82.1 (GPU) | | this PR, arm 2 | **3.82-3.87** | **76.3 / 76.0** | 67.4 / 37.8 (GPU) | | second VM: main + unslothai#16804 | 4.85-4.86 | 86.5 / 86.5 | 64.3 / 66.2 (GPU) | | second VM: this PR | **3.89-3.92** | **76.7 / 76.6** | 43.7 / 8.3 (GPU) | s/step is 18-20% lower (A/A within 1.3%); the fit kept 4006 MiB (15 groups) resident. Frames against main + unslothai#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 unslothai#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 in `tests/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).
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
video_stream_residencyre-fits a block-streamed video denoiser's resident prefix per request (group and streaming tiers), from free memory and the request's measured peak. It was limited to Wan and HunyuanVideo-1.5 (#14865), which left LTX-2 out with no stated failure. On a 40 GB card a bf16 LTX-2 DiT then streamed every block every step while about 17 GB of the card stayed idle.This adds LTX-2 to the fit by exact family name (
ltx-2covers 2.0 to 2.3).ltx-2.5, which uses a different decoder stack and was not measured, stays out. Nothing else changes. The fit is generic over offload groups, and LTX-2 is a single-DiT family.Kill switches are unchanged:
UNSLOTH_VIDEO_DIT_RESIDENT=0,UNSLOTH_VIDEO_DIT_RESIDENT_BLOCKS=0(top group only),UNSLOTH_VIDEO_DIT_RESIDENT_MEASURED=0(estimate only).Evidence
Colab A100-SXM4-40GB, one VM. Studio was installed with its own
install.sh(torch 2.13.0+cu130, diffusers 0.42.1, transformers 5.5.0). Model:Lightricks/LTX-2, 768x512, 49 frames, 8 steps, CFG 4 (family default), memory mode Fast, transformer quant off (bf16 DiT, plangroup: denoiser streamed block by block). Each arm is a fresh process. Arms ran in this order: base, head, head, base, head with the kill switch. Base ismain157305f (the merge base). Times are scheduler-step medians, one DiT call per step (the pipeline batches both guidance branches).UNSLOTH_VIDEO_DIT_RESIDENT=0bc544a0a2dd4b627,e0266cb88ba2bc8e,1c5258a24678ae47). Resident groups run the same kernels as streamed ones.8021 MiB of the streamed denoiser resident (11 groups) ... room 8284 MiB (measured peak ...).LTX2VideoTransformer3DModel(6 blocks) under diffusers block-level group offload on CUDA: re-fits at room 0, a partial room, the whole model and 0 again. The forward outputs are bitwise equal to the fully resident model every time, and groups are promoted and released as expected.Tests (
tests/test_video_stream_residency.py+tests/test_diffusion_auto_multigpu_policy.py, CPU):test_applies_only_to_block_streamed_single_dit_wan_hunyuanvideo_and_ltx2_on_cudaNot covered