fix: move conditioning tensors to model device when partial loading enabled#8970
Open
aayushbaluni wants to merge 1 commit intoinvoke-ai:mainfrom
Open
fix: move conditioning tensors to model device when partial loading enabled#8970aayushbaluni wants to merge 1 commit intoinvoke-ai:mainfrom
aayushbaluni wants to merge 1 commit intoinvoke-ai:mainfrom
Conversation
…nabled When enable_partial_loading is true, conditioning embeddings from compel may remain on CPU while the UNet model is on CUDA. Passing CPU tensors to the CUDA model causes RuntimeError: Expected all tensors on same device. Ensure all conditioning tensors (embeds, pooled_embeds, add_time_ids) are moved to the same device as the input tensor x before calling model_forward_callback, in both batch and sequential conditioning paths. Fixes invoke-ai#8850
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.
Summary
Fixes #8850
When
enable_partial_loadingis true, conditioning embeddings from compel may remain on CPU while the UNet model is on CUDA. This causes aRuntimeError: Expected all tensors to be on the same deviceduring denoising.Root Cause
The
_apply_standard_conditioningand_apply_standard_conditioning_sequentiallymethods pass conditioning tensors (.embeds,.pooled_embeds,.add_time_ids) directly tomodel_forward_callbackwithout ensuring they are on the same device as the model inputx. When partial loading offloads conditioning data to CPU to save VRAM, these tensors stay on CPU while the model expects CUDA tensors.Fix
Before each
model_forward_callbackcall, explicitly move conditioning tensors tox.device:uncond_text.embedsandcond_text.embedsvia.to(x.device)added_cond_kwargs(SDXLtext_embedsandtime_ids) via.to(x.device)Applied to both the batch path (
_apply_standard_conditioning) and the sequential path (_apply_standard_conditioning_sequentially).Test Plan
enable_partial_loadingin InvokeAI configRuntimeError: Expected all tensors to be on the same deviceMade with Cursor