Skip to content

LTX2: Refactor forward function for better VRAM efficiency and fix spatial inpainting#12046

Merged
comfyanonymous merged 3 commits intoComfy-Org:masterfrom
kijai:ltx2_memory
Jan 23, 2026
Merged

LTX2: Refactor forward function for better VRAM efficiency and fix spatial inpainting#12046
comfyanonymous merged 3 commits intoComfy-Org:masterfrom
kijai:ltx2_memory

Conversation

@kijai
Copy link
Contributor

@kijai kijai commented Jan 23, 2026

There are a lot of intermediate tensors that can be freed before the heavier operations like feedforward activation and video attention, I've been testing this through custom patch node for few days now without any issues.

I'm aware FFN could additionally be chunked, but it doesn't seem possible to do without affecting the model output in every situation, especially when something like fp8 matmuls are used. So that remains optional memory saving through custom nodes.

Before and after at 1024x1024 x 497:

chrome_Kua1U5FoQz

Output remains unchanged, and speed difference is within margin of error, tested in Windows on 4090:

before:
loaded partially; 9325.47 MB usable, 9235.26 MB loaded, 11306.01 MB offloaded
4/4 [02:10<00:00, 32.66s/it]
4/4 [02:09<00:00, 32.33s/it]

after:
loaded partially; 9326.22 MB usable, 9235.26 MB loaded, 11306.01 MB offloaded
4/4 [02:10<00:00, 32.52s/it]
4/4 [02:09<00:00, 32.34s/it]

Also realized that my previous memory optimization broke spatial inpainting, so I added bit of code to detect if spatial mask is used and in that case just revert to the old behavior, which is of course going to negate memory savings. However that's bit of an edge case as overall functionality of spatial masking remains questionable, and mostly the model is used with only temporal masks.

@comfyanonymous comfyanonymous merged commit 55bd606 into Comfy-Org:master Jan 23, 2026
12 checks passed
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.

2 participants