Files
exp-model-parameter-similarity/functional/report.py
T

50 lines
3.2 KiB
Python

"""Render scientific pilot figures using saved data; never reopen model weights."""
import argparse
import csv
import json
from pathlib import Path
import numpy as np
import matplotlib
matplotlib.use('Agg')
import matplotlib.pyplot as plt
def main():
p=argparse.ArgumentParser();p.add_argument('--root',type=Path,required=True);a=p.parse_args();root=a.root
out=root/'figures';out.mkdir(exist_ok=True)
plt.rcParams.update({'font.size':10,'savefig.bbox':'tight','pdf.fonttype':42,'svg.fonttype':'none'})
def save(fig,name):
for ext in ('png','pdf','svg'):fig.savefig(out/f'{name}.{ext}',dpi=180)
plt.close(fig)
status=json.loads((root/'functional-status.json').read_text())
if (root/'candidate-summary.json').exists():
c=json.loads((root/'candidate-summary.json').read_text())
fig,ax=plt.subplots(figsize=(10,4.5))
ax.bar(np.arange(len(c)),[max(v['maximum_symmetric_relative_error'],1e-8) for v in c],color=['#238b45' if v['passed'] else '#9e9e9e' for v in c])
ax.axhline(.05,color='#b2182b',linestyle='--',label='Relative L2 screen = 0.05; other gates also apply')
ax.set_yscale('log');ax.set_xticks(np.arange(len(c)),[v['id'] for v in c],rotation=45,ha='right')
ax.set_ylabel('Worst calibration symmetric relative L2')
ax.set_title('Fixed candidates; same-input function comparison\n4 calibration texts, 32 tokens; no training')
ax.legend(loc='upper left',bbox_to_anchor=(0,1.01),fontsize=8);fig.tight_layout();save(fig,'candidate_function_errors')
if (root/'interventions.json').exists():
interventions=json.loads((root/'interventions.json').read_text())
fig,ax=plt.subplots(figsize=(8,4.5))
for idx,r in enumerate(interventions):
values=r['sequence_nll_deltas'];x=np.arange(len(values))
ax.plot(x,values,'o-',label=r['direction'])
ax.axhline(0,color='gray',linewidth=.7);ax.axhline(.01,color='#b2182b',linestyle='--',label='Mean-delta budget (not per-sequence bound)')
ax.set_xticks(np.arange(4),['heldout zh1','heldout zh2','heldout en1','heldout en2'])
ax.set_ylabel('Token NLL change (nat/token)');ax.set_title('Single-site interventions; frozen candidate\n4 heldout texts, 32 tokens; limited pilot evidence')
ax.legend(loc='upper left',bbox_to_anchor=(0,-.18),fontsize=8);fig.tight_layout();save(fig,'heldout_intervention_nll')
text=['# CPU functional reuse pilot','',f'- State: {status["state"]}',f'- Positive bidirectional pilot: {status.get("positive_bidirectional_quality",False)}',
f'- Elapsed analysis seconds: {status.get("elapsed_seconds")}',f'- Peak RSS KiB: {status.get("peak_rss_kib")}',
'- Original BF16 weights decoded into FP32 CPU operators, no training.',
'- Calibration and heldout samples are distinct but very small, short and experiment-authored.',
'- A positive result is limited to these empirical tests, not global equivalence or GPU speedup.',
'- Weight retention: keep until explicit user deletion request; no automatic cleanup.','']
if status['state']!='completed':text+=['## Stop evidence','',f'{status.get("error_type")}: {status.get("error")}','']
(root/'FUNCTIONAL_REPORT.md').write_text('\n'.join(text))
if __name__=='__main__':main()