Files

32 lines
2.3 KiB
Python

"""Run the authorized isolated test and restore prior IQ3 through normal API."""
import json,pathlib,subprocess,time,urllib.request
stage=pathlib.Path('/opt/athena-deck-dev/context-prepared-20261013');out=pathlib.Path('/data/experiments/strata-context-20261013')
attempts=[]
for context in (1000000,524288):
out.mkdir(parents=True,exist_ok=True)
(out/'extended-status.json').write_text(json.dumps({'phase':'running','context':context,'attempts':attempts}))
rc=subprocess.run(['python3',str(stage/'launch.py'),'--go','--context',str(context)]).returncode
resultpath=out/f'extended-{context}'/'results.json'
rows=json.loads(resultpath.read_text()) if resultpath.exists() else []
full=next((r for r in rows if r['case']=='full-max'),None)
usable=rc==0 and full is not None and full.get('needle_exact') is True
attempts.append({'context':context,'returncode':rc,'complete':rc==0,'full_needle_ok':bool(full and full.get('needle_exact')),'usable':usable})
if usable and not (stage/'run-512-after-million').exists():break
(out/'extended-status.json').write_text(json.dumps({'phase':'complete','attempts':attempts}))
result={'benchmark_returncode':rc,'restored':False}
try:
c=json.loads(subprocess.check_output(['docker','inspect','athena-voxcpm2-web']))[0]
f=next(pathlib.Path(m['Source']) for m in c['Mounts'] if m['Destination']=='/data');token=json.loads((f/'deck-connection.json').read_text())['token']
headers={'Authorization':'Bearer '+token,'Content-Type':'application/json'}
status=json.load(urllib.request.urlopen(urllib.request.Request('http://127.0.0.1:8108/api/v1/status',headers=headers),timeout=20))
if status['endpoint']['active_requests'] or status['endpoint']['counts']['llm']['loaded']:
result['restore_skipped']='user_activity'
else:
body={'model':'flash-next-strata-iq3','messages':[{'role':'user','content':'Antworte mit OK.'}],'max_tokens':1,'reasoning_effort':'none'}
with urllib.request.urlopen(urllib.request.Request('http://127.0.0.1:8120/v1/chat/completions',headers=headers,data=json.dumps(body).encode()),timeout=240) as r:
value=json.load(r);result.update(restored=r.status==200,restore_usage=value.get('usage',{}))
except Exception as e:result['restore_error_type']=type(e).__name__
out.mkdir(parents=True,exist_ok=True);(out/'extended-restore.json').write_text(json.dumps(result))
print(json.dumps(result),flush=True)
raise SystemExit(rc)