How should `ModularPipeline` handle a component that failed to load?

Open
#15,227 6 comments 0 reactions 0 assignees View on GitHub

Maintainers usually reply within 1 day

Nobody has claimed this yet.

Assessment

Difficulty
5/5
Estimated time
Over a week
Newbie friendliness
15/100
Issue type
Feature
Clarity
Needs clarification
Activity status
Active
Tech stack
python, pytorch
Domain
ai

Research direction

Start in ModularPipeline.load_components, where each component load sits inside a try/except that logs a warning and leaves None. The example reproduces through Qwen2VLProcessor raising an ImportError for missing torchvision, so trace how that error reaches the modular path. Done means maintainers have agreed on whether a failed load should raise, be marked as deferred, or stay a warning, and that decision is recorded in the thread before any code is written.

Written by the indexing model from the issue text.

Description

idea-contribution-welcome
What happens today

ModularPipeline.load_components wraps every component load in try/except. When one fails, it logs a warning and carries on with the others, leaving None for the component that failed.

My motivation for this was that loading is a time-consuming process, and one failure should not force the user to load everything again. If the component is optional (e.g. a safety checker that needs an external dependency that is not installed), they can simply skip it. If it is required and failed for a legitimate reason (e.g. a missing dependency), it is better that they load it separately and pass it with update_components than reload everything.

The other side of this is that a warning is not loud enough. If you do not notice it, the failure comes back at run time as an AttributeError or TypeError on None inside a block, far from the warning that explained the cause. In diffusers we prefer things to be explicit, and silently carrying on with a None component is not.

Example

Qwen2VLProcessor bundles a video processor that only has a torchvision implementation, and torchvision is not installed by diffusers or transformers. In an environment without it:

from diffusers import ModularPipeline

pipe = ModularPipeline.from_pretrained("Qwen/Qwen-Image-Edit")
pipe.load_components(names=["tokenizer", "processor"])
# logs: Failed to create component processor: ... you can safely ignore this message ...
#       ImportError: Qwen2VLVideoProcessor requires the Torchvision library but it was not found in your environment.
print(pipe.processor)  # None

Running the pipeline afterwards fails in the text encoder block when it calls the None processor. Loading the same processor directly, or through DiffusionPipeline.from_pretrained, raises the ImportError right away, so this only happens on the modular path.

Feedback and suggestions welcome.

Opened by Claude on behalf of @yiyixuxu

Dominant language
Python
Stars
35k
Forks
7.5k
Avg merge
2d 22h
Merged PRs (30d)
58

Getting set up

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from huggingface/diffusers

All issues in huggingface/diffusers

Similar issues

More Python issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.