@@ -202,6 +202,36 @@ def test_sdxl_1_0_lora(self):
202202 pipe .unload_lora_weights ()
203203 release_memory (pipe )
204204
205+ def test_sdxl_1_0_blockwise_lora (self ):
206+ generator = torch .Generator ("cpu" ).manual_seed (0 )
207+
208+ pipe = StableDiffusionXLPipeline .from_pretrained ("stabilityai/stable-diffusion-xl-base-1.0" )
209+ pipe .enable_model_cpu_offload ()
210+ lora_model_id = "hf-internal-testing/sdxl-1.0-lora"
211+ lora_filename = "sd_xl_offset_example-lora_1.0.safetensors"
212+ pipe .load_lora_weights (lora_model_id , weight_name = lora_filename , adapter_name = "offset" )
213+ scales = {
214+ "unet" : {
215+ "down" : {"block_1" : [1.0 , 1.0 ], "block_2" : [1.0 , 1.0 ]},
216+ "mid" : 1.0 ,
217+ "up" : {"block_0" : [1.0 , 1.0 , 1.0 ], "block_1" : [1.0 , 1.0 , 1.0 ]},
218+ },
219+ }
220+ pipe .set_adapters (["offset" ], [scales ])
221+
222+ images = pipe (
223+ "masterpiece, best quality, mountain" , output_type = "np" , generator = generator , num_inference_steps = 2
224+ ).images
225+
226+ images = images [0 , - 3 :, - 3 :, - 1 ].flatten ()
227+ expected = np .array ([0.4468 , 0.4087 , 0.4134 , 0.366 , 0.3202 , 0.3505 , 0.3786 , 0.387 , 0.3535 ])
228+
229+ max_diff = numpy_cosine_similarity_distance (expected , images )
230+ assert max_diff < 1e-4
231+
232+ pipe .unload_lora_weights ()
233+ release_memory (pipe )
234+
205235 def test_sdxl_lcm_lora (self ):
206236 pipe = StableDiffusionXLPipeline .from_pretrained (
207237 "stabilityai/stable-diffusion-xl-base-1.0" , torch_dtype = torch .float16
0 commit comments