3737 EulerDiscreteScheduler ,
3838 LCMScheduler ,
3939 StableDiffusionPipeline ,
40+ StableDiffusionXLAdapterPipeline ,
4041 StableDiffusionXLControlNetPipeline ,
4142 StableDiffusionXLPipeline ,
43+ T2IAdapter ,
4244 UNet2DConditionModel ,
4345)
4446from 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 )
0 commit comments