Download code/falcon/mktables.py from LiteMind/homunculus: direct link, hf CLI and curl.
- Browser
- Download file 2.5 kB
-
https://huggingface.co/LiteMind/homunculus/resolve/main/code/falcon/mktables.py
- Command line
-
hf download hf://LiteMind/homunculus/code/falcon/mktables.py
-
curl -L -o mktables.py https://huggingface.co/LiteMind/homunculus/resolve/main/code/falcon/mktables.py
2.5 kB
| import json | |
| def rd(f): return [json.loads(l) for l in open(f)] | |
| def row(*c): return '| '+' | '.join(str(x) for x in c)+' |' | |
| def hdr(*c): return row(*c)+'\n'+row(*['---']*len(c)) | |
| T = {} | |
| # pruning axes | |
| P = rd('prune_results.jsonl'); L = [hdr('config (axis:method:cut)', 'params kept', 'val CE', 'KL(orig||pruned)', 'top-1 agree', 'gen identical (of 6)', 'gen prefix frac')] | |
| for d in P: L.append(row(d['job'], '%.3f' % d['frac'], '%.2f' % d['ce_shakes'], '%.2f' % d['kl_prompts'], '%.2f' % d['top1_agree'], d['gen_identical'], '%.2f' % d['gen_prefix_frac'])) | |
| T['PRUNE'] = '\n'.join(L) | |
| C = rd('clust2_results.jsonl'); L = [hdr('method:cut', 'params kept', 'val CE', 'KL', 'top-1', 'gen identical', 'round-trip rel. error gate/up (mean of 24 layers)', 'round-trip rel. error down (mean)')] | |
| for d in sorted(C, key=lambda d: (float(d['job'].split(':')[-1]), d['job'])): | |
| rt = d['rt']; L.append(row(d['job'][3:], '%.3f' % d['frac'], '%.2f' % d['ce_shakes'], '%.2f' % d['kl_prompts'], '%.2f' % d['top1_agree'], d['gen_identical'], '%.3f' % (sum(x['rel_gu'] for x in rt)/24), '%.3f' % (sum(x['rel_down'] for x in rt)/24))) | |
| T['C2'] = '\n'.join(L) | |
| d = [x for x in C if x['job'] == 'c2:gud:0.25'][0]['rt'] | |
| T['PERLAYER'] = '\n'.join([hdr('layer', 'rel. error gate/up', 'max abs error gate/up')]+[row(i, '%.3f' % x['rel_gu'], '%.3f' % x['max_gu']) for i, x in enumerate(d)]) | |
| L = [hdr('config', 'params kept', 'val CE', 'KL', 'top-1', 'gen identical', 'gen prefix frac')] | |
| L.append(row('Q4 alone (per-row symmetric int4, all layer weights)', '1.000', '6.94', '3.62', '0.35', 0, '0.02')) | |
| for d in rd('clust3_results.jsonl'): L.append(row(d['job'][3:], '%.3f' % d['frac'], '%.2f' % d['ce_shakes'], '%.3f' % d['kl_prompts'], '%.2f' % d['top1_agree'], d['gen_identical'], '%.2f' % d['gen_prefix_frac'])) | |
| T['QUANT'] = '\n'.join(L) | |
| L = [hdr('ordering:binning:cut', 'val CE', 'KL', 'top-1')] | |
| for d in rd('clust4_results.jsonl'): L.append(row(d['job'][3:], '%.2f' % d['ce_shakes'], '%.2f' % d['kl_prompts'], '%.2f' % d['top1_agree'])) | |
| T['C4'] = '\n'.join(L) | |
| S = json.load(open('samples.json')); L = [] | |
| for i, s in enumerate(S, 1): | |
| L.append('**%d. Prompt:** `%s`\n\n- Original: %s\n- Pruned 25%% + Q8: %s\n' % (i, s['prompt'].replace('\n', '\\n'), json.dumps(s['orig'], ensure_ascii=False), json.dumps(s['pruned_q8'], ensure_ascii=False))) | |
| T['SAMPLES'] = '\n'.join(L) | |
| json.dump(T, open('tables.json', 'w'), ensure_ascii=False) | |
| for k, v in T.items(): print('==', k, len(v.splitlines())) | |
| print(T['QUANT']); print(T['C4']) | |