MCPcopy Create free account
hub / github.com/boyiwei/alignment-attribution-code / make_Act

Function make_Act

lib/model_wrapper.py:91–112  ·  view source on GitHub ↗
(model, verbose=False)

Source from the content-addressed store, hash-verified

89
90
91def make_Act(model, verbose=False):
92 replace_map = dict()
93 for name, module in model.named_modules():
94 if isinstance(module, nn.Linear):
95 replace_map[name] = ActLinear(module)
96
97 for name, module in model.named_modules():
98 if verbose:
99 print("current:", name)
100 for k, v in replace_map.items():
101 k_ = k.split(".")
102 name_prefix, name_suffix = ".".join(k_[:-1]), k_[-1]
103 if name_prefix == "": # outer layer
104 if name == name_suffix:
105 if verbose:
106 print(" not modifying ", name_suffix)
107 # setattr(model, name_suffix, v)
108 elif name == name_prefix:
109 if verbose:
110 print(" modifying ", name_suffix, "inside", name)
111 setattr(module, name_suffix, v)
112 return model
113
114
115def revert_Act_to_Linear(model):

Callers 4

prune_wanda_v2Function · 0.70
prune_wandg_v1Function · 0.70
prune_wandgFunction · 0.70
model_wrapper.pyFile · 0.70

Calls 1

ActLinearClass · 0.70

Tested by

no test coverage detected