MCPcopy
hub / github.com/jingyaogong/minimind / apply_lora

Function apply_lora

model/model_lora.py:21–32  ·  view source on GitHub ↗
(model, rank=16)

Source from the content-addressed store, hash-verified

19
20
21def apply_lora(model, rank=16):
22 for name, module in model.named_modules():
23 if isinstance(module, nn.Linear) and module.in_features == module.out_features:
24 lora = LoRA(module.in_features, module.out_features, rank=rank).to(model.device)
25 setattr(module, "lora", lora)
26 original_forward = module.forward
27
28 # 显式绑定
29 def forward_with_lora(x, layer1=original_forward, layer2=lora):
30 return layer1(x) + layer2(x)
31
32 module.forward = forward_with_lora
33
34
35def load_lora(model, path):

Callers 4

convert_merge_base_loraFunction · 0.90
init_modelFunction · 0.90
train_lora.pyFile · 0.90
init_modelFunction · 0.85

Calls 1

LoRAClass · 0.85

Tested by

no test coverage detected