Skip to content

[LTX-2] Fix component device placement for split-device pipelines - #15420

Open
dacorvo wants to merge 3 commits into
mainfrom
ltx2-split-device
Open

dacorvo wants to merge 3 commits into
mainfrom
ltx2-split-device

Conversation

@dacorvo

@dacorvo dacorvo commented Nov 27, 2026

Copy link
Copy Markdown

Problem

#14739 lets a pipeline run with its components on different devices, for example the denoiser on the accelerator and the text encoder and VAEs on the CPU. It didn't cover the LTX-2 pipelines. With such a split they run on the accelerator (#14383), but they still move the inputs of every component there. So they fail as soon as the text encoder, the connectors, the duration head, the VAE, the audio VAE or the vocoder stays on the CPU.

What this PR does

How to use it

import torch
from diffusers import LTX2Pipeline

pipe = LTX2Pipeline.from_pretrained("Lightricks/LTX-2", torch_dtype=torch.bfloat16)
pipe.transformer.to("cuda")  # every other component stays on the CPU
video, audio = pipe(prompt="A cat playing the piano", output_type="np", return_dict=False)

Testing

  • On a NeuronCore (AWS Trainium), the new test fails without the fix, in the Gemma 3 embedding. With the fix, it passes for 6 of the 7 pipelines.
  • HDR needs a 1e-2 tolerance. Its inverse LogC3 transfer function takes the output up to ~55, and the largest difference I measured is 5.75e-3.
  • DFR temporal refine fails on Neuron on main too, even with every component on the core (in the scheduler's noise draw). So its split path is untested there.
  • The dummy pipelines have no duration head. I checked it by hand on Neuron for T2V, I2V and condition: same predicted length, and frames within 2.7e-4 of an all-CPU run.
  • The LTX-2 pipeline tests pass on CPU, where the new tests skip.
  • Not run on CUDA.

🤖 Generated with Claude Code

With only the transformer on the accelerator, the LTX-2 pipelines run
on the accelerator (#14383), but they gave the text encoder, the
connectors, the duration head, the VAE, the audio VAE and the vocoder
their inputs on that device. They failed as soon as one of these
components stayed on the CPU.

Move the inputs of each component to its own device, as #14739 does
for other pipelines, and add an opt-in test that runs a pipeline with
only its denoiser on the accelerator.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@github-actions github-actions Bot added tests pipelines size/L PR with diff > 200 LOC labels Nov 27, 2026
@HuggingFaceDocBuilderDev

Copy link
Copy Markdown

The docs for this PR live here. All of your documentation changes will be reflected on that endpoint. The docs are available until 30 days after the last update.

dacorvo added a commit to huggingface/blog that referenced this pull request Nov 27, 2026
huggingface/diffusers#15420 gives each component of the LTX-2 pipelines
its inputs on its own device, which would remove the need to pin the
pipeline to the host.

The paragraph no longer says the planned `_tp_plan` would make the first
workaround unnecessary. The LTX-2.5 attention normalizes the queries and
keys over all the heads, so a plan alone does not replace its attention
processor.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

@JingyaHuang JingyaHuang left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

thanks for adding the fix to ltx-2! just a small nit for the test helper.

Comment thread tests/pipelines/testing_utils/memory.py Outdated

def test_split_device_forward_pass(self, base_pipe_output, expected_max_diff=1e-4):
pipe = self.get_pipeline()
denoiser = getattr(pipe, "transformer", None) or getattr(pipe, "unet", None)

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

maybe we should make this more configurable, so a pipeline can choose which components go on the accelerator instead of only the denoiser?

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.

I don't understand the test. How does it show that the pipeline has split device setting?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

I modified the mixin to make it more generic and the test class instantiations to better show what is on the device.

text_encoder_hidden_states = text_encoder_outputs.hidden_states
text_encoder_hidden_states = torch.stack(text_encoder_hidden_states, dim=-1)
prompt_embeds = text_encoder_hidden_states.flatten(2, 3).to(dtype=dtype) # Pack to 3D
prompt_embeds = text_encoder_hidden_states.flatten(2, 3).to(device=device, dtype=dtype) # Pack to 3D

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.

Should it not be model_device?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

@sayakpaul that's the pattern drawn by @JingyaHuang that I replicate here: model_device is where the text encoder runs, so only its inputs go there. The embeddings go to the pipeline device.

text_encoder_hidden_states = torch.stack(text_encoder_hidden_states, dim=-1)
prompt_embeds = text_encoder_hidden_states.flatten(2, 3).to(dtype=dtype) # Pack to 3D
prompt_embeds = text_encoder_hidden_states.flatten(2, 3).to(device=device, dtype=dtype) # Pack to 3D
prompt_attention_mask = prompt_attention_mask.to(device)

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.

Same.

Comment thread tests/pipelines/testing_utils/memory.py Outdated

def test_split_device_forward_pass(self, base_pipe_output, expected_max_diff=1e-4):
pipe = self.get_pipeline()
denoiser = getattr(pipe, "transformer", None) or getattr(pipe, "unet", None)

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.

I don't understand the test. How does it show that the pipeline has split device setting?

dacorvo and others added 2 commits November 27, 2026 14:38
`SplitDeviceTesterMixin` places the components named in
`accelerator_components` on the accelerator, instead of looking up the
transformer or the unet. It defaults to the transformer, so the LTX-2
tests keep the same placement.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
`SplitDeviceTesterMixin` no longer defaults `accelerator_components` to
the transformer. Each LTX-2 test class sets it, so the test shows which
components it places on the accelerator. The class docstrings name the
transformer instead of the denoiser.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

pipelines size/L PR with diff > 200 LOC tests

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants