Repository navigation
Studio LTX-2.x: drop the all-ones text mask so text cross-attention runs without a bias - #18804
Conversation
…uns without a bias The connectors replace padding with learned registers and hand the DiT an all-ones mask, which it turns into an all-zero additive bias. That bias sends every text cross-attention to the mem-efficient kernel and Inductor materialises it per call. A forward pre-hook replaces an all-ones 2-D mask with None (same maths); any padded mask is kept. Off on the reference speed tier and with UNSLOTH_LTX2_DROP_FULL_TEXT_MASK=0.
…eed tier except off)
|
@codex review |
Codex Review Summary: ✅ CompletedThis 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. Hooray! 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". |
…ich the drop removes exactly [skip ci]
|
@codex review |
|
Codex Review: Didn't find any major issues. Another round soon, please! 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". |
LTX-2.x's text connectors replace prompt padding with learned registers and return an all-ones attention mask. The DiT turns that mask into an additive bias of zeros (
(1 - mask) * -10000) and passes it to both text cross-attentions in every block. Adding zero changes nothing, but anyattn_maskkeeps SDPA off the flash kernel and on the mem-efficient one. Undertorch.compile, Inductor also materialises the bias at[batch, heads, video tokens, text tokens], which is about 0.9 GB of bf16 zeros written and read on every block at 1280x704x121.On the L4 profile of Studio's LTX-2.5 defaults this showed up as
fmha_cutlassF_bf16_aligned_64x128(1.75 s per profiled render, one call per block) plus a fused norm +clone_expandkernel that writes the bias (0.73 s).Change
video_ltx2.install_ltx2_full_mask_drop(pipe)registers a forward pre-hook on everyLTX2VideoTransformer3DModelin the pipe. Whenencoder_attention_mask/audio_encoder_attention_maskis a 2-D mask equal to 1 everywhere, the hook passesNonein its place. The maths is the same, and SDPA can now pick flash.video.pyinstalls it next to the HunyuanVideo-1.5 padded-text trim, on every speed tier exceptoff, and reportsltx2_full_mask_dropinspeed_optims.UNSLOTH_LTX2_DROP_FULL_TEXT_MASK=0turns it off.The output is not bit-identical to main: flash and mem-efficient attention round differently. This is the same trade the HunyuanVideo-1.5 trim already makes.
Tests
New
tests/test_video_ltx2_full_mask.py(CPU, a tiny realLTX2VideoTransformer3DModel):test_all_ones_mask_is_dropped_and_the_output_is_unchanged: the stock forward passes a bias to SDPA, while the hooked forward passes none, drops both masks, and gives the same output (allclose 1e-5).test_padded_mask_is_kept: a padded mask still reaches SDPA and the output is bit-identical.Added to
tests/test_video_backend.py:test_ltx2_full_mask_drop_installed_and_reported(eager / default / max) fails on main and passes here.test_ltx2_full_mask_drop_skipped_on_the_off_tierpasses on both.test_differential.py: DISCRIMINATING, fixed=3, head_fail=0, 547 unchanged.tests/test_video_backend.py,test_video_ltx25.py,test_video_ltx2_prequant.py,test_diffusion_attention_trim.py: 758 passed, 2 skipped.GPU results (Colab L4, LTX-2.5 Studio defaults, 1280x704x121, 8 + 3 distilled steps, INT8 DiT streamed)
One VM, one fresh process per arm, in the order main, branch, branch, main, main, branch. Each arm runs a cold render and then two timed renders (seeds 11 and 12). The first arm of each tree starts with an empty home, and later arms reuse that tree's compile cache.
The steady denoise is 1.66 s per clip faster (3.8%). The main-vs-main spread is 0.18 s and the two ranges do not overlap. Peak allocation is set elsewhere in the render and does not change. The cold render is a tie.
Profile of one render (2 stage-1 + 3 stage-2 steps):
clone_expandkernel that writes the bias (240 calls, 0.6 s) is gone.Accuracy. Every main arm gives the same frames (md5 equal across all three), and so does every branch arm. Main vs branch: LPIPS 0.114 / 0.052 and PSNR 20.8 / 32.8 dB on the two clips. That is the same size of change #17680 produced (0.117 / 0.056), which is how strongly this distilled sampler amplifies one-ulp differences. The maths is unchanged: the bias that is removed is all zeros.
Accuracy against a higher-precision reference. I added a third arm on its own L4 VM: main with every attention call run on fp32 q/k/v (fp32 mem-efficient kernel, the mask kept as main passes it, output cast back). Fresh process per arm, order ref / main / branch / ref, same prompts, seeds and shape. LPIPS (alex) and PSNR over all saved frames:
The branch is no further from the fp32-attention reference than main on either clip, and slightly closer on both.
Not proven here
< 1e-6binarisation maps padded positions to 1 as well), so the bias is dropped there too. A padded mask from any other caller is kept (test_padded_mask_is_kept).