|
8 | 8 | from diffusers import ( |
9 | 9 | AuraFlowPipeline, |
10 | 10 | AuraFlowTransformer2DModel, |
| 11 | + FluxControlPipeline, |
11 | 12 | FluxPipeline, |
12 | 13 | FluxTransformer2DModel, |
13 | 14 | GGUFQuantizationConfig, |
14 | 15 | SD3Transformer2DModel, |
15 | 16 | StableDiffusion3Pipeline, |
16 | 17 | ) |
| 18 | +from diffusers.utils import load_image |
17 | 19 | from diffusers.utils.testing_utils import ( |
18 | 20 | is_gguf_available, |
19 | 21 | nightly, |
20 | 22 | numpy_cosine_similarity_distance, |
21 | 23 | require_accelerate, |
22 | 24 | require_big_gpu_with_torch_cuda, |
23 | 25 | require_gguf_version_greater_or_equal, |
| 26 | + require_peft_backend, |
24 | 27 | torch_device, |
25 | 28 | ) |
26 | 29 |
|
@@ -456,3 +459,46 @@ def test_pipeline_inference(self): |
456 | 459 | ) |
457 | 460 | max_diff = numpy_cosine_similarity_distance(expected_slice, output_slice) |
458 | 461 | assert max_diff < 1e-4 |
| 462 | + |
| 463 | + |
| 464 | +@require_peft_backend |
| 465 | +@nightly |
| 466 | +@require_big_gpu_with_torch_cuda |
| 467 | +@require_accelerate |
| 468 | +@require_gguf_version_greater_or_equal("0.10.0") |
| 469 | +class FluxControlLoRAGGUFTests(unittest.TestCase): |
| 470 | + def test_lora_loading(self): |
| 471 | + ckpt_path = "https://huggingface.co/city96/FLUX.1-dev-gguf/blob/main/flux1-dev-Q2_K.gguf" |
| 472 | + transformer = FluxTransformer2DModel.from_single_file( |
| 473 | + ckpt_path, |
| 474 | + quantization_config=GGUFQuantizationConfig(compute_dtype=torch.bfloat16), |
| 475 | + torch_dtype=torch.bfloat16, |
| 476 | + ) |
| 477 | + pipe = FluxControlPipeline.from_pretrained( |
| 478 | + "black-forest-labs/FLUX.1-dev", |
| 479 | + transformer=transformer, |
| 480 | + torch_dtype=torch.bfloat16, |
| 481 | + ).to("cuda") |
| 482 | + pipe.load_lora_weights("black-forest-labs/FLUX.1-Canny-dev-lora") |
| 483 | + |
| 484 | + prompt = "A robot made of exotic candies and chocolates of different kinds. The background is filled with confetti and celebratory gifts." |
| 485 | + control_image = load_image( |
| 486 | + "https://huggingface.co/datasets/sayakpaul/sample-datasets/resolve/main/control_image_robot_canny.png" |
| 487 | + ) |
| 488 | + |
| 489 | + output = pipe( |
| 490 | + prompt=prompt, |
| 491 | + control_image=control_image, |
| 492 | + height=256, |
| 493 | + width=256, |
| 494 | + num_inference_steps=10, |
| 495 | + guidance_scale=30.0, |
| 496 | + output_type="np", |
| 497 | + generator=torch.manual_seed(0), |
| 498 | + ).images |
| 499 | + |
| 500 | + out_slice = output[0, -3:, -3:, -1].flatten() |
| 501 | + expected_slice = np.array([0.8047, 0.8359, 0.8711, 0.6875, 0.7070, 0.7383, 0.5469, 0.5820, 0.6641]) |
| 502 | + |
| 503 | + max_diff = numpy_cosine_similarity_distance(expected_slice, out_slice) |
| 504 | + self.assertTrue(max_diff < 1e-3) |
0 commit comments