Skip to content

How should ModularPipeline handle a component that failed to load? #15227

Open

Description

@yiyixuxu

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

Activity

  1. PrakshaaleJain commented on Nov 10, 2026

    @PrakshaaleJain
    Contributor

    Hi @yiyixuxu, what if we keep the non-blocking load behavior, but cache the load error per component and register the components that succeeded before raising?

    1. Register successful components first, then raise (or warn):
      When load_components() runs, let it finish loading all the components that succeed and attach them to pipe first. That way, even if an error is raised at the end (e.g., when names or workflow is explicitly passed), the already-loaded models stay on pipe and don't need to be reloaded calling load_components() again or update_components() will only touch the missing component.

    2. Cache failed components and surface the original error when used:
      If a component fails to load during load_components(), we can store the original exception on the pipeline (e.g., mapping the failed component name to its ImportError).

      • If the user's workflow never uses that component, the pipeline still runs normally without failing on an optional dependency.
      • If a block does need that component, we check before the block runs and re-raise the cached exception (raise RuntimeError(...) from cached_error) instead of failing later inside the block with an AttributeError or TypeError on None.
  2. yiyixuxu commented on Nov 10, 2026

    @yiyixuxu
    CollaboratorAuthor

    thanks @PrakshaaleJain
    i like the overall idea, but I think for (2), maybe instead of trying to figure out whether the components is needed we can just raise at run time when the block failed to run because a component is None with a cached load error

    would love to hear @sayakpaul @DN6 's thoughts on this too
    this is a small quality-of-life improvement, if we decide to go with a fix, it should be very lean & simple

  3. PrakshaaleJain commented on Nov 11, 2026

    @PrakshaaleJain
    Contributor

    Great discussion! Didnt foresee that a silent None component can cause a lot of confusion down the line. Caching the load error for runtime seems like a neat idea. Looking forward to seeing where this lands.

  4. added
    idea-contribution-welcomeWe want discussion, not a PR. feedbacks that help us will get co-author credit
    on Nov 11, 2026
  5. added this to the Release 0.44.0 milestone on Nov 13, 2026
  6. sayakpaul commented on Nov 13, 2026

    @sayakpaul
    Member

    I like @PrakshaaleJain's idea. We load all the successful components and then just raise for the ones that were not loaded. Particularly this bit from @yiyixuxu

    we can just raise at run time when the block failed to run because a component is None with a cached load error

    This way, we also cover the situation where we aren't raising unnecessarily for a component(s) that is not even needed to run something.

  7. charchit7 commented on Nov 16, 2026

    @charchit7
    Contributor

    +1 to the idea.

    Two details that might keep it lean:

    • The block runners already catch exceptions to log "Error in block: ..." before re-raising. That looks like the natural place for this: if one of the block's expected components is None and has a cached load error, include that error there (or chain it with raise ... from). No need to decide up front which components a workflow needs.
    • The cached error should be cleared when the component is set later, through update_components or a successful load_components retry. Otherwise an unrelated failure in that block could get blamed on a load error that was already fixed.

    Also, the current warning says "If this component is not required for your workflow you can safely ignore this message", which leaves the user to work out whether it's required. With the error cached, it could say what will happen instead, e.g. "this will raise when a block uses processor".

  8. PrakshaaleJain commented on Nov 16, 2026

    @PrakshaaleJain
    Contributor

    Thanks @yiyixuxu and @sayakpaul!
    Catching this in the block runner's try...except is much cleaner. If a component isn't used by the block, execution proceeds unaffected. If the block fails on a None component, we simply chain the cached load error.

    Also fully agree with @charchit7's points on clearing _failed_components when updated/reloaded and updating the warning message.

  9. removed this from the Release 0.44.0 milestone on Nov 17, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    idea-contribution-welcomeWe want discussion, not a PR. feedbacks that help us will get co-author credit

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions