Modular Diffusers Custom Blocks
Collection
Custom blocks for Modular Diffusers
•
10 items
•
Updated
•
2
A template for creating custom ModularPipelineBlocks. Use this as a starting point for building your own blocks.
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
Open block.py and implement your custom block:
descriptionexpected_components if your block needs modelsinputs with your input parametersintermediate_outputs with your output parameters__call__from diffusers import ModularPipelineBlocks
blocks = ModularPipelineBlocks.from_pretrained(local_dir, trust_remote_code=True)
pipeline = blocks.init_pipeline()
output = pipeline(...) # your inputs here
pipeline.save_pretrained(local_dir, repo_id="your-username/your-block-name", push_to_hub=True)
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.