fix(pipeline): preserve original pipeline dtype in from_pipe() by default#13964
Open
Liauuu wants to merge 1 commit into
Open
fix(pipeline): preserve original pipeline dtype in from_pipe() by default#13964Liauuu wants to merge 1 commit into
Liauuu wants to merge 1 commit into
Conversation
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.
Description
Fixes #12754
Currently,
from_pipe()forces the newly created pipeline (and its shared components) tofloat32by default unlesstorch_dtypeis explicitly provided. This causes unexpected VRAM spikes, CUDA OOMs, and introduces a regression in developer experience (DX) when working withfloat16orbfloat16pipelines.This PR modifies
from_pipe()to automatically infer and inherit the source pipeline'sdtypeif the user leavestorch_dtype=None.Safety & Edge Case Defense
To perfectly guard against the edge case where shared components might have mixed dtypes:
torch.nn.Modulecomponents insidepipeline.components.values().torch_dtypeif and only if all components share the exact same dtype (len(dtypes) == 1).torch_dtype = Noneand skips casting, maintaining the exact original state of the components without breaking any shared weight links.Testing
tests/pipelines/test_pipeline_utils.pychecking thatfrom_pipecorrectly inheritsfloat16and shares the same object reference without unwanted mutations.