Skip to content

Studio: close the LTX-2.5 two-stage speed gaps in a shared multi-stage layer - #13508

Merged
danielhanchen merged 5 commits into
mainfrom
studio-ltx25-speed
Oct 13, 2026
Merged

danielhanchen merged 5 commits into
mainfrom
studio-ltx25-speed

Conversation

@danielhanchen

Copy link
Copy Markdown
Member

Summary

LTX-2.5 already picks the same speed levers as LTX-2 (block compile, cuDNN attention, runtime int8 / fp8, VAE channels_last and wide tiles, the same family flags). What was missing were gaps inside LTX-2.5's own two-stage render(). This closes four of them. Every change leaves the frames bit-identical to the base.

The stage-boundary levers live in a new family-agnostic module, core/inference/diffusion_multistage.py (encode_once(runner), hold_denoiser_between_calls(pipe, runner, companions)). They key only on what the pipeline object carries (its offload hook list, its denoiser, its encode_prompt), never on a family name, so any render that calls its pipeline more than once per request can wrap its calls in them. LTX-2.5's render() is the first user.

  • Live preview. Stage 1 denoises at half size, but the previewer unpacked its tokens with the full-size grid, so 8 of the 11 preview steps showed scrambled frames. render() now reports each stage's size before it runs (on_stage), and a failing hint never fails the render.
  • Background compile. LTX-2.5 conditions an image-to-video render through its own condition pipeline, not the i2v swap, so those renders were recorded as text-to-video samples, with per-token timesteps. _bg_i2v_render(first_pil, i2v_active) now treats any render with a first frame as image-to-video: no recording, and the session settles the same way. For families that already swap to an i2v pipeline nothing changes; for any other image-conditioned render it only means the background compile does not record that sample.
  • Prompt reuse. The two stages encoded the same prompt twice (157 ms per request). The prompt is now encoded once and uploaded once per request (44 ms).
  • low_vram between stages. Model offload re-uploaded the whole DiT for stage 2 on every request. The DiT now stays on the card when the next stage still fits, and is offloaded as before when it does not.

Measurements

Exclusive B200, 1280x704, 121 frames, family defaults. Each figure is the median [min - max] of 6 warm renders across 2 interleaved processes per arm.

Arm Base This PR
default, same prompt 4.095 s [4.000 - 4.250] 3.900 s [3.780 - 4.420]
default, new prompt every render 5.160 s [4.360 - 5.800] 4.240 s [4.210 - 4.620]
low_vram 8.335 s [7.360 - 9.100] 6.910 s [6.460 - 11.700]

Under low_vram the first step of stage 2 drops from 1299 to 514 ms. Peak memory rises from 25.7 to 31.0 GiB, still under the 32.3 GiB that image-to-video already uses. Speed off (eager) is 5.445 s, so compile alone gives 1.60x on the half-size stage and 1.46x on the full-size stage.

CUDA graphs stay off: the profiler shows the GPU busy about 99.8% of every DiT forward, so there is no launch overhead to remove. The max tier matches default per step but costs 140 s on the first render, so default stays.

Testing

  • tests/test_video*.py tests/test_diffusion_memory.py tests/test_comfy_*.py tests/test_diffusion_multistage.py tests/test_diffusion_preview.py tests/test_orchestrator_unload_cancel.py (CUDA hidden): 2752 passed / 109 skipped / 0 failed.
  • With diffusers hidden, as on Backend CI: test_video_ltx25.py plus test_diffusion_multistage.py give 134 passed / 14 skipped.
  • Real weights on the final head: warm T2V 3.98 - 4.03 s and warm I2V 4.08 s at the defaults, no new graphs after the first render of each kind; under low_vram the first full-size step is 500 ms (1226 - 1475 ms on the base). Frames bit-identical to the base in both modes.
  • tests/test_diffusion_preview.py on a GPU: 17 passed. New tests cover the stage sizes, the failing hint, the background-compile classification, the single prompt upload and the low_vram keep / offload decision.
  • A tiny end-to-end run through VideoBackend (T2V, I2V, low_vram, speed off) passes on every arm.

Not covered: a smaller capped card under low_vram, image-to-video under low_vram (it still re-uploads the DiT at stage 2), and any GPU other than B200.

