|
25 | 25 | from transformers import AutoTokenizer, CLIPTextModel, CLIPTokenizer, T5EncoderModel |
26 | 26 |
|
27 | 27 | from diffusers import FlowMatchEulerDiscreteScheduler, FluxControlPipeline, FluxPipeline, FluxTransformer2DModel |
28 | | -from diffusers.utils import logging |
| 28 | +from diffusers.utils import load_image, logging |
29 | 29 | from diffusers.utils.testing_utils import ( |
30 | 30 | CaptureLogger, |
31 | 31 | floats_tensor, |
@@ -578,3 +578,75 @@ def test_flux_xlabs_load_lora_with_single_blocks(self): |
578 | 578 | max_diff = numpy_cosine_similarity_distance(expected_slice.flatten(), out_slice) |
579 | 579 |
|
580 | 580 | assert max_diff < 1e-3 |
| 581 | + |
| 582 | + def test_flux_bfl_control_lora_canny(self): |
| 583 | + self.pipeline = FluxControlPipeline.from_pipe(self.pipeline) |
| 584 | + self.pipeline.load_lora_weights("black-forest-labs/FLUX.1-Canny-dev-lora", "canny") |
| 585 | + self.pipeline.set_adapters("canny", 0.85) |
| 586 | + self.pipeline.fuse_lora() |
| 587 | + self.pipeline.unload_lora_weights() |
| 588 | + self.pipeline.enable_model_cpu_offload() |
| 589 | + |
| 590 | + prompt = "A robot made of exotic candies and chocolates of different kinds. The background is filled with confetti and celebratory gifts." |
| 591 | + control_image = load_image( |
| 592 | + "https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/diffusers/robot_canny.png" |
| 593 | + ) |
| 594 | + |
| 595 | + output = self.pipeline( |
| 596 | + prompt=prompt, |
| 597 | + control_image=control_image, |
| 598 | + height=768, |
| 599 | + width=768, |
| 600 | + num_inference_steps=20, |
| 601 | + guidance_scale=30.0, |
| 602 | + generator=torch.manual_seed(self.seed), |
| 603 | + output_type="np", |
| 604 | + ).images |
| 605 | + output = output.flatten() |
| 606 | + output_slice = np.concatenate((output[:16], output[-16:])) |
| 607 | + |
| 608 | + # fmt: off |
| 609 | + expected_slice = np.array([0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]) |
| 610 | + # fmt: on |
| 611 | + |
| 612 | + print([round(x, 4) for x in output_slice.tolist()]) |
| 613 | + |
| 614 | + max_diff = numpy_cosine_similarity_distance(expected_slice.flatten(), output_slice) |
| 615 | + |
| 616 | + assert max_diff < 1e-3 |
| 617 | + |
| 618 | + def test_flux_bfl_control_lora_depth(self): |
| 619 | + self.pipeline = FluxControlPipeline.from_pipe(self.pipeline) |
| 620 | + self.pipeline.load_lora_weights("black-forest-labs/FLUX.1-Depth-dev-lora", "depth") |
| 621 | + self.pipeline.set_adapters("depth", 0.85) |
| 622 | + self.pipeline.fuse_lora() |
| 623 | + self.pipeline.unload_lora_weights() |
| 624 | + self.pipeline.enable_model_cpu_offload() |
| 625 | + |
| 626 | + prompt = "A robot made of exotic candies and chocolates of different kinds. The background is filled with confetti and celebratory gifts." |
| 627 | + control_image = load_image( |
| 628 | + "https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/diffusers/robot_depth.png" |
| 629 | + ) |
| 630 | + |
| 631 | + output = self.pipeline( |
| 632 | + prompt=prompt, |
| 633 | + control_image=control_image, |
| 634 | + height=768, |
| 635 | + width=768, |
| 636 | + num_inference_steps=20, |
| 637 | + guidance_scale=10.0, |
| 638 | + generator=torch.manual_seed(self.seed), |
| 639 | + output_type="np", |
| 640 | + ).images |
| 641 | + output = output.flatten() |
| 642 | + output_slice = np.concatenate((output[:16], output[-16:])) |
| 643 | + |
| 644 | + # fmt: off |
| 645 | + expected_slice = np.array([0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]) |
| 646 | + # fmt: on |
| 647 | + |
| 648 | + print([round(x, 4) for x in output_slice.tolist()]) |
| 649 | + |
| 650 | + max_diff = numpy_cosine_similarity_distance(expected_slice.flatten(), output_slice) |
| 651 | + |
| 652 | + assert max_diff < 1e-3 |
0 commit comments