@@ -1135,6 +1135,43 @@ def test_wrong_adapter_name_raises_error(self):
11351135 pipe .set_adapters ("adapter-1" )
11361136 _ = pipe (** inputs , generator = torch .manual_seed (0 ))[0 ]
11371137
1138+ def test_multiple_wrong_adapter_name_raises_error (self ):
1139+ scheduler_cls = self .scheduler_classes [0 ]
1140+ components , text_lora_config , denoiser_lora_config = self .get_dummy_components (scheduler_cls )
1141+ pipe = self .pipeline_class (** components )
1142+ pipe = pipe .to (torch_device )
1143+ pipe .set_progress_bar_config (disable = None )
1144+ _ , _ , inputs = self .get_dummy_inputs (with_generator = False )
1145+
1146+ if "text_encoder" in self .pipeline_class ._lora_loadable_modules :
1147+ pipe .text_encoder .add_adapter (text_lora_config , "adapter-1" )
1148+ self .assertTrue (check_if_lora_correctly_set (pipe .text_encoder ), "Lora not correctly set in text encoder" )
1149+
1150+ denoiser = pipe .transformer if self .unet_kwargs is None else pipe .unet
1151+ denoiser .add_adapter (denoiser_lora_config , "adapter-1" )
1152+ self .assertTrue (check_if_lora_correctly_set (denoiser ), "Lora not correctly set in denoiser." )
1153+
1154+ if self .has_two_text_encoders or self .has_three_text_encoders :
1155+ if "text_encoder_2" in self .pipeline_class ._lora_loadable_modules :
1156+ pipe .text_encoder_2 .add_adapter (text_lora_config , "adapter-1" )
1157+ self .assertTrue (
1158+ check_if_lora_correctly_set (pipe .text_encoder_2 ), "Lora not correctly set in text encoder 2"
1159+ )
1160+
1161+ scale_with_wrong_components = {"foo" : 0.0 , "bar" : 0.0 , "tik" : 0.0 }
1162+ logger = logging .get_logger ("diffusers.loaders.lora_base" )
1163+ logger .setLevel (30 )
1164+ with CaptureLogger (logger ) as cap_logger :
1165+ pipe .set_adapters ("adapter-1" , adapter_weights = scale_with_wrong_components )
1166+
1167+ wrong_components = sorted (set (scale_with_wrong_components .keys ()))
1168+ msg = f"The following components in `adapter_weights` are not part of the pipeline: { wrong_components } . "
1169+ self .assertTrue (msg in str (cap_logger .out ))
1170+
1171+ # test this works.
1172+ pipe .set_adapters ("adapter-1" )
1173+ _ = pipe (** inputs , generator = torch .manual_seed (0 ))[0 ]
1174+
11381175 def test_simple_inference_with_text_denoiser_block_scale (self ):
11391176 """
11401177 Tests a simple inference with lora attached to text encoder and unet, attaches
0 commit comments