Skip to content

[modular] fallback to default_blocks_name when loading base block classes in ModularPipeline#13193

Open
yiyixuxu wants to merge 1 commit intomainfrom
fix-modular-pipeline-blocks-fallback
Open

[modular] fallback to default_blocks_name when loading base block classes in ModularPipeline#13193
yiyixuxu wants to merge 1 commit intomainfrom
fix-modular-pipeline-blocks-fallback

Conversation

@yiyixuxu
Copy link
Collaborator

@yiyixuxu yiyixuxu commented Feb 27, 2026

so that we are able to correctly load repos like https://huggingface.co/diffusers/flux2-modular

When creating a pipeline using SequentialPipelineBlocks.from_blocks_dict() and saving it, the modular_model_index.json stores _blocks_class_name as "SequentialPipelineBlocks". On loading, from_pretrained tries to instantiate SequentialPipelineBlocks() directly, which has empty block_classes and produces a broken pipeline.

from diffusers import ModularPipeline
pipe = ModularPipeline.from_pretrained("diffusers/flux2-modular")
print(pipe.blocks)

under main, it won't be able to map to Flux2AutoBlocks

>>> print(pipe.blocks)
SequentialPipelineBlocks(
  Class: ModularPipelineBlocks

  Description: 


  Sub-Blocks:
)

This PR added a fallback behavior in ModularPipeline.__init__ method so if the resolved blocks class is not importable from our library or has empty block_classes (i.e., it's a base class like SequentialPipelineBlocks, ConditionalPipelineBlocks, etc.), fall back to the pipeline's default_blocks_name .

@yiyixuxu yiyixuxu requested a review from DN6 February 27, 2026 09:46
@HuggingFaceDocBuilderDev

The docs for this PR live here. All of your documentation changes will be reflected on that endpoint. The docs are available until 30 days after the last update.

@yiyixuxu yiyixuxu requested a review from sayakpaul February 27, 2026 09:49
Copy link
Member

@sayakpaul sayakpaul left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Was just thinking about this today. Thanks!

assert not hasattr(pipe, "test_component") or pipe.test_component is None


class TestModularPipelineInitFallback:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is perfect test! I will try to make it available to other pipelines in #13192.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants