MCPcopy Create free account
hub / github.com/CERT-Lab/lora-sb / get_replacement_module

Function get_replacement_module

utils/initialization_utils.py:15–23  ·  view source on GitHub ↗
(weight, module_name, type, writer, reconstruct_config, init_scaling=1)

Source from the content-addressed store, hash-verified

13
14
15def get_replacement_module(weight, module_name, type, writer, reconstruct_config, init_scaling=1):
16 cfg = reconstruct_config[type]
17 if type == 'svd':
18 Ur, sr, Vrt = get_svd_grad(weight.detach(), cfg['rank'])
19 final_enc = torch.tensor(Ur @ sr, dtype=weight.dtype, device=weight.device)
20 final_dec = torch.tensor(Vrt, dtype=weight.dtype, device=weight.device)
21 else:
22 raise NotImplementedError(f"{type} is currently not supported.")
23 return final_enc, final_dec
24
25def get_replacement_module_grad(weight, type, reconstruct_config):
26 cfg = reconstruct_config[type]

Callers 1

find_and_initializeFunction · 0.85

Calls 1

get_svd_gradFunction · 0.85

Tested by

no test coverage detected