MCPcopy
hub / github.com/Tele-AI/Telechat / convert_lora_to_linear_layer

Function convert_lora_to_linear_layer

deepspeed-telechat/utils/module/lora.py:132–147  ·  view source on GitHub ↗
(model)

Source from the content-addressed store, hash-verified

130
131# convert the LoRA layer to linear layer
132def convert_lora_to_linear_layer(model):
133 replace_name = []
134 for name, module in model.named_modules():
135 if isinstance(module, LinearLayer_LoRA):
136 replace_name.append(name)
137 for name in replace_name:
138 module = recursive_getattr(model, name)
139 zero_stage_3 = hasattr(module.weight, 'ds_id')
140 with deepspeed.zero.GatheredParameters(_z3_params_to_fetch([
141 module.weight, module.bias, module.lora_left_weight,
142 module.lora_right_weight
143 ]),
144 modifier_rank=0,
145 enabled=zero_stage_3):
146 module.fuse_lora_weight()
147 return model
148
149def recover_lora(model):
150 replace_name = []

Callers 1

mainFunction · 0.90

Calls 3

fuse_lora_weightMethod · 0.80
_z3_params_to_fetchFunction · 0.70
appendMethod · 0.45

Tested by

no test coverage detected