According to recent reports, modular Diffusers introduces a upcoming way to build diffusion pipelines by composing reusable blocks. Instead of writing entire pipelines from scratch, you can mix and match blocks to create workflows tailored to your needs! This complements the existing DiffusionPipeline class with a more flexible, composable alternative.
In this post, we'll walk through how Modular Diffusers works β from the familiar API to run a modular pipeline, to building fully custom blocks and composing them into your own workflow. We'll also show how it integrates with Mellon, a node-based visual workflow interface that you can use to wire Modular Diffusers blocks together.
Here is a simple example of how to run inference with FLUX.2 Klein 4B using pre-built blocks:.
You get the same results as with a standard DiffusionPipeline, but the pipeline is very different under the hood: it's composed of flexible blocks β text encoding, image encoding, denoising, and decoding β that you can inspect directly:.
Each block is self-contained with its own inputs and outputs. You can run any block independently as its own pipeline, or add, remove, and swap blocks freely β they dynamically recompose to work with whatever blocks remain. Use .init_pipeline() to convert blocks into a runnable pipeline, and .load_components() to load the model weights.
For more on block types, composition patterns, lazy loading, and memory management with ComponentsManager, check out the Modular Diffusers documentation.
Recent findings suggest that modular Diffusers really shines when creating your own blocks. A custom block is a Python class that defines its components, inputs, outputs, and computation logic β and once defined, you can plug it into any workflow.
Here's an example block that extracts depth maps from images using Depth Anything V2.
It has been revealed that let's use this block with Qwen's ControlNet workflow. Extract the ControlNet workflow and insert the depth block at the beginning:.
Blocks in a sequence share data automatically: the depth block's control_image output flows to downstream blocks that need it, and its image input becomes a pipeline input since no earlier block provides it.
You can publish your custom block to the Hub so anyone can load it with trust_remote_code=True. We've created a template to get you started β check out the Building Custom Blocks guide for the full walkthrough.
The DepthProcessorBlock from this post is published at diffusers/depth-processor-custom-block β you can load and use it directly:.
We've published a collection of ready-to-use custom blocks here.
ModularPipeline.from_pretrained works with any existing Diffusers repo out of the box, but Modular Diffusers also introduces a fresh kind of repo: the Modular Repository.
Sources indicate that A modular repository is able to reference components from their original model repos. For example, diffusers/flux2-bnb-4bit-modular contains a quantized transformer and loads the remaining components from the original repo.
Modular repositories can also host custom pipeline blocks as Python code and visual UI configurations for tools like Mellon β all in one place.
The community has already started building complete pipelines with Modular Diffusers and publishing them on the Hub, with model weights and ready-to-run code.
Teams can build novel architectures, package them as blocks, and publish the entire pipeline on the Hub for anyone to use with ModularPipeline.from_pretrained.
Check out the full collection of community pipelines for more.
π‘ Mellon is in early development and not ready for production use yet. Consider this a sneak peek of how the integration works!
Sources indicate that mellon is a node graph interface integrated with Modular Diffusers. If you're familiar with node-based tools like ComfyUI, you'll feel right at home β but there are some key differences:.
This integration is possible because every block exposes the same properties (inputs, intermediate_outputs, expected_components). This consistent API means Mellon can automatically generate a node's UI from any block definition and compose blocks into higher-level nodes.
In a recent development, for example, diffusers/FLUX.2-klein-4B-modular contains a pipeline definition, component references, and a mellon_pipeline_config.json β all in one repo. Load it in Python with ModularPipeline.from_pretrained("diffusers/FLUX.2-klein-4B-modular") or in Mellon to create either a single-node or multi-node workflow.
Here's a quick example. We add a Gemini prompt expansion node β hosted as a modular repo at diffusers/gemini-prompt-expander-mellon β to an existing text-to-image workflow:.
Industry observers note that gemini expands your short prompt into a detailed description before generating the image. No code, no configuration β just a Hub repo id.
According to recent reports, this is just one example. For a detailed walkthrough, check out the Mellon x Modular Diffusers guide. You can also check out this video!
It has been revealed that modular Diffusers brings the composability and flexibility the community has been asking for, without compromising the features that make Diffusers powerful. It's still early β we want your input to shape what comes next. Give it a try and tell us what works, what doesn't, and what's missing.
Thanks to Chun Te Lee for the thumbnail, and to Poli, Pedro, Lysandre, Linoy, Aritra, and Steven for their thoughtful reviews.
In a recent development, this is such a well written blog post! Thanks to the diffusers team for blessing us with this.