Update README.md
Browse files
README.md
CHANGED
|
@@ -1,3 +1,60 @@
|
|
| 1 |
-
---
|
| 2 |
-
license: apache-2.0
|
| 3 |
-
---
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
---
|
| 2 |
+
license: apache-2.0
|
| 3 |
+
---
|
| 4 |
+
# Custom Block Template
|
| 5 |
+
|
| 6 |
+
A template for creating custom ModularPipelineBlocks. Use this as a starting point for building your own blocks.
|
| 7 |
+
|
| 8 |
+
## Getting Started
|
| 9 |
+
|
| 10 |
+
### 1. Download the template
|
| 11 |
+
```python
|
| 12 |
+
from diffusers import ModularPipelineBlocks
|
| 13 |
+
|
| 14 |
+
model_id = "diffusers/custom-block-template"
|
| 15 |
+
local_dir = model_id.split("/")[-1]
|
| 16 |
+
|
| 17 |
+
blocks = ModularPipelineBlocks.from_pretrained(
|
| 18 |
+
model_id,
|
| 19 |
+
trust_remote_code=True,
|
| 20 |
+
local_dir=local_dir
|
| 21 |
+
)
|
| 22 |
+
```
|
| 23 |
+
|
| 24 |
+
This saves the template files to `custom-block-template/` locally. Feel free to use a custom `local_dir`
|
| 25 |
+
|
| 26 |
+
### 2. Edit locally
|
| 27 |
+
|
| 28 |
+
Open `block.py` and implement your custom block:
|
| 29 |
+
- Update the class name and `description`
|
| 30 |
+
- Define `expected_components` if your block needs models
|
| 31 |
+
- Define `inputs` with your input parameters
|
| 32 |
+
- Define `intermediate_outputs` with your output parameters
|
| 33 |
+
- Implement your logic in `__call__`
|
| 34 |
+
|
| 35 |
+
|
| 36 |
+
### 3. Test your block
|
| 37 |
+
```python
|
| 38 |
+
from diffusers import ModularPipelineBlocks
|
| 39 |
+
|
| 40 |
+
blocks = ModularPipelineBlocks.from_pretrained(local_dir, trust_remote_code=True)
|
| 41 |
+
pipeline = blocks.init_pipeline()
|
| 42 |
+
output = pipeline(...) # your inputs here
|
| 43 |
+
```
|
| 44 |
+
|
| 45 |
+
### 4. Upload to the Hub
|
| 46 |
+
```python
|
| 47 |
+
pipeline.save_pretrained(local_dir, repo_id="your-username/your-block-name", push_to_hub=True)
|
| 48 |
+
```
|
| 49 |
+
|
| 50 |
+
## Adding Mellon Support
|
| 51 |
+
|
| 52 |
+
To use your block in [Mellon](https://github.com/cubiq/Mellon), add `metadata={"mellon": "<type>"}` to your InputParam/OutputParam definitions, then generate the config:
|
| 53 |
+
```python
|
| 54 |
+
from diffusers.modular_pipelines.mellon_node_utils import MellonPipelineConfig
|
| 55 |
+
|
| 56 |
+
mellon_config = MellonPipelineConfig.from_custom_block(blocks)
|
| 57 |
+
mellon_config.save(local_dir, repo_id="your-username/your-block-name", push_to_hub=True)
|
| 58 |
+
```
|
| 59 |
+
|
| 60 |
+
See the [Mellon integration guide](https://huggingface.co/docs/diffusers/main/en/modular_pipelines/mellon_custom_blocks) for more details.
|