---
title: custom-block-template
canonical_url: "https://www.modelscope.cn/models/hf-diffusers/custom-block-template"
md_url: "https://www.modelscope.cn/models/hf-diffusers/custom-block-template.md"
repository: hf-diffusers/custom-block-template
last_updated: 2026-02-08
license: apache-2.0
library_name:
  - pytorch
frameworks:
  - pytorch
downloads: 29
stars: 0
---

# custom-block-template

> custom-block-template - hf-diffusers 在 ModelScope 开源的模型。Custom Block Template

hf-diffusers/custom-block-template 是 ModelScope 魔搭社区上的机器学习模型，采用 apache-2.0 许可。

- **Repository**: hf-diffusers/custom-block-template
- **License**: apache-2.0
- **Downloads**: 29
- **Stars**: 0
- **Last updated**: 2026-02-08

Source: https://www.modelscope.cn/models/hf-diffusers/custom-block-template

---

# 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
```python
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
```python
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
```python
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](https://github.com/cubiq/Mellon), add `metadata={"mellon": "<type>"}` to your InputParam/OutputParam definitions, then generate the config:
```python
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](https://huggingface.co/docs/diffusers/main/en/modular_pipelines/mellon_custom_blocks) for more details.
