This commit is contained in:
yuyu5333 2025-12-15 15:43:10 +08:00 committed by GitHub
commit e988830b31
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 4 additions and 1 deletions

1
.gitignore vendored
View File

@ -1,4 +1,5 @@
model/__pycache__
trainer/__pycache__
out
website/
docs-minimind/

View File

@ -34,9 +34,11 @@ def apply_lora(model, rank=8):
def load_lora(model, path):
state_dict = torch.load(path, map_location=model.device)
# 去除权重键名中可能存在的 module. 前缀
cleaned_state_dict = {k.replace('module.', ''): v for k, v in state_dict.items()}
for name, module in model.named_modules():
if hasattr(module, 'lora'):
lora_state = {k.replace(f'{name}.lora.', ''): v for k, v in state_dict.items() if f'{name}.lora.' in k}
lora_state = {k.replace(f'{name}.lora.', ''): v for k, v in cleaned_state_dict.items() if f'{name}.lora.' in k}
module.lora.load_state_dict(lora_state)