@@ -359,29 +359,6 @@ def from_pretrained(cls,
359359 continue
360360 state_dict = cls .load_state_file (sub_folder )
361361 if state_dict is not None :
362- model_is_qlora = len ([
363- k for k in self .state_dict ().keys ()
364- if k .endswith (f'.lora_A.{ _adapter } .weight' ) or k .endswith (f'.lora_B.{ _adapter } .weight' )
365- ])
366- if not model_is_qlora :
367- # model is lora, state_dict: qlora->lora
368- state_dict = {
369- k [:- len (f'.{ _name } .weight' ) if k .endswith (f'.lora_A.{ _name } .weight' ) or k .
370- endswith (f'.lora_B.{ _name } .weight' ) else None ]: v
371- for k , v in state_dict .items ()
372- }
373- if any (['loramodule' in key for key in state_dict ]):
374- # Compatible with old checkpoints before ms-swift:1.5.0
375- state_dict = {
376- key .replace (f'loramodule_{ _name } .lora_A' , 'lora_A' ) if f'loramodule_{ _name } .lora_A.{ _name } '
377- in key else key .replace (f'loramodule_{ _name } .lora_A' , f'lora_A.{ _name } .weight' ): value
378- for key , value in state_dict .items ()
379- }
380- state_dict = {
381- key .replace (f'loramodule_{ _name } .lora_B' , 'lora_B' ) if f'loramodule_{ _name } .lora_B.{ _name } '
382- in key else key .replace (f'loramodule_{ _name } .lora_B' , f'lora_B.{ _name } .weight' ): value
383- for key , value in state_dict .items ()
384- }
385362 if isinstance (adapter_name , dict ):
386363 # TODO this logic is fragile! replace `_name` may cause other parts replaced
387364 state_dict = {key .replace (_name , adapter_name [_name ]): value for key , value in state_dict .items ()}
0 commit comments