Skip to content

Studio LTX-2.5: keep a streamed denoiser partly resident per request - #16845

Merged
danielhanchen merged 6 commits into
mainfrom
n5lx-partial-residency
Nov 6, 2026
Merged

danielhanchen merged 6 commits into
mainfrom
n5lx-partial-residency

Conversation

@danielhanchen

@danielhanchen danielhanchen commented Nov 5, 2026 •

Copy link
Copy Markdown
Member

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 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; 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.
  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 + #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 + #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 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).

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

Copy link
Copy Markdown
Member Author

@codex review

@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-06T01:14:33.156235Z c73fba6 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. Another round soon, please!

Reviewed commit: 4f8f14016c

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

… 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]
@danielhanchen

Copy link
Copy Markdown
Member Author

@codex review

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 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".

Comment on lines +1155 to +1157
finally:
if restore is not None:
restore()

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge 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 👍 / 👎.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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]
@danielhanchen

Copy link
Copy Markdown
Member Author

@codex review

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. What shall we delve into next?

Reviewed commit: c73fba6df5

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant