@@ -150,6 +150,54 @@ def test_integration_move_lora_cpu(self):
150150 if ("adapter-1" in n or "adapter-2" in n ) and not isinstance (m , (nn .Dropout , nn .Identity )):
151151 self .assertTrue (m .weight .device != torch .device ("cpu" ))
152152
153+ @require_torch_gpu
154+ def test_integration_move_lora_dora_cpu (self ):
155+ from peft import LoraConfig
156+
157+ path = "runwayml/stable-diffusion-v1-5"
158+ unet_lora_config = LoraConfig (
159+ init_lora_weights = "gaussian" ,
160+ target_modules = ["to_k" , "to_q" , "to_v" , "to_out.0" ],
161+ use_dora = True ,
162+ )
163+ text_lora_config = LoraConfig (
164+ init_lora_weights = "gaussian" ,
165+ target_modules = ["q_proj" , "k_proj" , "v_proj" , "out_proj" ],
166+ use_dora = True ,
167+ )
168+
169+ pipe = StableDiffusionPipeline .from_pretrained (path , torch_dtype = torch .float16 )
170+ pipe .unet .add_adapter (unet_lora_config , "adapter-1" )
171+ pipe .text_encoder .add_adapter (text_lora_config , "adapter-1" )
172+
173+ self .assertTrue (
174+ check_if_lora_correctly_set (pipe .text_encoder ),
175+ "Lora not correctly set in text encoder" ,
176+ )
177+
178+ self .assertTrue (
179+ check_if_lora_correctly_set (pipe .unet ),
180+ "Lora not correctly set in text encoder" ,
181+ )
182+
183+ for name , param in pipe .unet .named_parameters ():
184+ if "lora_" in name :
185+ self .assertEqual (param .device , torch .device ("cpu" ))
186+
187+ for name , param in pipe .text_encoder .named_parameters ():
188+ if "lora_" in name :
189+ self .assertEqual (param .device , torch .device ("cpu" ))
190+
191+ pipe .set_lora_device (["adapter-1" ], torch_device )
192+
193+ for name , param in pipe .unet .named_parameters ():
194+ if "lora_" in name :
195+ self .assertNotEqual (param .device , torch .device ("cpu" ))
196+
197+ for name , param in pipe .text_encoder .named_parameters ():
198+ if "lora_" in name :
199+ self .assertNotEqual (param .device , torch .device ("cpu" ))
200+
153201
154202@slow
155203@require_torch_gpu
0 commit comments