Skip to content

Studio video: keep a streamed LTX-2 denoiser partly resident per request (21% faster per step) - #16787

Merged
danielhanchen merged 2 commits into
mainfrom
studio-ltx2-dit-resident
Nov 5, 2026
Merged

danielhanchen merged 2 commits into
mainfrom
studio-ltx2-dit-resident

Conversation

@danielhanchen

Copy link
Copy Markdown
Member

Summary

video_stream_residency re-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-2 covers 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, plan group: 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 is main 157305f (the merge base). Times are scheduler-step medians, one DiT call per step (the pipeline batches both guidance branches).

arm request 1 s/step request 2 s/step request 3 s/step peak allocated DiT resident
base r1 (main) 9.225 9.225 9.225 23.1 GiB 0
base r2 (main) 9.242 9.241 9.241 23.1 GiB 0
head r1 9.233 7.301 7.301 31.2 GiB 8021 MiB (11 groups) from request 2
head r2 9.235 7.308 7.308 31.2 GiB 8021 MiB (11 groups) from request 2
head, UNSLOTH_VIDEO_DIT_RESIDENT=0 9.246 9.246 9.246 23.1 GiB 0
  • A/A spread: base 9.225 to 9.242 s/step (0.2%), head 7.301 to 7.308 (0.1%). Once a measured peak exists (request 2 onward), head is 21% faster per DiT call, far outside the noise.
  • Output: for every request, the decoded frame bytes and the mp4 bytes are identical across all five arms (frames sha bc544a0a2dd4b627, e0266cb88ba2bc8e, 1c5258a24678ae47). Resident groups run the same kernels as streamed ones.
  • Request 1 promotes nothing. With no measured peak yet, the flat estimate leaves no room, so the first render is unchanged. The fit log reads 8021 MiB of the streamed denoiser resident (11 groups) ... room 8284 MiB (measured peak ...).
  • Default plan on the same card (int8 DiT quant, placed resident with the text encoders streamed): the fit has no streamed groups to promote. Base and head are both 1.405 s/step with identical frames, so nothing changes there.
  • Tiny 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):

tree result failing IDs
base (main + this test file) 1 failed test_applies_only_to_block_streamed_single_dit_wan_hunyuanvideo_and_ltx2_on_cuda
head all passed (6 CUDA-only skips) none

Not covered

  • LTX-2.3 single-file and LTX-2.5 were not run (2.5 is excluded on purpose).
  • The streaming tier (text encoder larger than the card's budget) was not run for LTX-2; the fit itself is shared with the group tier.
  • Measured on one card model (A100 40 GB). No consumer card was run.

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.
@danielhanchen danielhanchen self-assigned this Nov 5, 2026
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 5, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-05T13:00:41.970104Z 4b027e9 Manual request
ℹ️ 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" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@danielhanchen

Copy link
Copy Markdown
Member Author

@codex review

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. More of your lovely PRs please.

Reviewed commit: 4b027e9776

ℹ️ 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".

@danielhanchen
danielhanchen merged commit c6f4f78 into main Nov 5, 2026
@danielhanchen
danielhanchen deleted the studio-ltx2-dit-resident branch November 5, 2026 17:38
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).
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant