Skip to content

Studio: seam-free LTX-2.3 video decode (untiled when it fits, VRAM-sized tiles otherwise) - #12698

Merged
danielhanchen merged 9 commits into
mainfrom
studio/ltx-vae-seams
Oct 5, 2026
Merged

danielhanchen merged 9 commits into
mainfrom
studio/ltx-vae-seams

Conversation

@danielhanchen

Copy link
Copy Markdown
Member

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:

shape main (stock tiles) untiled, run twice
768x512x121 (default) 33.8 0.0
1216x704x121 (largest preset) 41.7 0.0

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-2 joins the resident untiled-when-it-fits path (same gate, same UNSLOTH_VIDEO_VAE_UNTILED switch, 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.
  • New video_ltx2_vae_tiles.py, installed on every LTX load that tiles the decode, replaces the VAE's tiled_decode:
    • Picks the fewest, largest tiles that fit the free VRAM now, down to one untiled decode when the whole latent fits (the fastest case). It never uses tiles smaller than the stock 16 latents.
    • Neighbouring tiles overlap by at least 8 latents (ComfyUI's overlap for its 32-latent tiles), spread evenly, and the last tile ends at the frame edge, so there are no slivers.
    • Each tile gets zero weight within 3 latents of an edge it shares with another tile, then ramps up over 2 latents. Weights are normalised and accumulated in fp32.
    • The per-tile estimate comes from measured peaks: 0.11 MiB per frame x latent pixel for the stock decoder, 0.075 with the fused decoder passes (0.0704 to 0.0716 measured), plus 5% and 512 MiB. If a decode still runs out of memory, it retries once with stock-size 16-latent tiles.
    • temb and causal are passed to every tile.
    • Kill switch: UNSLOTH_VIDEO_VAE_WIDE_TILES=0. Set at load, the install is skipped. Set later, each decode takes the stock tiled path. With UNSLOTH_VIDEO_VAE_UNTILED=0, the decode always uses at least two tiles.
  • Temporal tiling: Studio never turns on use_framewise_decoding for 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.decode first 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 VideoBackend in 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:

tier (free at decode) shape main decode s this PR decode s main / PR decode peak MiB main / PR seam
full card, resident (112 GB) 768x512x121 0.148, 0.144 0.110, 0.109 (untiled) 2186 / 3279 33.8 / 0.0
1216x704x121 0.311, 0.307 0.228, 0.226 (untiled) 2367 / 7138 41.7 / 0.0
24 GiB, group offload (15.1 GB) 768x512x121 0.138, 0.138 0.108, 0.106 (one tile) 2186 / 3279 33.8 / 0.0
1216x704x121 0.295, 0.297 0.219, 0.228 (one tile) 2367 / 7138 41.7 / 0.0
16 GiB, group offload (6.9 GB) 768x512x121 0.136, 0.135 0.108, 0.136 (one tile) 2186 / 3279 33.8 / 0.0
1216x704x121 0.301, 0.319 0.288, 0.288 (2 tiles of 22x23) 2367 / 5508 41.7 / 1.8
  • Whole render seconds (reps 1 and 2), main / this PR: full card 2.8, 3.4 / 2.8, 2.8 (768x512) and 7.1, 6.7 / 5.4, 5.3 (1216x704). On the offload tiers the render varies by several seconds from run to run on main alone (for example 9.6 to 12.7 s at 24 GiB), so the 0.03 to 0.08 s decode gain is too small to show there. No offload-tier render was slower than main's own spread.
  • Peak memory for the whole render, main / this PR: full card 69.9 / 70.9 GB (768x512) and 70.6 / 74.8 GB (1216x704). 24 GiB: 11.2 / 15.4 GB at 1216x704. 16 GiB: 11.2 / 13.7 GB at 1216x704. Each stays inside the tier, and no cell logged an OOM fallback.
  • 12 GiB: LTX-2.3 does not load on either tree. The planner asks for 11.8 GiB and finds 10.8 GiB (also with the fp8 text encoder). The fp8 DiT is refused on that plan. So no 12 GiB cell exists for this change to affect.
  • Decode only, same latents, B200, Studio's fused decoder: the 16 GiB plan (2 tiles) took 0.27 s, and the stock tiles took 0.30 s in one run and 0.63 s in another. Stock-tile timing varies that much between processes, while the untiled and wide-tile timings repeat within 0.005 s.
  • Decode only on real L4 and RTX PRO 6000 cards (Colab, torch 2.11.0, Studio's fused decoder), using the same two latents. The tier columns plan at the free memory Studio measured at decode on the B200 tiers. Median of 3 after a warm-up, seconds, with the seam score in brackets:
card shape main (stock tiles) this PR, card's own free memory this PR, 16 GiB plan (6.9 GB free)
L4 768x512x121 2.54 (34.0) 2.10, untiled (0.0) 2.11, untiled (0.0)
L4 1216x704x121 5.58 (41.9) 4.80, untiled (0.0) 5.78, 2 tiles (1.8)
RTX PRO 6000 768x512x121 0.439 (34.0) 0.336, untiled (0.0) 0.337, untiled (0.0)
RTX PRO 6000 1216x704x121 0.899 (42.0) 0.749, untiled (0.0) 0.905, 2 tiles (1.9)

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.

  • Tile geometry, chosen on the 1216x704x121 latent with the stock decoder (seam score against untiled; the untiled decode repeated is 0.0):
tiles (latents) count seam
stock: 16, 2-latent blend 6 15.8
16, overlap >= 8, margin 2 / ramp 4 8 2.4
22x24 (overlap 10), margin 2 / ramp 4 2 2.35
22x24 (overlap 10), margin 3 / ramp 2 (shipped) 2 1.7
22x24, overlap >= 12, margin 4 / ramp 4 3 1.4
untiled 1 0.0

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 real AutoencoderKLLTX2Video, CPU), 156 tests with the untiled suite:
    • stock tiles vs these tiles against the untiled decode: the line error drops more than 3x, and the kill switch set after install returns the stock decode bit for bit;
    • a latent that fits decodes bit-identical to untiled; UNSLOTH_VIDEO_VAE_UNTILED=0 keeps two or more tiles;
    • more free memory gives fewer, larger tiles, and every chosen tile's estimate fits (stock and fused coefficients);
    • temb / causal reach every tile; an OOM retries once in 16-latent tiles;
    • tile layout for lengths 1 to 129: full-size tiles, last tile edge-aligned, overlaps >= 8, weights sum to 1;
    • the ltx-2 untiled estimate covers every measured peak (within 20%), and the resident wrapper decodes untiled when it fits and tiled when it does not;
    • video.py installs the tiles after enabling tiling, under the resident untiled wrapper.
  • On main the new test file fails at collection (video_ltx2_vae_tiles does not exist), and untiled_decode_bytes("ltx-2", ...) returns None.
  • tests/test_video_backend.py: 451 passed.
  • torch 2.6.0 (CPU, diffusers pin, no torchao), 2.11.0 + torchao 0.17.0, 2.12.1 + torchao 0.18.0, 2.14.1 + torchao 0.18.0 (the latest torchao release): all 156 pass.

Not covered

  • The tier renders ran on a B200 with the VRAM simulator. The L4 and RTX PRO 6000 numbers are decode only, at the free memory the simulator measured. No full render ran on a real 16 or 24 GB card, and no 16 GB consumer card (for example a 4060 Ti 16 GB) was measured.
  • At the 16 GiB tier, 1216x704x121 decodes in 2 tiles: the seams are gone (41.7 to 1.8), but the decode on an L4 is 0.2 s slower than the stock tiles, because the 2 tiles decode the same area.
  • The free-memory planner assumes a decode on CUDA. On ROCm, MPS and CPU, Studio's fused decoder passes are off, so the stock-decoder estimate is used. Those platforms were not run.
  • SPEED_OFF loads get the same tiles (seams are a correctness bug, as with Qwen-Image-2.1's wide tiles), so an SPEED_OFF LTX decode that fits in memory is now untiled rather than stock-tiled.

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.
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 4, 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-05T10:44:05.623952Z 410007b 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

The Repo tests (CPU, rest) failure is from this PR, not main: tests/test_source_read_encoding.py flags studio/backend/tests/test_video_ltx2_vae_tiles.py:248, an open() of a checked-in file without an encoding. Passing encoding = "utf-8" there should clear it; otherwise Windows reads it with the ANSI codepage as soon as the file gains a non-ASCII byte.

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.
@danielhanchen danielhanchen self-assigned this Oct 5, 2026
@unslothai unslothai deleted a comment from chatgpt-codex-connector Bot Oct 5, 2026
@danielhanchen

Copy link
Copy Markdown
Member Author

@codex review

1 similar comment
@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: 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".

Comment on lines +75 to +76
pos = (torch.arange(size, dtype = torch.float64, device = device) + 0.5) / scale
total = torch.zeros(length * scale, dtype = torch.float64, device = device)

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

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

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

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.

Comment on lines +260 to +263
stats["oom_fallback"] += 1
torch.cuda.empty_cache()
th, tw = floor
vae._unsloth_last_decode_tile = floor

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

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

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.

@danielhanchen

Copy link
Copy Markdown
Member Author

@codex review

1 similar comment
@danielhanchen

Copy link
Copy Markdown
Member Author

@codex review

@chatgpt-codex-connector

Copy link
Copy Markdown

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

Reviewed commit: 410007ba5c

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

2 participants