You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
How should ModularPipeline handle a component that failed to load? #15227
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:
fromdiffusersimportModularPipelinepipe=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.
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?
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.
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.
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
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.
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.
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".
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.
Activity
PrakshaaleJain commentedon Nov 10, 2026
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?
Register successful components first, then raise (or warn):
When
load_components()runs, let it finish loading all the components that succeed and attach them topipefirst. That way, even if an error is raised at the end (e.g., whennamesorworkflowis explicitly passed), the already-loaded models stay onpipeand don't need to be reloaded callingload_components()again orupdate_components()will only touch the missing component.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 itsImportError).raise RuntimeError(...) from cached_error) instead of failing later inside the block with anAttributeErrororTypeErroronNone.yiyixuxu commentedon Nov 10, 2026
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
PrakshaaleJain commentedon Nov 11, 2026
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.
sayakpaul commentedon Nov 13, 2026
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
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.
charchit7 commentedon Nov 16, 2026
+1 to the idea.
Two details that might keep it lean:
Noneand has a cached load error, include that error there (or chain it withraise ... from). No need to decide up front which components a workflow needs.update_componentsor a successfulload_componentsretry. 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".PrakshaaleJain commentedon Nov 16, 2026
Thanks @yiyixuxu and @sayakpaul!
Catching this in the block runner's
try...exceptis much cleaner. If a component isn't used by the block, execution proceeds unaffected. If the block fails on aNonecomponent, we simply chain the cached load error.Also fully agree with @charchit7's points on clearing
_failed_componentswhen updated/reloaded and updating the warning message.