Repository navigation
Studio: seam-free LTX-2.3 video decode (untiled when it fits, VRAM-sized tiles otherwise) - #12698
Conversation
Studio tiles every LTX-2 / 2.3 video decode with diffusers' stock 512 px tiles and a 64 px blend, which leaves a visible line at every tile seam on every tier. Resident loads now decode untiled when the measured estimate fits (video_vae_untiled, OOM falls back to tiled); otherwise the decode uses the fewest, largest tiles the free VRAM holds (one untiled decode when the whole latent fits), with >= 8-latent overlaps and an edge-aligned last tile. Kill switch UNSLOTH_VIDEO_VAE_WIDE_TILES=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. |
|
The |
test_source_read_encoding refuses checked-in file reads that rely on the platform default encoding, which breaks on Windows once the file gains a non-ASCII byte.
…n fit, keeping the floor near stock memory
|
@codex review |
1 similar comment
|
@codex review |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 6ce50a6ad4
ℹ️ 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".
| pos = (torch.arange(size, dtype = torch.float64, device = device) + 0.5) / scale | ||
| total = torch.zeros(length * scale, dtype = torch.float64, device = device) |
There was a problem hiding this comment.
Use an MPS-supported dtype for blend weights
On Apple Silicon, any LTX-2 decode requiring multiple spatial tiles fails here because z.device is MPS and both this allocation and the following torch.zeros(..., dtype=torch.float64) request double-precision device tensors; PyTorch documents that MPS cannot allocate torch.float64. This affects the default 768x512 latent (16x24), since the MPS free-memory probe falls back to the 16-latent floor and therefore enters axis_weights; use float32 weights on MPS or perform the normalization on CPU before moving supported weights to the device.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Fixed in 410007b: blend weights are built in float64 on CPU and moved to the decode device as float32, with a test that no float64 tensor is created off CPU.
| stats["oom_fallback"] += 1 | ||
| torch.cuda.empty_cache() | ||
| th, tw = floor | ||
| vae._unsloth_last_decode_tile = floor |
There was a problem hiding this comment.
Remember tile plans that already exhausted memory
When the estimate is low enough for a selected wide tile to OOM, this fallback only replaces the local th/tw values for the current call. A later render with the same latent shape and reported free memory runs _plan again, selects the same known-failing tile, performs the expensive failed decode, clears the allocator, and retries from the floor again. Persist an OOM ceiling or failed plan on the VAE, as the adjacent untiled wrapper does with oom_need, so subsequent renders go directly to a viable tile size.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Performance only, not a correctness bug: the decode still completes after one retry in stock-size tiles, and the per-tile estimate already sits above the measured peaks, so a repeated OOM needs memory to shrink between renders.
|
@codex review |
1 similar comment
|
@codex review |
|
Codex Review: Didn't find any major issues. Swish! 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". |
Problem
Studio decodes every LTX-2 / LTX-2.3 video with tiling turned on, on every tier, using diffusers' default tiles for
AutoencoderKLLTX2Video. Those tiles are 512 px (16 latents) with a 448 px stride, so neighbouring tiles share only 2 latents and a 64 px linear blend. The decoder needs more context than 2 latents past a tile edge, so each tile decodes its border differently from its neighbour and every seam shows up as a visible line, one tile long, in every frame.Measured on the exact latent Studio hands to
vae.decode(same render, same seed), compared with Studio's own untiled decode of that latent. Score = worst 64 px window mean |tiled - untiled| along a column or row, worst frame, 8-bit levels:The resident path never decodes LTX untiled either, even with 100+ GB free, so a B200 pays for 6 tiles with seams instead of one cheaper untiled pass.
Change
video_vae_untiled.py:ltx-2joins the resident untiled-when-it-fits path (same gate, sameUNSLOTH_VIDEO_VAE_UNTILEDswitch, same OOM fallback to tiled). Unlike Wan, the LTX decoder holds every frame at once, so the estimate scales with output frames x latent pixels: 0.11 MiB each in bf16, against 0.102 to 0.105 MiB measured untiled on a B200 over 512x512 to 1216x704 and 25 to 241 frames.video_ltx2_vae_tiles.py, installed on every LTX load that tiles the decode, replaces the VAE'stiled_decode:tembandcausalare passed to every tile.UNSLOTH_VIDEO_VAE_WIDE_TILES=0. Set at load, the install is skipped. Set later, each decode takes the stock tiled path. WithUNSLOTH_VIDEO_VAE_UNTILED=0, the decode always uses at least two tiles.use_framewise_decodingfor LTX, and diffusers leaves it off, so every tile spans all frames on both main and this branch. No temporal tile boundaries exist. The per-frame error stays flat (largest frame-to-frame change of the per-frame mean error: 0.058 to 0.080 on main, 0.000 to 0.016 here).ComfyUI's LTXV decode follows the same plan.
VAE.decodefirst tries an untiled decode. If that would not fit (or runs out of memory), it falls back to tiles that start at 8 latents and grow while they fit the memory it reserved, with an overlap of a quarter of the tile, and it only splits frames when one tile cannot fit.Results
B200, Studio
VideoBackendin process, LTX-2.3 distilled with Studio defaults (8 steps, default speed tier, auto memory), seed 7. Base is main (c754470002). Each cell loads once, then runs 3 renders per shape, and rep 0 is the warm-up. Every card is exclusive, and the 24 / 16 GiB tiers use the VRAM simulator (total and allocator capped). The latent handed to the VAE is bit-identical across every cell (both trees, every tier), so the decode is the only difference.Decode seconds (reps 1 and 2), extra decode peak, and seam score against Studio's untiled decode:
With 2 tiles at 1216x704x121, the decoded area (2 x 22x23 latents) is the same as the stock tiles cover (1008 latents), so the decode time roughly matches stock: 0.6% slower on the RTX PRO 6000, 3.5% (0.2 s) slower on the L4, and 10% faster on the B200. Every other cell is 15 to 25% faster.
An overlap of 12 or more needs a third tile, which costs more time than the 0.3 level it saves.
Tests
tests/test_video_ltx2_vae_tiles.py(tiny realAutoencoderKLLTX2Video, CPU), 156 tests with the untiled suite:UNSLOTH_VIDEO_VAE_UNTILED=0keeps two or more tiles;temb/causalreach every tile; an OOM retries once in 16-latent tiles;ltx-2untiled estimate covers every measured peak (within 20%), and the resident wrapper decodes untiled when it fits and tiled when it does not;video.pyinstalls the tiles after enabling tiling, under the resident untiled wrapper.video_ltx2_vae_tilesdoes not exist), anduntiled_decode_bytes("ltx-2", ...)returns None.tests/test_video_backend.py: 451 passed.Not covered