Repository navigation
Studio: close the LTX-2.5 two-stage speed gaps in a shared multi-stage layer - #13508
Conversation
- 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.
|
@codex review |
|
You have reached your Codex usage limits for security reviews. Please try again later. |
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 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: Didn't find any major issues. Breezy! 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". |
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, itsencode_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'srender()is the first user.render()now reports each stage's size before it runs (on_stage), and a failing hint never fails the render._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.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.
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
maxtier matchesdefaultper step but costs 140 s on the first render, sodefaultstays.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.test_video_ltx25.pyplustest_diffusion_multistage.pygive 134 passed / 14 skipped.tests/test_diffusion_preview.pyon 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.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.