File size: 922 Bytes
8246b15 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 | import prune
from clust3 import *
import prune as P_
sd0, cfg0 = load(); sd0.pop('lm_head.weight', None); S = {eval(k): v for k, v in torch.load('S.pt').items()}
mo, _ = build(sd0, cfg0)
sd, cfg, _ = build_from(sd0, cfg0, 'imp', 0.25, None, S); sd = quant_b(sd, 8); mp, _ = build(sd, cfg)
prune.NEW = 48
out = []
labels = ["Why is the sky blue? Answer in two sentences.", "Write a short poem (4 lines) about a falcon flying over the desert.", "What is the capital of Libya?", P_.P[0], P_.P[1], P_.P[2]]
GO, GP = prune.gen(mo), prune.gen(mp)
for l, a, b in zip(labels, GO, GP):
out.append({'prompt': l, 'orig': tok.decode(a, skip_special_tokens=True), 'pruned_q8': tok.decode(b, skip_special_tokens=True), 'same': a == b})
json.dump(out, open('samples.json', 'w'), ensure_ascii=False, indent=1)
for o in out: print('PROMPT:', repr(o['prompt']), '\nORIG:', repr(o['orig']), '\nPRUNED25+Q8:', repr(o['pruned_q8']), '\n')
|