fix: Add type validation to prevent crashes from pipeline signature mismatches (#6969)#14070
Open
C1-BA-B1-F3 wants to merge 2 commits into
Open
fix: Add type validation to prevent crashes from pipeline signature mismatches (#6969)#14070C1-BA-B1-F3 wants to merge 2 commits into
C1-BA-B1-F3 wants to merge 2 commits into
Conversation
…shes from signature mismatches Fixes huggingface#6969 When community pipelines inherit from StableDiffusionPipeline but don't update their __init__ signature to include new parameters like 'image_encoder', positional arguments can be misaligned. This causes non-module values (like booleans from 'requires_safety_checker') to be passed where modules are expected, resulting in cryptic AttributeError: 'bool' object has no attribute '__module__'. This fix adds validation in _fetch_class_library_tuple to check for __module__ attribute and raise a clear TypeError with actionable guidance when invalid types are passed.
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
This PR fixes #6969 by adding type validation to
_fetch_class_library_tupleto prevent cryptic crashes when pipeline components have signature mismatches.Problem
When community pipelines inherit from
StableDiffusionPipelinebut don't update their__init__signature to include new parameters likeimage_encoder, positional arguments can be misaligned. This causes non-module values (like booleans fromrequires_safety_checker) to be passed where modules are expected, resulting in:Solution
Added validation in
_fetch_class_library_tupleto check for__module__attribute before accessing it. When invalid types are passed, a clearTypeErroris raised with actionable guidance:Testing
test_fix_6969.pythat verifies:bool,int, orstrraisesTypeErrorwith descriptive messageImpact
This is a minimal, non-breaking change that only affects error handling. Valid modules continue to work as before, while invalid inputs now get a clear, actionable error message instead of a cryptic crash.
Fixes #6969