- Live preview: LTX-2.5's stage 1 denoises at half size, but the previewer
  unpacked its tokens with the full-size grid (880 tokens per frame tile
  the 3520 of 16 half-size frames), so 8 of the 11 distilled steps showed
  four frames scrambled into one picture. render() now names each stage's
  size (on_stage) and LatentPreviewer.set_render_size follows it.
- Background compile (UNSLOTH_DIFFUSION_BG_COMPILE=1): an LTX-2.5
  image-to-video render runs the condition pipeline from its own render,
  never the i2v swap, so it seeded the compile with per-token timesteps
  and settled as a text render. It now skips recording and settles as
  image-to-video, like LTX-2's i2v pipeline.
- Prompt reuse: each request calls encode_prompt once per stage, and a
  cached Gemma 4 encode (385 MB packed hidden states) was cloned on the
  host and uploaded from pageable memory each time: 75-100 ms a call on a
  B200. The client keeps its cache pinned and the stage calls read it
  without a clone (non_blocking upload): 11 ms a call.
Under model CPU offload (low_vram), stage 1's pipeline call ends with
maybe_free_model_hooks, which offloads every component, so stage 2
uploaded the whole DiT again before its first step: 1.30 s for the int8
DiT on a B200, on every request. Text-to-video now holds it across the
boundary when the connectors and the latent upsampler, which run before
the DiT is needed again, still fit beside it with a 2 GiB margin (free
plus the allocator's idle cache); otherwise it offloads as before. The
image-to-video condition pipeline has no hook list of its own and already
kept the DiT: the same check now frees pipe's hooks there when stage 2
would not fit. A text render that stops between its stages resets the
hooks, as image renders already did.

B200, 1280x704x121, low_vram (int8 DiT, model offload), 6 warm renders
per arm, ABBA: stage-2 first step 1299 ms -> 514 ms, pipeline stages
6.02 s -> 4.78 s, request 8.34 s -> 6.91 s. Peak allocated 25.7 ->
31.0 GiB, under the 32.3 GiB the image-to-video path already peaks at.
Frames bit-identical.
…ompt

The pinned client cache made a repeated prompt cheap (157 -> 23 ms per
request) but paid a 385 MB cudaHostAlloc on every new prompt (+0.13 s on
the encode of a new prompt, measured on the I2V arms), which is the
common case. Drop the pinning and share one upload between the two
stages instead: the two-stage render memoises encode_prompt for the
request (stage 1 keeps a device copy, stage 2 takes it), and the client
cache is read without a host clone.

B200, 1280x704x121 default, ABBA 2 processes x 3 warm renders per arm:
same prompt 4.095 -> 3.900 s (stage 2 + decode 1.937 -> 1.869 s, prompt
work 157 -> 44 ms per request); a new prompt every render 5.160 -> 4.240
s (stage 2 + decode 1.982 -> 1.865 s). Frames unchanged.
The stage-boundary DiT hold and the per-request prompt memo lived in
video_ltx25.py. They key only on what a pipeline object carries (its
model-offload hook list, its denoiser, its encode_prompt), so they move
to diffusion_multistage.py: encode_once(runner) and
hold_denoiser_between_calls(pipe, runner, companions), usable by any
render that calls its pipeline more than once per request. The denoiser
comes from the graph layer's own discovery (_denoiser_modules), not
pipe.transformer. LTX-2.5's render only wraps its two calls in them.

The background-compile check for an image-conditioned render no longer
names a family: any render with a first frame, whether the family swaps
in an i2v pipeline or derives one in its own render, skips recording
and settles as image-to-video.

Frames bit-identical to the previous head and to base (default and
low_vram, T2V and I2V, real LTX-2.5 weights on a B200); stage-2 first
DiT step under low_vram still 500 ms (base 1299 ms).
Backend CI does not install diffusers, and the image path builds its
LTX2VideoCondition; same guard main uses for the other image-path tests.
@danielhanchen

Copy link
Copy Markdown
Member Author

@codex review

@chatgpt-codex-connector

Copy link
Copy Markdown

You have reached your Codex usage limits for security reviews. Please try again later.

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 13, 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-10-13T01:34:05.483327Z 0e93d30 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.

@chatgpt-codex-connector

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 ⚠️ Failed 2026-10-13T01:30:30.915979Z 0e93d30 PR opened
ℹ️ 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.

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Breezy!

Reviewed commit: 0e93d3054b

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant