[core] Fix component device placement for split-device pipelines - #14739
Open
JingyaHuang wants to merge 1 commit into
Open
[core] Fix component device placement for split-device pipelines#14739JingyaHuang wants to merge 1 commit into
JingyaHuang wants to merge 1 commit into
Conversation
|
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. |
DiffusionPipeline.device/`_execution_device` (huggingface#14383) already prefer any non-CPU, non-meta component so a pipeline with components split across devices (e.g. text encoder on CPU, denoising backbone on an accelerator) reports the right execution device. But several component call sites still moved a tensor to that execution `device` before handing it to a specific submodule, instead of the submodule's own device -- so encoding a prompt, encoding an IP-Adapter image, or decoding latents would crash with a device-mismatch error as soon as that submodule wasn't already sitting on the same device as everything else. Fixes three component types across the major pipeline families (StableDiffusionPipeline, StableDiffusionXLPipeline, StableDiffusion3Pipeline, FluxPipeline, Flux2(Klein)Pipeline, WanPipeline, WanImageToVideoPipeline): - Text encoder(s): `encode_prompt` / `_get_t5_prompt_embeds` / `_get_clip_prompt_embeds` now read the encoder's own `.device` instead of trusting the passed-in `device`. - VAE: the `vae.encode`/`vae.decode` calls in each `__call__`, plus `Flux2Pipeline.prepare_image_latents` (whose output also wasn't being moved back to the execution device). - image_encoder (IP-Adapter): `encode_image`, plus `run_safety_checker`'s feature-extractor input. Also fixes a cross-device bug in `WanImageToVideoPipeline.prepare_latents` and `Flux2KleinInpaintPipeline.prepare_latents`, where a vae-encoded tensor and the freshly-sampled noise tensor could end up on different devices before being combined by the scheduler. Fixed the canonical/root pipelines by hand, then ran `make fix-copies` to propagate the text-encoder/image-encoder fixes to every `# Copied from` derivative. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
JingyaHuang
force-pushed
the
fix-component-device-placement
branch
from
September 8, 2026 14:34
8191d58 to
50d2025
Compare
JingyaHuang
marked this pull request as ready for review
September 8, 2026 14:37
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What does this PR do?
Follow-up to #14383 (
DiffusionPipeline.devicededuction for split-device pipelines), #14383 fixed how the pipeline reports its execution device when components are split across devices (e.g. text encoders on CPU, denoising backbone on an accelerator, we preferred an accelerator to the host if components are split into different places).This PR fixes the other half: individual component call sites that assumed every submodule already lives on that execution device. Several places moved a tensor to
device(the execution device) before handing it to a specific submodule, instead of that submodule's own device:This affects three component types across the major pipeline families (StableDiffusionPipeline, StableDiffusionXLPipeline, StableDiffusion3Pipeline, FluxPipeline, Flux2(Klein)Pipeline, WanPipeline, WanImageToVideoPipeline):
encode_prompt/_get_t5_prompt_embeds/_get_clip_prompt_embedsvae.encode/vae.decodecalls in each__call__, plusFlux2Pipeline.prepare_image_latents(its output wasn't being moved back to the execution device either)encode_image, plusrun_safety_checker's feature-extractor inputAlso fixes a real cross-device bug in
WanImageToVideoPipeline.prepare_latents, wherelatent_condition(fromvae.encode) andlatents_mean/latents_stdcould end up on different devices before being combined.Fixed the ~10 canonical/root pipelines by hand, then ran
make fix-copiesto propagate the text-encoder/image-encoder fixes to every# Copied fromderivative (89 more files). VAE fixes don't propagate this way (inline in__call__, not a copyable function) and are only applied to the canonical pipelines above.Before submitting
self-reviewskill on the diff?documentation guidelines, and
here are tips on formatting docstrings.
Who can review?
Anyone in the community is free to review the PR once the tests have passed. Feel free to tag
members/contributors who may be interested in your PR.