37
37
EulerDiscreteScheduler ,
38
38
LCMScheduler ,
39
39
StableDiffusionPipeline ,
40
+ StableDiffusionXLAdapterPipeline ,
40
41
StableDiffusionXLControlNetPipeline ,
41
42
StableDiffusionXLPipeline ,
43
+ T2IAdapter ,
42
44
UNet2DConditionModel ,
43
45
)
44
46
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):
2175
2177
self .assertTrue (np .allclose (images , expected , atol = 1e-3 ))
2176
2178
release_memory (pipeline )
2177
2179
2178
- def test_canny_lora (self ):
2180
+ def test_controlnet_canny_lora (self ):
2179
2181
controlnet = ControlNetModel .from_pretrained ("diffusers/controlnet-canny-sdxl-1.0" )
2180
2182
2181
2183
pipe = StableDiffusionXLControlNetPipeline .from_pretrained (
@@ -2199,6 +2201,34 @@ def test_canny_lora(self):
2199
2201
assert np .allclose (original_image , expected_image , atol = 1e-04 )
2200
2202
release_memory (pipe )
2201
2203
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
+
2202
2232
@nightly
2203
2233
def test_sequential_fuse_unfuse (self ):
2204
2234
pipe = DiffusionPipeline .from_pretrained ("stabilityai/stable-diffusion-xl-base-1.0" , torch_dtype = torch .float16 )
0 commit comments