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

Function prune_wanda_v2

lib/model_wrapper.py:143–188  ·  view source on GitHub ↗
(
    args,
    model,
    tokenizer,
    model_base=None,
    device=torch.device("cuda:0"),
    prune_n=0,
    prune_m=0,
    prune_data="wikitext",
)

Source from the content-addressed store, hash-verified

141
142
143def prune_wanda_v2(
144 args,
145 model,
146 tokenizer,
147 model_base=None,
148 device=torch.device("cuda:0"),
149 prune_n=0,
150 prune_m=0,
151 prune_data="wikitext",
152):
153 model = make_Act(model, verbose=False)
154
155 print(f"loading calibdation data {prune_data}")
156 assert prune_data in [
157 "wikitext",
158 "alpaca",
159 "alpaca_cleaned",
160 "alpaca_cleaned_no_safety",
161 "align",
162 "align_short",
163 "misalign",
164 ]
165 dataloader, _ = get_loaders(
166 prune_data,
167 nsamples=args.nsamples,
168 seed=args.seed,
169 seqlen=model.seqlen,
170 tokenizer=tokenizer,
171 disentangle=args.disentangle,
172 )
173 print("dataset loading complete")
174
175 clear_act_buffer(model)
176 with torch.no_grad():
177 for batch in dataloader:
178 inp, tar = batch[0].to(device), batch[1].to(device)
179
180 if args.disentangle:
181 mask = tar.ne(-100)
182 with set_mask(model, mask):
183 model(inp)
184 else:
185 model(inp)
186
187 _prune_core(args, model, model_base, prune_n, prune_m, prune_mode="activation")
188 model = revert_Act_to_Linear(model)
189
190
191def prune_wandg_v1(

Callers 1

mainFunction · 0.90

Calls 6

get_loadersFunction · 0.85
_prune_coreFunction · 0.85
make_ActFunction · 0.70
clear_act_bufferFunction · 0.70
set_maskClass · 0.70
revert_Act_to_LinearFunction · 0.70

Tested by

no test coverage detected