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

Function make_Act

lib/model_wrapper_low.py:76–97  ·  view source on GitHub ↗
(model, verbose=False)

Source from the content-addressed store, hash-verified

74
75
76def make_Act(model, verbose=False):
77 replace_map = dict()
78 for name, module in model.named_modules():
79 if isinstance(module, nn.Linear):
80 replace_map[name] = ActLinear(module)
81
82 for name, module in model.named_modules():
83 if verbose:
84 print("current:", name)
85 for k, v in replace_map.items():
86 k_ = k.split(".")
87 name_prefix, name_suffix = ".".join(k_[:-1]), k_[-1]
88 if name_prefix == "": # outer layer
89 if name == name_suffix:
90 if verbose:
91 print(" not modifying ", name_suffix)
92 # setattr(model, name_suffix, v)
93 elif name == name_prefix:
94 if verbose:
95 print(" modifying ", name_suffix, "inside", name)
96 setattr(module, name_suffix, v)
97 return model
98
99
100def revert_Act_to_Linear(model):

Callers 2

make_low_rankFunction · 0.70

Calls 1

ActLinearClass · 0.70

Tested by

no test coverage detected