Skip to content

[Modular] mellon doc etc#13051

Merged
yiyixuxu merged 30 commits intomainfrom
more-mellon-related
Feb 3, 2026
Merged

[Modular] mellon doc etc#13051
yiyixuxu merged 30 commits intomainfrom
more-mellon-related

Conversation

@yiyixuxu
Copy link
Collaborator

@yiyixuxu yiyixuxu commented Jan 29, 2026

mellon related, added a mellon guide in this PR as well

#!/usr/bin/env python
"""
Utility script for working with custom Mellon blocks.

Usage:
    # Download a custom block for editing
    python yiyi_mellon_utils.py download --repo diffusers-internal-dev/gemini-prompt-expander
    python yiyi_mellon_utils.py download --repo diffusers-internal-dev/gemini-prompt-expander --local-dir my-block
    python yiyi_mellon_utils.py download  # uses template when no repo provided
    
    # Generate and push Mellon config
    python yiyi_mellon_utils.py push-config --local-dir gemini-prompt-expander --repo YiYiXu/gemini-test
    python yiyi_mellon_utils.py push-config --local-dir gemini-prompt-expander  # pushes to same name as local_dir
"""

import argparse
from diffusers import ModularPipelineBlocks
from diffusers.modular_pipelines.mellon_node_utils import MellonPipelineConfig


TEMPLATE_REPO = "diffusers/custom-block-template"


def download(repo_id: str = None, local_dir: str = None):
    """Download a custom block from Hub for editing."""
    if repo_id is None:
        repo_id = TEMPLATE_REPO
        print(f"No --repo provided, using template: {repo_id}")
    
    if local_dir is None:
        local_dir = repo_id.split("/")[-1]
    
    print(f"Downloading {repo_id} to {local_dir}/")
    blocks = ModularPipelineBlocks.from_pretrained(
        repo_id, 
        trust_remote_code=True, 
        local_dir=local_dir
    )
    print(f"Done! Edit your block in {local_dir}/")
    return blocks


def push_config(local_dir: str, repo_id: str = None):
    """Generate Mellon config and push to Hub."""
    if local_dir is None:
        raise ValueError("--local-dir is required")
    
    if repo_id is None:
        repo_id = local_dir
        print(f"No --repo provided, will push to {repo_id}")
    
    print(f"Loading blocks from {local_dir}/")
    blocks = ModularPipelineBlocks.from_pretrained(local_dir, trust_remote_code=True)
    
    print("Generating Mellon config...")
    mellon_config = MellonPipelineConfig.from_custom_block(blocks)
    
    print(f"Pushing to {repo_id}...")
    mellon_config.save(
        save_directory=local_dir,
        repo_id=repo_id,
        push_to_hub=True
    )
    print(f"Done! Config pushed to https://huggingface.co/{repo_id}")


def main():
    parser = argparse.ArgumentParser(description="Utility for working with custom Mellon blocks")
    subparsers = parser.add_subparsers(dest="command", required=True)
    
    # Download command
    dl_parser = subparsers.add_parser("download", help="Download a custom block for editing")
    dl_parser.add_argument("--repo", type=str, help="Hub repo ID to download (default: template)")
    dl_parser.add_argument("--local-dir", type=str, help="Local directory to save to (default: repo name)")
    
    # Push config command
    push_parser = subparsers.add_parser("push-config", help="Generate and push Mellon config")
    push_parser.add_argument("--local-dir", type=str, required=True, help="Local directory with the block")
    push_parser.add_argument("--repo", type=str, help="Hub repo ID to push to (default: same as local-dir)")
    
    args = parser.parse_args()
    
    if args.command == "download":
        download(repo_id=args.repo, local_dir=args.local_dir)
    elif args.command == "push-config":
        push_config(local_dir=args.local_dir, repo_id=args.repo)


if __name__ == "__main__":
    main()

@HuggingFaceDocBuilderDev

The docs for this PR live here. All of your documentation changes will be reflected on that endpoint. The docs are available until 30 days after the last update.

@yiyixuxu yiyixuxu requested a review from sayakpaul January 29, 2026 04:30
@yiyixuxu
Copy link
Collaborator Author

still working on a couple other things in this PR but mellon guide is ready for review @sayakpaul @asomoza

Copy link
Member

@sayakpaul sayakpaul left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you! Looks great

- Drag a **Dynamic Block Node** from the ModularDiffusers section
- Enter your `repo_id` (e.g., `YiYiXu/gemini-prompt-expander`)
- Click **Load Custom Block**
- The node will transform to show your block's inputs and outputs No newline at end of file
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe show a screenshot of how it should render?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i will make a short video clip maybe:)

@yiyixuxu yiyixuxu requested a review from stevhliu January 31, 2026 09:12
| `video` | Both | Video |
| `text` | Both | Text display |
| `textbox` | Input | Text input |
| `dropdown` | Input | Dropdown selection menu |
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was trying to create this from the block itself, we can set the dropdown but can we also set the options?

Copy link
Member

@stevhliu stevhliu left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thanks for the new guide!

yiyixuxu and others added 8 commits February 3, 2026 05:39
Co-authored-by: Steven Liu <59462357+stevhliu@users.noreply.github.com>
Co-authored-by: Steven Liu <59462357+stevhliu@users.noreply.github.com>
Co-authored-by: Steven Liu <59462357+stevhliu@users.noreply.github.com>
@yiyixuxu yiyixuxu merged commit 6d4fc6b into main Feb 3, 2026
16 checks passed
@yiyixuxu yiyixuxu deleted the more-mellon-related branch February 3, 2026 23:39
@yiyixuxu
Copy link
Collaborator Author

yiyixuxu commented Feb 4, 2026

@sayakpaul @stevhliu
I addressed all your feedback, but feel free to open a PR to update more if you see anything you want to improve
i uploaded a video too, but I think the text are a bit too small to be able to read clearly, will probably do a new one soom https://huggingface.co/docs/diffusers/main/en/modular_diffusers/mellon

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants