Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Add Qwen-Image-Edit Inpainting pipeline #12225

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
yiyixuxu merged 10 commits into huggingface:main from Trgtuan10:qwen-image
Aug 31, 2025
Merged

Conversation

Copy link
Contributor

@Trgtuan10 Trgtuan10 commented Aug 23, 2025
edited
Loading

What does this PR do?

This PR introduces support for the Qwen-Image-Edit model in Inpainting tasks, expanding the model’s creative capabilities and integration within the Diffusers library.

Example code

import torch
from diffusers import QwenImageEditInpaintPipeline
from diffusers.utils import load_image
import os
os.environ["HF_ENABLE_PARALLEL_LOADING"] = "YES"
pipe = QwenImageEditInpaintPipeline.from_pretrained("Qwen/Qwen-Image-Edit", torch_dtype=torch.bfloat16)
pipe.to("cuda")
prompt = "change the hat to red"
negative_prompt = " "
source = load_image("https://github.com/Trgtuan10/Image_storage/blob/main/cute_cat.png?raw=true")
mask = load_image("https://github.com/Trgtuan10/Image_storage/blob/main/mask_cat.png?raw=true")
image = pipe(
 prompt=prompt,
 negative_prompt=negative_prompt,
 image=source,
 mask_image=mask,
 strength=1.0,
 num_inference_steps=35,
 true_cfg_scale=4.0,
 generator=torch.Generator(device="cuda").manual_seed(422)
).images[0]
image.save(f"qwen_inpainting.png")

Comparison about performance of QwenImage-Edit Inpaint

Init image
Mask
QwenImage Inpaint
QwenImage-Edit
QwenImage-Edit Inpaint

Who can review?

cc @a-r-r-o-w @sayakpaul

Alexios-hub, toyxyz, and Parthiban-3997 reacted with thumbs up emoji DanhVinhLe reacted with hooray emoji
Copy link
Member

Cc: @naykun as well.

Trgtuan10 and naykun reacted with heart emoji

Copy link
Contributor

naykun commented Aug 24, 2025

Hi @Trgtuan10 , that would be an amazing feature! It seems to preserve details better than the current QwenImageInpaintPipeline—great improvement!

I’ll dive in and run some more extensive tests on this PR shortly. Thanks so much for your contribution, and for helping push this forward! 🙌

TuanNT-ZenAI reacted with heart emoji

Copy link
Contributor

Thanks @naykun! Please feel free to test it out and let me know if you run into any issues.

Copy link
Contributor

Hi @naykun @sayakpaul, have you tested it yet? I'd appreciate any feedback or reviews!

Copy link
Contributor

naykun commented Aug 27, 2025

@Trgtuan10 I've tested it, and things are working well overall. This approach shows promise for handling complex editing scenarios while keeping the rest of the content unchanged. There are a few unstable cases where instructions don't always take effect, but I believe we can mitigate those with better prompts and strategic masking. I suggest we move forward with this PR.
cc @sayakpaul @yiyixuxu

Trgtuan10 reacted with heart emoji

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.

Thanks for this! I have two minor comments.

I think we should also add tests and docs. Thanks to @naykun for running the tests as well.

Copy link
Collaborator

@yiyixuxu yiyixuxu 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 for your PR!!
left some very small comments about #Copied from

Copy link
Contributor Author

Thanks for the reviews @sayakpaul @yiyixuxu. I’ve updated the code to stay up to date with the latest changes from the main branch. Please check it again.

Copy link
Collaborator

@bot /style

Copy link
Contributor

Style fix is beginning .... View the workflow run here.

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.

Copy link
Collaborator

oh CI still fail and style bot cannot fix
would you be able to fix it? just run make style and fix the format issues as listed

thanks!

TuanNT-ZenAI reacted with heart emoji

Copy link
Contributor

@yiyixuxu I just fixed

@yiyixuxu yiyixuxu merged commit 67ffa70 into huggingface:main Aug 31, 2025
10 checks passed
Copy link
Contributor

@yiyixuxu I just fixed

Hi,
I have read the code, and i'm confused why masked_image_latents is not used when send to DiT?

Copy link
Contributor Author

@xduzhangjiayu No problem, I don’t think anyone is using these parameters. Feel free to open a PR to make the code clearer

Copy link
Contributor

xduzhangjiayu commented Sep 1, 2025
edited
Loading

@Trgtuan10 We don't need to concat the masked_image_latents and latents for inpainting model?

Copy link
Contributor Author

Yes, we don't need. The mask is only used when creating latents after each step, code

Copy link
Contributor

Yes, we don't need. The mask is only used when creating latents after each step, code

Thanks! I understand, it's like a BLD inpainting

Trgtuan10 reacted with heart emoji

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

@sayakpaul sayakpaul sayakpaul left review comments

@yiyixuxu yiyixuxu yiyixuxu approved these changes

@asomoza asomoza Awaiting requested review from asomoza

Assignees
No one assigned
Labels
None yet
Projects
None yet
Milestone
No milestone
Development

Successfully merging this pull request may close these issues.

AltStyle によって変換されたページ (->オリジナル) /