@@ -257,26 +257,18 @@ def get_module_weight(weight_for_adapter, module_name):
257
257
258
258
return block_weight
259
259
260
- # iterate over each adapter, make it active and set the corresponding scaling weight
261
- for adapter_name , weight in zip (adapter_names , weights ):
262
- for module_name , module in model .named_modules ():
263
- if isinstance (module , BaseTunerLayer ):
264
- # For backward compatbility with previous PEFT versions
265
- if hasattr (module , "set_adapter" ):
266
- module .set_adapter (adapter_name )
267
- else :
268
- module .active_adapter = adapter_name
269
- module .set_scale (adapter_name , get_module_weight (weight , module_name ))
270
-
271
- # set multiple active adapters
272
- for module in model .modules ():
260
+ for module_name , module in model .named_modules ():
273
261
if isinstance (module , BaseTunerLayer ):
274
- # For backward compatbility with previous PEFT versions
262
+ # For backward compatibility with previous PEFT versions, set multiple active adapters
275
263
if hasattr (module , "set_adapter" ):
276
264
module .set_adapter (adapter_names )
277
265
else :
278
266
module .active_adapter = adapter_names
279
267
268
+ # Set the scaling weight for each adapter for this module
269
+ for adapter_name , weight in zip (adapter_names , weights ):
270
+ module .set_scale (adapter_name , get_module_weight (weight , module_name ))
271
+
280
272
281
273
def check_peft_version (min_version : str ) -> None :
282
274
r"""
0 commit comments