-
Notifications
You must be signed in to change notification settings - Fork 88
feat(diffusers/pipelines): add pipelines and required modules of QwenImage in Diffusers Master #1288
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
base: master
Are you sure you want to change the base?
Conversation
clean no-use notes
add model seamless_m4t
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Summary of Changes
Hello @Dong1017, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!
This pull request integrates the QwenImage model family into the Diffusers library, providing a robust set of pipelines for various image generation and editing tasks. It introduces specialized model architectures and utilities tailored for QwenImage's unique features, enhancing the library's capabilities for advanced diffusion models.
Highlights
- New QwenImage Integration: Comprehensive support for QwenImage models has been added, including its unique VAE and Transformer architectures, enabling advanced image generation capabilities.
- Diverse Pipeline Support: Five distinct pipelines for QwenImage have been introduced: text-to-image, image-to-image, inpainting, editing, and combined edit-inpainting, offering a wide range of functionalities.
- Custom Model Components: Specialized components like
AutoencoderKLQwenImage
with causal 3D convolutions andQwenImageTransformer2DModel
featuring dual-stream attention and rotary embeddings have been implemented. - LoRA Loading Capability: The
QwenImageLoraLoaderMixin
and associated conversion utilities were added to enable seamless loading of LoRA checkpoints for QwenImage models. - MindSpore Compatibility Enhancements: Core utilities related to attention processing, weight normalization, and model loading have been updated to ensure full compatibility and optimized performance within the MindSpore framework.
- Comprehensive Unit Testing: New unit tests have been included for all newly added QwenImage pipelines, ensuring their correctness and stability.
Using Gemini Code Assist
The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.
Invoking Gemini
You can request assistance from Gemini at any point by creating a comment using either /gemini <command>
or @gemini-code-assist <command>
. Below is a summary of the supported commands on the current page.
Feature | Command | Description |
---|---|---|
Code Review | /gemini review |
Performs a code review for the current pull request in its current state. |
Pull Request Summary | /gemini summary |
Provides a summary of the current pull request in its current state. |
Comment | @gemini-code-assist | Responds in comments when explicitly tagged, both in pull request comments and review comments. |
Help | /gemini help |
Displays a list of available commands. |
Customization
To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/
folder in the base of the repository. Detailed instructions can be found here.
Limitations & Feedback
Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here.
You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.
Footnotes
-
Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution. ↩
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Code Review
This pull request introduces support for QwenImage pipelines and their associated modules into the Diffusers library. The changes are extensive, including new pipelines for text-to-image, image-to-image, inpainting, and editing, as well as the necessary model components like AutoencoderKLQwenImage
and QwenImageTransformer2DModel
. My review has identified several critical syntax errors in the newly added test files that will prevent them from running. Additionally, there are some documentation errors, including incorrect model identifiers and type hints, and a notable performance issue in the blending logic within the VAE model that could be significantly improved with vectorization. Addressing these points will enhance the correctness, usability, and performance of this new feature.
tests/diffusers_tests/pipelines/qwenimage/test_qwenimage_edit.py
Outdated
Show resolved
Hide resolved
tests/diffusers_tests/pipelines/qwenimage/test_qwenimage_edit.py
Outdated
Show resolved
Hide resolved
tests/diffusers_tests/pipelines/qwenimage/test_qwenimage_img2img.py
Outdated
Show resolved
Hide resolved
tests/diffusers_tests/pipelines/qwenimage/test_qwenimage_inpaint.py
Outdated
Show resolved
Hide resolved
adapter_name=adapter_name, | ||
metadata=metadata, | ||
_pipeline=_pipeline, | ||
low_cpu_mem_usage=low_cpu_mem_usage, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
可以先删掉 我们暂时还不支持
) | ||
encoder_hidden_states = self.text_encoder( | ||
input_ids=ms.Tensor(txt_tokens.input_ids), | ||
attention_mask=ms.Tensor(txt_tokens.attention_mask), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
tensor使用优先ms.tensor 后面应该还有一些类似Tensor的问题
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
其他pipeline也将进行对应修改
pt_pipe = pt_pipe.to(pt_dtype) | ||
ms_pipe = ms_pipe.to(ms_dtype) | ||
|
||
sys.modules[ms_pipe.__module__].randn_tensor = randn_tensor |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
为什么这里要单独替换呀?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
img2img pipe中单独替换以保证随机性一致;text2img, inpaint, edit pipes中无需单独设置,将删除冗余行
How to fix the requirement of |
) | ||
latents = latents / latents_std + latents_mean | ||
# TODO: we use pynative mode here since cache in vae.decode which not supported in graph mode | ||
with pynative_context(): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is it necessary? since the default MS mode and the supported mode is pynative?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the review. with pynative_context()
will be removed, since the double-check shows that its impact on results is minimal. Tests for all pipelines are doing.
[CLIPTokenizer](https://huggingface.co/docs/transformers/en/model_doc/clip#transformers.CLIPTokenizer). | ||
""" | ||
|
||
model_cpu_offload_seq = "text_encoder->transformer->vae" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is the offloading seq supported?
Can add an inference example and lora fine-tune example in |
What does this PR do?
Adds
1. QwenImage Pipelines and Required Modules
(Comparable with Diffusers Master)
a. Pipelines
mindone.diffusers.QwenImagePipeline
mindone.diffusers.QwenImageImg2ImgPipeline
mindone.diffusers.QwenImageInpaintPipeline
mindone.diffusers.QwenImageEditPipeline
mindone.diffusers.QwenImageEditInpaintPipeline
b. Modules
mindone.diffusers.models.AutoencoderQwenImage
mindone.diffusers.models.QwenImageTransformer2DModel
mindone.diffusers.loaders.QwenImageLoraLoaderMixin
2. add UTs of pipelines — all passed
(targeting Diffusers Master)
tests/diffusers_tests/pipelines/qwenimage/test_qwenimage.py
tests/diffusers_tests/pipelines/qwenimage/test_qwenimage_img2img.py
tests/diffusers_tests/pipelines/qwenimage/test_qwenimage_inpaint.py
tests/diffusers_tests/pipelines/qwenimage/test_qwenimage_edit.py
Usage
Performance
(Infer experiments are tested on Ascend Atlas 800T A2 machines with MindSpore 2.7.0, setting to pynative mode)
Limitation
QwenImageEditPipeline
andQwenImageEditInpaintPipeline
will load modules from Qwen-Image-Edit. The use of these two pipes requires manually changingimage_processor_type
fromQwen2VLImageProcessorFast
toQwen2VLImageProcessor
inQwen-Image-Edit/processor/preprocessor_config.json
Notes
random seed
andhidden states
from the text encoder.Before submitting
What's New
. Here are thedocumentation guidelines
Who can review?
Anyone in the community is free to review the PR once the tests have passed. Feel free to tag
members/contributors who may be interested in your PR.
@xxx