-
Notifications
You must be signed in to change notification settings - Fork 6.5k
[modular] add tests for qwen modular #12585
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
Open
sayakpaul
wants to merge
26
commits into
main
Choose a base branch
from
qwen-modular
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+194
−123
Open
Changes from all commits
Commits
Show all changes
26 commits
Select commit
Hold shift + click to select a range
e35962b
add tests for qwenimage modular.
sayakpaul 94fa202
qwenimage edit.
sayakpaul 7d3c250
qwenimage edit plus.
sayakpaul 7334520
Merge branch 'main' into qwen-modular
sayakpaul 92d7977
Merge branch 'main' into qwen-modular
sayakpaul 7ad48f0
empty
sayakpaul 5821dd9
Merge branch 'main' into qwen-modular
sayakpaul d7a887b
Merge branch 'main' into qwen-modular
sayakpaul 42f0bf7
Merge branch 'main' into qwen-modular
sayakpaul 27a1c25
align with the latest structure
sayakpaul 5d52377
up
sayakpaul f191e93
Merge branch 'main' into qwen-modular
sayakpaul 2378461
up
sayakpaul 0e9d1a9
reason
sayakpaul 8144a0e
up
sayakpaul 650424e
fix multiple issues.
sayakpaul b75096b
up
sayakpaul 2c3ad62
Merge branch 'main' into qwen-modular
sayakpaul c8f814a
up
sayakpaul 3b0749f
Merge branch 'main' into qwen-modular
sayakpaul 75a7047
fix
sayakpaul 2515423
Merge branch 'main' into qwen-modular
sayakpaul 5eb121f
up
sayakpaul 6aa3b5c
make it similar to the original pipeline.
sayakpaul 6debf47
Merge branch 'main' into qwen-modular
sayakpaul 55c30cf
Merge branch 'main' into qwen-modular
sayakpaul File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -503,6 +503,8 @@ def __call__(self, components: QwenImageModularPipeline, state: PipelineState): | |
| block_state.prompt_embeds = block_state.prompt_embeds[:, : block_state.max_sequence_length] | ||
| block_state.prompt_embeds_mask = block_state.prompt_embeds_mask[:, : block_state.max_sequence_length] | ||
|
|
||
| block_state.negative_prompt_embeds = None | ||
| block_state.negative_prompt_embeds_mask = None | ||
|
Comment on lines
+506
to
+507
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Otherwise, no CFG settings would break. |
||
| if components.requires_unconditional_embeds: | ||
| negative_prompt = block_state.negative_prompt or "" | ||
| block_state.negative_prompt_embeds, block_state.negative_prompt_embeds_mask = get_qwen_prompt_embeds( | ||
|
|
@@ -627,6 +629,8 @@ def __call__(self, components: QwenImageModularPipeline, state: PipelineState): | |
| device=device, | ||
| ) | ||
|
|
||
| block_state.negative_prompt_embeds = None | ||
| block_state.negative_prompt_embeds_mask = None | ||
| if components.requires_unconditional_embeds: | ||
| negative_prompt = block_state.negative_prompt or " " | ||
| block_state.negative_prompt_embeds, block_state.negative_prompt_embeds_mask = get_qwen_prompt_embeds_edit( | ||
|
|
@@ -679,6 +683,8 @@ def __call__(self, components: QwenImageModularPipeline, state: PipelineState): | |
| device=device, | ||
| ) | ||
|
|
||
| block_state.negative_prompt_embeds = None | ||
| block_state.negative_prompt_embeds_mask = None | ||
| if components.requires_unconditional_embeds: | ||
| negative_prompt = block_state.negative_prompt or " " | ||
| block_state.negative_prompt_embeds, block_state.negative_prompt_embeds_mask = ( | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
120 changes: 120 additions & 0 deletions
120
tests/modular_pipelines/qwen/test_modular_pipeline_qwenimage.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,120 @@ | ||
| # coding=utf-8 | ||
| # Copyright 2025 HuggingFace Inc. | ||
| # | ||
| # Licensed under the Apache License, Version 2.0 (the "License"); | ||
| # you may not use this file except in compliance with the License. | ||
| # You may obtain a copy of the License at | ||
| # | ||
| # http://www.apache.org/licenses/LICENSE-2.0 | ||
| # | ||
| # Unless required by applicable law or agreed to in writing, software | ||
| # distributed under the License is distributed on an "AS IS" BASIS, | ||
| # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| # See the License for the specific language governing permissions and | ||
| # limitations under the License. | ||
|
|
||
|
|
||
| import PIL | ||
| import pytest | ||
|
|
||
| from diffusers.modular_pipelines import ( | ||
| QwenImageAutoBlocks, | ||
| QwenImageEditAutoBlocks, | ||
| QwenImageEditModularPipeline, | ||
| QwenImageEditPlusAutoBlocks, | ||
| QwenImageEditPlusModularPipeline, | ||
| QwenImageModularPipeline, | ||
| ) | ||
|
|
||
| from ..test_modular_pipelines_common import ModularGuiderTesterMixin, ModularPipelineTesterMixin | ||
|
|
||
|
|
||
| class TestQwenImageModularPipelineFast(ModularPipelineTesterMixin, ModularGuiderTesterMixin): | ||
| pipeline_class = QwenImageModularPipeline | ||
| pipeline_blocks_class = QwenImageAutoBlocks | ||
| repo = "hf-internal-testing/tiny-qwenimage-modular" | ||
|
|
||
| params = frozenset(["prompt", "height", "width", "negative_prompt", "attention_kwargs", "image", "mask_image"]) | ||
| batch_params = frozenset(["prompt", "negative_prompt", "image", "mask_image"]) | ||
|
|
||
| def get_dummy_inputs(self): | ||
| generator = self.get_generator() | ||
| inputs = { | ||
| "prompt": "dance monkey", | ||
| "negative_prompt": "bad quality", | ||
| "generator": generator, | ||
| "num_inference_steps": 2, | ||
| "height": 32, | ||
| "width": 32, | ||
| "max_sequence_length": 16, | ||
| "output_type": "pt", | ||
| } | ||
| return inputs | ||
|
|
||
| def test_inference_batch_single_identical(self): | ||
| super().test_inference_batch_single_identical(expected_max_diff=5e-4) | ||
|
|
||
|
|
||
| class TestQwenImageEditModularPipelineFast(ModularPipelineTesterMixin, ModularGuiderTesterMixin): | ||
| pipeline_class = QwenImageEditModularPipeline | ||
| pipeline_blocks_class = QwenImageEditAutoBlocks | ||
| repo = "hf-internal-testing/tiny-qwenimage-edit-modular" | ||
|
|
||
| params = frozenset(["prompt", "height", "width", "negative_prompt", "attention_kwargs", "image", "mask_image"]) | ||
| batch_params = frozenset(["prompt", "negative_prompt", "image", "mask_image"]) | ||
|
|
||
| def get_dummy_inputs(self): | ||
| generator = self.get_generator() | ||
| inputs = { | ||
| "prompt": "dance monkey", | ||
| "negative_prompt": "bad quality", | ||
| "generator": generator, | ||
| "num_inference_steps": 2, | ||
| "height": 32, | ||
| "width": 32, | ||
| "output_type": "pt", | ||
| } | ||
| inputs["image"] = PIL.Image.new("RGB", (32, 32), 0) | ||
| return inputs | ||
|
|
||
| def test_guider_cfg(self): | ||
| super().test_guider_cfg(7e-5) | ||
|
|
||
|
|
||
| class TestQwenImageEditPlusModularPipelineFast(ModularPipelineTesterMixin, ModularGuiderTesterMixin): | ||
| pipeline_class = QwenImageEditPlusModularPipeline | ||
| pipeline_blocks_class = QwenImageEditPlusAutoBlocks | ||
| repo = "hf-internal-testing/tiny-qwenimage-edit-plus-modular" | ||
|
|
||
| # No `mask_image` yet. | ||
| params = frozenset(["prompt", "height", "width", "negative_prompt", "attention_kwargs", "image"]) | ||
| batch_params = frozenset(["prompt", "negative_prompt", "image"]) | ||
|
|
||
| def get_dummy_inputs(self): | ||
| generator = self.get_generator() | ||
| inputs = { | ||
| "prompt": "dance monkey", | ||
| "negative_prompt": "bad quality", | ||
| "generator": generator, | ||
| "num_inference_steps": 2, | ||
| "height": 32, | ||
| "width": 32, | ||
| "output_type": "pt", | ||
| } | ||
| inputs["image"] = PIL.Image.new("RGB", (32, 32), 0) | ||
| return inputs | ||
|
|
||
| @pytest.mark.xfail(condition=True, reason="Batch of multiple images needs to be revisited", strict=True) | ||
| def test_num_images_per_prompt(self): | ||
| super().test_num_images_per_prompt() | ||
|
|
||
| @pytest.mark.xfail(condition=True, reason="Batch of multiple images needs to be revisited", strict=True) | ||
| def test_inference_batch_consistent(): | ||
| super().test_inference_batch_consistent() | ||
|
|
||
| @pytest.mark.xfail(condition=True, reason="Batch of multiple images needs to be revisited", strict=True) | ||
| def test_inference_batch_single_identical(): | ||
| super().test_inference_batch_single_identical() | ||
|
Comment on lines
+107
to
+117
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. These are skipped in the standard pipeline tests, too. |
||
|
|
||
| def test_guider_cfg(self): | ||
| super().test_guider_cfg(1e-3) | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Similar to how it's done in the other pipelines.