Custom Block Template

A template for creating custom ModularPipelineBlocks. Use this as a starting point for building your own blocks.

Getting Started

1. Download the template

from diffusers import ModularPipelineBlocks

model_id = "diffusers/custom-block-template"
local_dir = model_id.split("/")[-1]

blocks = ModularPipelineBlocks.from_pretrained(
    model_id, 
    trust_remote_code=True, 
    local_dir=local_dir
)

This saves the template files to custom-block-template/ locally. Feel free to use a custom local_dir

2. Edit locally

Open block.py and implement your custom block:

  • Update the class name and description
  • Define expected_components if your block needs models
  • Define inputs with your input parameters
  • Define intermediate_outputs with your output parameters
  • Implement your logic in __call__

3. Test your block

from diffusers import ModularPipelineBlocks

blocks = ModularPipelineBlocks.from_pretrained(local_dir, trust_remote_code=True)
pipeline = blocks.init_pipeline()
output = pipeline(...)  # your inputs here

4. Upload to the Hub

pipeline.save_pretrained(local_dir, repo_id="your-username/your-block-name", push_to_hub=True)

Adding Mellon Support

To use your block in Mellon, add metadata={"mellon": "<type>"} to your InputParam/OutputParam definitions, then generate the config:

from diffusers.modular_pipelines.mellon_node_utils import MellonPipelineConfig

mellon_config = MellonPipelineConfig.from_custom_block(blocks)
mellon_config.save(local_dir, repo_id="your-username/your-block-name", push_to_hub=True)

See the Mellon integration guide for more details.

Downloads last month

-

Downloads are not tracked for this model. How to track
Inference Providers NEW
This model isn't deployed by any Inference Provider. 🙋 Ask for provider support

Collection including diffusers/custom-block-template