Skip to content

Commit 40dd9cb

Browse files
authored
Move SDXL T2I Adapter lora test into PEFT workflow (#6965)
update
1 parent 30bcda7 commit 40dd9cb

File tree

2 files changed

+31
-29
lines changed

2 files changed

+31
-29
lines changed

tests/lora/test_lora_layers_peft.py

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,10 @@
3737
EulerDiscreteScheduler,
3838
LCMScheduler,
3939
StableDiffusionPipeline,
40+
StableDiffusionXLAdapterPipeline,
4041
StableDiffusionXLControlNetPipeline,
4142
StableDiffusionXLPipeline,
43+
T2IAdapter,
4244
UNet2DConditionModel,
4345
)
4446
from diffusers.utils.import_utils import is_accelerate_available, is_peft_available
@@ -2175,7 +2177,7 @@ def test_sd_load_civitai_empty_network_alpha(self):
21752177
self.assertTrue(np.allclose(images, expected, atol=1e-3))
21762178
release_memory(pipeline)
21772179

2178-
def test_canny_lora(self):
2180+
def test_controlnet_canny_lora(self):
21792181
controlnet = ControlNetModel.from_pretrained("diffusers/controlnet-canny-sdxl-1.0")
21802182

21812183
pipe = StableDiffusionXLControlNetPipeline.from_pretrained(
@@ -2199,6 +2201,34 @@ def test_canny_lora(self):
21992201
assert np.allclose(original_image, expected_image, atol=1e-04)
22002202
release_memory(pipe)
22012203

2204+
def test_sdxl_t2i_adapter_canny_lora(self):
2205+
adapter = T2IAdapter.from_pretrained("TencentARC/t2i-adapter-lineart-sdxl-1.0", torch_dtype=torch.float16).to(
2206+
"cpu"
2207+
)
2208+
pipe = StableDiffusionXLAdapterPipeline.from_pretrained(
2209+
"stabilityai/stable-diffusion-xl-base-1.0",
2210+
adapter=adapter,
2211+
torch_dtype=torch.float16,
2212+
variant="fp16",
2213+
)
2214+
pipe.load_lora_weights("CiroN2022/toy-face", weight_name="toy_face_sdxl.safetensors")
2215+
pipe.enable_model_cpu_offload()
2216+
pipe.set_progress_bar_config(disable=None)
2217+
2218+
generator = torch.Generator(device="cpu").manual_seed(0)
2219+
prompt = "toy"
2220+
image = load_image(
2221+
"https://huggingface.co/datasets/hf-internal-testing/diffusers-images/resolve/main/t2i_adapter/toy_canny.png"
2222+
)
2223+
2224+
images = pipe(prompt, image=image, generator=generator, output_type="np", num_inference_steps=3).images
2225+
2226+
assert images[0].shape == (768, 512, 3)
2227+
2228+
image_slice = images[0, -3:, -3:, -1].flatten()
2229+
expected_slice = np.array([0.4284, 0.4337, 0.4319, 0.4255, 0.4329, 0.4280, 0.4338, 0.4420, 0.4226])
2230+
assert numpy_cosine_similarity_distance(image_slice, expected_slice) < 1e-4
2231+
22022232
@nightly
22032233
def test_sequential_fuse_unfuse(self):
22042234
pipe = DiffusionPipeline.from_pretrained("stabilityai/stable-diffusion-xl-base-1.0", torch_dtype=torch.float16)

tests/pipelines/stable_diffusion_xl/test_stable_diffusion_xl_adapter.py

Lines changed: 0 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -672,34 +672,6 @@ def tearDown(self):
672672
gc.collect()
673673
torch.cuda.empty_cache()
674674

675-
def test_canny_lora(self):
676-
adapter = T2IAdapter.from_pretrained("TencentARC/t2i-adapter-lineart-sdxl-1.0", torch_dtype=torch.float16).to(
677-
"cpu"
678-
)
679-
pipe = StableDiffusionXLAdapterPipeline.from_pretrained(
680-
"stabilityai/stable-diffusion-xl-base-1.0",
681-
adapter=adapter,
682-
torch_dtype=torch.float16,
683-
variant="fp16",
684-
)
685-
pipe.load_lora_weights("CiroN2022/toy-face", weight_name="toy_face_sdxl.safetensors")
686-
pipe.enable_model_cpu_offload()
687-
pipe.set_progress_bar_config(disable=None)
688-
689-
generator = torch.Generator(device="cpu").manual_seed(0)
690-
prompt = "toy"
691-
image = load_image(
692-
"https://huggingface.co/datasets/hf-internal-testing/diffusers-images/resolve/main/t2i_adapter/toy_canny.png"
693-
)
694-
695-
images = pipe(prompt, image=image, generator=generator, output_type="np", num_inference_steps=3).images
696-
697-
assert images[0].shape == (768, 512, 3)
698-
699-
image_slice = images[0, -3:, -3:, -1].flatten()
700-
expected_slice = np.array([0.4284, 0.4337, 0.4319, 0.4255, 0.4329, 0.4280, 0.4338, 0.4420, 0.4226])
701-
assert numpy_cosine_similarity_distance(image_slice, expected_slice) < 1e-4
702-
703675
def test_download_ckpt_diff_format_is_same(self):
704676
ckpt_path = (
705677
"https://huggingface.co/stabilityai/stable-diffusion-xl-base-1.0/blob/main/sd_xl_base_1.0.safetensors"

0 commit comments

Comments
 (0)