Skip to content

Conversation

@yiyixuxu
Copy link
Collaborator

pipeline blocks are definitions - they're dynamically composable. you can add, remove, combine, or swap blocks.
Pipelines are stateful, and modifying the blocks attribute on a pipeline directly won't update the pipeline's internal state correctly.

This change makes blocks a property that returns a deepcopy, so users can't change the blocks and expect it to work. e.g. if you do something like this, the original pipeline would still work (currently it does not)

pipe = ModularPipeline.from_pretrained()
text_block = pipe.blocks.sub_blocks.pop("text_encoder")

@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 review from DN6, Copilot and sayakpaul and removed request for Copilot January 22, 2026 03:23
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.

Important fix! Let's also add a mini test case for this?

@DN6
Copy link
Collaborator

DN6 commented Feb 2, 2026

Just seeking some clarification. In this PR we want to enforce the fact that blocks cannot/should not be modified after the pipeline is initialized? If we want to customize the blocks in a pipeline, it should happen before the pipeline is created? Am I understanding that correctly?

If that is the intent, the change is good with me. Something to consider about the provided example pipe.blocks.sub_blocks.pop("text_encoder"); a pop method typically implies that an element has been removed from a collection. So a user trying this might expect the block to be gone. And now it won't be.

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.

4 participants