-
Notifications
You must be signed in to change notification settings - Fork 7.3k
[tests] refactor b* pipeline tests #14625
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
+92
−26
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -27,7 +27,9 @@ | |
| from ...testing_utils import assert_tensors_close, torch_device | ||
| from ..testing_utils import ( | ||
| BasePipelineTesterConfig, | ||
| PipelineOffloadTesterMixin, | ||
| LoraMemoryTesterMixin, | ||
| LoraTesterMixin, | ||
| MemoryTesterMixin, | ||
| PipelineTesterMixin, | ||
| ) | ||
|
|
||
|
|
@@ -69,7 +71,17 @@ def get_dummy_components(self): | |
| scheduler = FlowMatchEulerDiscreteScheduler() | ||
|
|
||
| torch.manual_seed(0) | ||
| text_encoder = SmolLM3ForCausalLM(SmolLM3Config(hidden_size=32)) | ||
| text_encoder = SmolLM3ForCausalLM( | ||
| SmolLM3Config( | ||
| hidden_size=32, | ||
| intermediate_size=64, | ||
| num_hidden_layers=2, | ||
| num_attention_heads=2, | ||
| num_key_value_heads=1, | ||
| # `vocab_size` stays at the SmolLM3 default: the pipeline hardcodes the beginning-of-text id | ||
| # (128000) for empty prompts, so a smaller vocabulary would not be a valid text encoder here. | ||
| ) | ||
| ) | ||
| tokenizer = AutoTokenizer.from_pretrained("hf-internal-testing/tiny-random-t5") | ||
|
|
||
| return { | ||
|
|
@@ -105,7 +117,7 @@ def test_inference(self): | |
| assert generated_image.shape == self.output_shape | ||
|
|
||
| # fmt: off | ||
| expected_slice = torch.tensor([0.4025, 0.4722, 0.4377, 0.6178, 0.3643, 0.4914, 0.3694, 0.5096, 0.5980, 0.5516, 0.5228, 0.4731, 0.6202, 0.2424, 0.6280, 0.3556]) | ||
| expected_slice = torch.tensor([0.3804, 0.4799, 0.5112, 0.5784, 0.3970, 0.4709, 0.4027, 0.4882, 0.5627, 0.4635, 0.4718, 0.3876, 0.5741, 0.2936, 0.5912, 0.4014]) | ||
|
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. Using a small text encoder that is why |
||
| # fmt: on | ||
|
|
||
| generated_slice = generated_image.flatten() | ||
|
|
@@ -117,7 +129,7 @@ def test_encode_prompt_works_in_isolation(self): | |
| pass | ||
|
|
||
| def test_bria_fibo_different_prompts(self): | ||
| pipe = self.pipeline_class(**self.get_dummy_components()).to(torch_device) | ||
| pipe = self.get_pipeline().to(torch_device) | ||
|
|
||
| inputs = self.get_dummy_inputs() | ||
| output_same_prompt = pipe(**inputs).images[0] | ||
|
|
@@ -130,7 +142,7 @@ def test_bria_fibo_different_prompts(self): | |
| assert max_diff > 1e-6 | ||
|
|
||
| def test_image_output_shape(self): | ||
| pipe = self.pipeline_class(**self.get_dummy_components()).to(torch_device) | ||
| pipe = self.get_pipeline().to(torch_device) | ||
| inputs = self.get_dummy_inputs() | ||
|
|
||
| height_width_pairs = [(32, 32), (64, 64), (32, 64)] | ||
|
|
@@ -141,5 +153,22 @@ def test_image_output_shape(self): | |
| assert (output_height, output_width) == (height, width) | ||
|
|
||
|
|
||
| class TestBriaFiboPipelineMemory(BriaFiboPipelineTesterConfig, PipelineOffloadTesterMixin): | ||
| pass | ||
| class TestBriaFiboPipelineMemory(BriaFiboPipelineTesterConfig, MemoryTesterMixin): | ||
| """Memory optimization tests (CPU offload, group offload, layerwise casting) for the Bria FIBO pipeline.""" | ||
|
|
||
|
|
||
| class TestBriaFiboPipelineLoRA(BriaFiboPipelineTesterConfig, LoraTesterMixin): | ||
| """LoRA tests for the Bria FIBO pipeline.""" | ||
|
|
||
| @pytest.mark.skip( | ||
| "`_load_lora_into_text_encoder` only infers per-module ranks for CLIP-style names " | ||
| "(`.q_proj`/`.k_proj`/`.v_proj`/`.out_proj`/`.fc1`/`.fc2`, see `src/diffusers/loaders/lora_base.py`), so the " | ||
| "LLaMA-style `.o_proj` on the SmolLM3 text encoder falls back to the default rank and the non-uniform " | ||
| "`rank_pattern` this test builds cannot round-trip." | ||
| ) | ||
| def test_simple_inference_with_partial_text_lora(self): | ||
| pass | ||
|
|
||
|
|
||
| class TestBriaFiboPipelineLoRAMemory(BriaFiboPipelineTesterConfig, LoraMemoryTesterMixin): | ||
| """LoRA x memory-optimization tests (group offload, CPU offload) for the Bria FIBO pipeline.""" | ||
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 |
|---|---|---|
|
|
@@ -29,7 +29,9 @@ | |
| from ...testing_utils import assert_tensors_close, torch_device | ||
| from ..testing_utils import ( | ||
| BasePipelineTesterConfig, | ||
| PipelineOffloadTesterMixin, | ||
| LoraMemoryTesterMixin, | ||
| LoraTesterMixin, | ||
| MemoryTesterMixin, | ||
| PipelineTesterMixin, | ||
| ) | ||
|
|
||
|
|
@@ -73,7 +75,17 @@ def get_dummy_components(self): | |
| z_dim=16, | ||
| ) | ||
| scheduler = FlowMatchEulerDiscreteScheduler() | ||
| text_encoder = SmolLM3ForCausalLM(SmolLM3Config(hidden_size=32)) | ||
| text_encoder = SmolLM3ForCausalLM( | ||
| SmolLM3Config( | ||
| hidden_size=32, | ||
| intermediate_size=64, | ||
| num_hidden_layers=2, | ||
| num_attention_heads=2, | ||
| num_key_value_heads=1, | ||
| # `vocab_size` stays at the SmolLM3 default: the pipeline hardcodes the beginning-of-text id | ||
| # (128000) for empty prompts, so a smaller vocabulary would not be a valid text encoder here. | ||
| ) | ||
| ) | ||
| tokenizer = AutoTokenizer.from_pretrained("hf-internal-testing/tiny-random-t5") | ||
|
|
||
| return { | ||
|
|
@@ -111,7 +123,7 @@ def test_inference(self): | |
| assert generated_image.shape == self.output_shape | ||
|
|
||
| # fmt: off | ||
| expected_slice = torch.tensor([0.5615, 0.4469, 0.4043, 0.4312, 0.3783, 0.4426, 0.4081, 0.4446, 0.6549, 0.6302, 0.6324, 0.5871, 0.6117, 0.6647, 0.5871, 0.6246]) | ||
| expected_slice = torch.tensor([0.5594, 0.4469, 0.4011, 0.4329, 0.3747, 0.4408, 0.4074, 0.4452, 0.6472, 0.6353, 0.6258, 0.5867, 0.6104, 0.6624, 0.5824, 0.6277]) | ||
|
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. Using a small text encoder, that is why. |
||
| # fmt: on | ||
|
|
||
| generated_slice = generated_image.flatten() | ||
|
|
@@ -131,7 +143,7 @@ def test_inference_batch_single_identical(self): | |
| pass | ||
|
|
||
| def test_bria_fibo_different_prompts(self): | ||
| pipe = self.pipeline_class(**self.get_dummy_components()).to(torch_device) | ||
| pipe = self.get_pipeline().to(torch_device) | ||
|
|
||
| inputs = self.get_dummy_inputs() | ||
| output_same_prompt = pipe(**inputs).images[0] | ||
|
|
@@ -144,7 +156,7 @@ def test_bria_fibo_different_prompts(self): | |
| assert max_diff > 1e-6 | ||
|
|
||
| def test_image_output_shape(self): | ||
| pipe = self.pipeline_class(**self.get_dummy_components()).to(torch_device) | ||
| pipe = self.get_pipeline().to(torch_device) | ||
| inputs = self.get_dummy_inputs() | ||
|
|
||
| height_width_pairs = [(32, 32), (64, 64), (32, 64)] | ||
|
|
@@ -155,7 +167,7 @@ def test_image_output_shape(self): | |
| assert (output_height, output_width) == (height, width) | ||
|
|
||
| def test_bria_fibo_multi_reference_uses_distinct_rope_time_planes(self): | ||
| pipe = self.pipeline_class(**self.get_dummy_components()).to(torch_device) | ||
| pipe = self.get_pipeline().to(torch_device) | ||
|
|
||
| references = [ | ||
| Image.new("RGB", (336, 192), (255, 255, 255)), | ||
|
|
@@ -180,7 +192,7 @@ def test_bria_fibo_multi_reference_uses_distinct_rope_time_planes(self): | |
| assert image.shape == self.output_shape | ||
|
|
||
| def test_batched_prompts_with_multiple_references(self): | ||
| pipe = self.pipeline_class(**self.get_dummy_components()).to(torch_device) | ||
| pipe = self.get_pipeline().to(torch_device) | ||
| inputs = self.get_dummy_inputs() | ||
| inputs.update( | ||
| prompt=[inputs["prompt"], inputs["prompt"].replace("squirrel", "robot")], | ||
|
|
@@ -192,15 +204,15 @@ def test_batched_prompts_with_multiple_references(self): | |
| assert (images[0] - images[1]).abs().max() > 1e-4 | ||
|
|
||
| def test_multi_reference_mask_requires_single_reference(self): | ||
| pipe = self.pipeline_class(**self.get_dummy_components()).to(torch_device) | ||
| pipe = self.get_pipeline().to(torch_device) | ||
| inputs = self.get_dummy_inputs() | ||
| inputs["image"] = [inputs["image"], Image.new("RGB", (160, 96), (0, 0, 0))] | ||
| inputs["mask"] = Image.new("L", (336, 192), 255) | ||
| with pytest.raises(ValueError, match="exactly one reference"): | ||
| pipe(**inputs) | ||
|
|
||
| def test_bria_fibo_edit_mask(self): | ||
| pipe = self.pipeline_class(**self.get_dummy_components()).to(torch_device) | ||
| pipe = self.get_pipeline().to(torch_device) | ||
| inputs = self.get_dummy_inputs() | ||
|
|
||
| mask = Image.fromarray((np.ones((192, 336)) * 255).astype(np.uint8), mode="L") | ||
|
|
@@ -211,7 +223,7 @@ def test_bria_fibo_edit_mask(self): | |
| assert output.shape == (3, 192, 336) | ||
|
|
||
| def test_bria_fibo_edit_mask_image_size_mismatch(self): | ||
| pipe = self.pipeline_class(**self.get_dummy_components()).to(torch_device) | ||
| pipe = self.get_pipeline().to(torch_device) | ||
| inputs = self.get_dummy_inputs() | ||
|
|
||
| mask = Image.fromarray((np.ones((64, 64)) * 255).astype(np.uint8), mode="L") | ||
|
|
@@ -221,7 +233,7 @@ def test_bria_fibo_edit_mask_image_size_mismatch(self): | |
| pipe(**inputs) | ||
|
|
||
| def test_bria_fibo_edit_mask_no_image(self): | ||
| pipe = self.pipeline_class(**self.get_dummy_components()).to(torch_device) | ||
| pipe = self.get_pipeline().to(torch_device) | ||
| inputs = self.get_dummy_inputs() | ||
|
|
||
| mask = Image.fromarray((np.ones((32, 32)) * 255).astype(np.uint8), mode="L") | ||
|
|
@@ -233,5 +245,22 @@ def test_bria_fibo_edit_mask_no_image(self): | |
| pipe(**inputs) | ||
|
|
||
|
|
||
| class TestBriaFiboEditPipelineMemory(BriaFiboEditPipelineTesterConfig, PipelineOffloadTesterMixin): | ||
| pass | ||
| class TestBriaFiboEditPipelineMemory(BriaFiboEditPipelineTesterConfig, MemoryTesterMixin): | ||
| """Memory optimization tests (CPU offload, group offload, layerwise casting) for the Bria FIBO Edit pipeline.""" | ||
|
|
||
|
|
||
| class TestBriaFiboEditPipelineLoRA(BriaFiboEditPipelineTesterConfig, LoraTesterMixin): | ||
| """LoRA tests for the Bria FIBO Edit pipeline.""" | ||
|
|
||
| @pytest.mark.skip( | ||
| "`_load_lora_into_text_encoder` only infers per-module ranks for CLIP-style names " | ||
| "(`.q_proj`/`.k_proj`/`.v_proj`/`.out_proj`/`.fc1`/`.fc2`, see `src/diffusers/loaders/lora_base.py`), so the " | ||
| "LLaMA-style `.o_proj` on the SmolLM3 text encoder falls back to the default rank and the non-uniform " | ||
| "`rank_pattern` this test builds cannot round-trip." | ||
| ) | ||
| def test_simple_inference_with_partial_text_lora(self): | ||
| pass | ||
|
|
||
|
|
||
| class TestBriaFiboEditPipelineLoRAMemory(BriaFiboEditPipelineTesterConfig, LoraMemoryTesterMixin): | ||
| """LoRA x memory-optimization tests (group offload, CPU offload) for the Bria FIBO Edit pipeline.""" | ||
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.
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.
Do we need to set
eval()on this?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.
get_pipeline()already does it. Made sure we are using that method always.