Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

[BUG] Misleading ValueError when subclassing StableDiffusionImg2ImgPipeline with a mismatched __init__ signature #12255

Closed
Labels
bugSomething isn't working
@BoostZhu

Description

Describe the bug

When subclassing diffusers.StableDiffusionImg2ImgPipeline, if the subclass's init signature does not include the requires_safety_checker: bool = True argument, the default .from_pretrained() loader raises a confusing and indirect ValueError.

The official documentation for StableDiffusionImg2ImgPipeline confirms that requires_safety_checker is an explicit keyword argument in its init signature.

The current ValueError (pasted below) reports a component list mismatch between 'kwargs' and 'requires_safety_checker'. This error message hides the true root cause—a TypeError from the signature mismatch—making the problem very difficult to debug.

Reproduction

The following minimal script reliably reproduces the error.


from diffusers import StableDiffusionImg2ImgPipeline
from diffusers.models import AutoencoderKL, UNet2DConditionModel
from diffusers.schedulers import KarrasDiffusionSchedulers
from transformers import CLIPTextModel, CLIPTokenizer
from typing import Optional, Any
# A custom pipeline inheriting from StableDiffusionImg2ImgPipeline,
# but with an incorrect __init__ signature. It incorrectly tries
# to catch `requires_safety_checker` with **kwargs.
class MyCustomPipeline(StableDiffusionImg2ImgPipeline):
 def __init__(
 self,
 vae: AutoencoderKL,
 text_encoder: CLIPTextModel,
 tokenizer: CLIPTokenizer,
 unet: UNet2DConditionModel,
 scheduler: KarrasDiffusionSchedulers,
 safety_checker: Optional[Any] = None,
 feature_extractor: Optional[Any] = None,
 image_encoder: Optional[Any] = None,
 **kwargs,
 ):
 super().__init__(
 vae=vae,
 text_encoder=text_encoder,
 tokenizer=tokenizer,
 unet=unet,
 scheduler=scheduler,
 safety_checker=safety_checker,
 feature_extractor=feature_extractor,
 image_encoder=image_encoder,
 **kwargs,
 )
# This line will fail and raise the misleading ValueError.
# It can be copy-pasted directly to reproduce the bug.
pipe = MyCustomPipeline.from_pretrained("runwayml/stable-diffusion-v1-5")

Logs

ValueError: MyCustomPipeline {
 "_class_name": "MyCustomPipeline",
 "_diffusers_version": "0.29.0.dev0", # Replace with your version
 "feature_extractor": [
 "transformers",
 "CLIPImageProcessor"
 ],
 "image_encoder": [
 null,
 null
 ],
 "requires_safety_checker": true,
 "safety_checker": [
 "stable_diffusion",
 "StableDiffusionSafetyChecker"
 ],
 "scheduler": [
 "diffusers",
 "PNDMScheduler"
 ],
 "text_encoder": [
 "transformers",
 "CLIPTextModel"
 ],
 "tokenizer": [
 "transformers",
 "CLIPTokenizer"
 ],
 "unet": [
 "diffusers",
 "UNet2DConditionModel"
 ],
 "vae": [
 "diffusers",
 "AutoencoderKL"
 ]
}
 has been incorrectly initialized or <class '__main__.MyCustomPipeline'> is incorrectly implemented. Expected ['feature_extractor', 'image_encoder', 'kwargs', 'safety_checker', 'scheduler', 'text_encoder', 'tokenizer', 'unet', 'vae'] to be defined, but ['feature_extractor', 'image_encoder', 'requires_safety_checker', 'safety_checker', 'scheduler', 'text_encoder', 'tokenizer', 'unet', 'vae'] are defined.

System Info

diffusers version: 0.34.0
Platform: Linux-5.15.0-78-generic-x86_64-with-glibc2.35
Python version: 3.12.11 | [GCC 11.2.0]
PyTorch version: 2.5.1+cu121

Who can help?

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions

        AltStyle によって変換されたページ (->オリジナル) /