Skip to content

fix: Add type validation to prevent crashes from pipeline signature mismatches (#6969)#14070

Open
C1-BA-B1-F3 wants to merge 2 commits into
huggingface:mainfrom
C1-BA-B1-F3:fix-issue-6969-type-checking
Open

fix: Add type validation to prevent crashes from pipeline signature mismatches (#6969)#14070
C1-BA-B1-F3 wants to merge 2 commits into
huggingface:mainfrom
C1-BA-B1-F3:fix-issue-6969-type-checking

Conversation

@C1-BA-B1-F3

Copy link
Copy Markdown

Description

This PR fixes #6969 by adding type validation to _fetch_class_library_tuple to prevent cryptic crashes when pipeline components have signature mismatches.

Problem

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:

AttributeError: 'bool' object has no attribute '__module__'

Solution

Added validation in _fetch_class_library_tuple to check for __module__ attribute before accessing it. When invalid types are passed, a clear TypeError is raised with actionable guidance:

TypeError: Expected a module or class instance for pipeline component, but received bool: True. 
This is likely due to a signature mismatch in a pipeline's __init__ method. 
If you are using a custom pipeline, please ensure it matches the signature of the base pipeline class. 
For example, if inheriting from StableDiffusionPipeline, ensure your __init__ accepts all parameters 
including 'image_encoder' (added in recent versions).

Testing

  • Added test script test_fix_6969.py that verifies:
    • Valid modules still work correctly
    • Passing bool, int, or str raises TypeError with descriptive message
  • All existing pipeline tests pass (56 passed, 33 skipped)

Impact

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

…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.
@github-actions github-actions Bot added fixes-issue size/M PR with diff < 200 LOC pipelines and removed size/M PR with diff < 200 LOC labels Jun 25, 2026
@github-actions github-actions Bot added the size/S PR with diff < 50 LOC label Jun 25, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Expanded init fields in StableDiffusionPipeline cause incompatibilities with many/most inherited pipelines

1 participant