Skip to content

Conversation

@yiyixuxu
Copy link
Collaborator

@yiyixuxu yiyixuxu commented Dec 22, 2025

This PR adds support for QwenImageLayred, along with some refactor

QwenImage-Layered

testing script

import torch
from diffusers import ModularPipeline
from diffusers.utils import load_image

device = "cuda:0"
repo_id = "Qwen/Qwen-Image-Layered"

pipeline = ModularPipeline.from_pretrained(repo_id)
pipeline.load_components(torch_dtype=torch.bfloat16)
pipeline.to(device)
image = load_image("https://huggingface.co/datasets/YiYiXu/testing-images/resolve/main/halloween.png").convert("RGBA")

output_images = pipeline(
    image=image,
    negative_prompt=" ",
    num_inference_steps=50,
    resolution=640,
    generator=torch.Generator(device="cuda").manual_seed(777),
    use_en_prompt=True,
).images[0]
for i, image in enumerate(output_images):
    image.save(f"test1_output_{i}.png")

refactors

1. Introduced ConditionalPipelineBlocks base class

Added a new base class ConditionalPipelineBlocks that allows defining custom block selection logic via select_block() method. This generalizes how conditional/branching pipelines work:

class ConditionalPipelineBlocks(ModularPipelineBlocks):
    block_classes = []
    block_names = []
    
    def select_block(self, *input_names) -> Optional[str]:
        """Custom logic to select which sub-block to run."""
        raise NotImplementedError()

AutoPipelineBlocks now becomes a specialized subclass that auto-generates select_block() from block_trigger_inputs - the previous behavior is preserved .

get_execution_blocks(*trigger_inputs) still works, so we can still pre-determine which blocks will run without actually executing the pipeline.

2. Reorganized modular blocks into pipeline-specific files

Split the monolithic modular_blocks.py into separate files per pipeline variant for better maintainability:

modular_pipelines/qwenimage/
├── modular_blocks_qwenimage.py          
├── modular_blocks_qwenimage_edit.py    
├── modular_blocks_qwenimage_edit_plus.py 
├── modular_blocks_qwenimage_layered.py  

@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 merged commit 1903383 into main Jan 9, 2026
14 of 15 checks passed
@yiyixuxu yiyixuxu deleted the modular-qwen-layer branch January 9, 2026 09:38
@yiyixuxu
Copy link
Collaborator Author

yiyixuxu commented Jan 9, 2026

@DN6 @sayakpaul
I merged because I want to iterate quickly on mellon, feel free to take a look when you have time later

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.

3 participants