54 lines
3.6 KiB
Python
54 lines
3.6 KiB
Python
"""Athena host launcher: regular GUI unload first, isolated test, regular API restore."""
|
|
import json,os,pathlib,subprocess,time,urllib.request
|
|
P=pathlib.Path
|
|
STAGE=P('/opt/athena-deck-dev/batch-ab-20261014')
|
|
RUN=os.environ.get('TEST_RUN','strata-batch-ab-20261014')
|
|
if RUN not in ('strata-batch-ab-20261014','strata-batch-fixed16-20261014','strata-batch-fresh16-20261014'):
|
|
raise ValueError('Unknown isolated test directory')
|
|
OUT=P('/data/experiments')/RUN
|
|
def credentials():
|
|
d=json.loads(subprocess.check_output(['docker','inspect','athena-voxcpm2-web']))[0]
|
|
p=next(P(m['Source']) for m in d['Mounts'] if m['Destination']=='/data')
|
|
return json.loads((p/'deck-connection.json').read_text())['token']
|
|
def request(path,data=None):
|
|
req=urllib.request.Request('http://127.0.0.1:'+('8120' if path.startswith('/v1/') else '8108')+path,
|
|
data=json.dumps(data).encode() if data is not None else None,
|
|
headers={'Authorization':'Bearer '+credentials(),'Content-Type':'application/json'})
|
|
with urllib.request.urlopen(req,timeout=600) as r:return r.status,json.load(r)
|
|
def mark(phase,**extra):
|
|
p=OUT/'launcher.tmp';p.write_text(json.dumps(dict(phase=phase,updated=time.time(),**extra)));p.replace(OUT/'launcher-status.json')
|
|
def main():
|
|
_,s=request('/api/v1/status')
|
|
if s['endpoint']['active_requests'] or s['endpoint']['counts']['llm']['loaded']:
|
|
raise RuntimeError('Regularly unload idle Deck LLM first')
|
|
g=subprocess.check_output(['nvidia-smi','--query-compute-apps=pid','--format=csv,noheader,nounits'],text=True).strip()
|
|
if g and 'No running processes' not in g:raise RuntimeError('GPU processes still present; no test started')
|
|
d=json.loads(subprocess.check_output(['docker','inspect','athena-deck-dev']))[0]
|
|
args=['docker','run','--rm','--name','athena-'+RUN,'--gpus','all',
|
|
'--user','65534:65534','--read-only','--cap-drop','ALL','--security-opt','no-new-privileges:true',
|
|
'--memory','44g','--memory-swap','44g','--cpus','6','--network','none',
|
|
'--tmpfs','/tmp:rw,nosuid,nodev,size=512m','-e','HOME=/experiment/home',
|
|
'-e','PYTHONDONTWRITEBYTECODE=1','-e','NVIDIA_DRIVER_CAPABILITIES=compute,utility','--entrypoint','python3']
|
|
for name in ('TEST_RESIDENT_GIB','TEST_REPETITIONS','TEST_TARGETS','TEST_ARMS'):
|
|
if name in os.environ:args+=['-e',name+'='+os.environ[name]]
|
|
for m in d['Mounts']:
|
|
if m['Type']=='bind' and (m['Destination']=='/var/lib/deck' or 'strata' in m['Destination']):
|
|
args+=['--mount',f"type=bind,src={m['Source']},dst={m['Destination']},readonly"]
|
|
args+=['--mount',f'type=bind,src={STAGE},dst=/test,readonly','--mount',f'type=bind,src={OUT},dst=/experiment',d['Config']['Image'],'/test/benchmark.py']
|
|
try:
|
|
mark('running')
|
|
with (OUT/'container-test.log').open('w') as f:r=subprocess.run(args,stdout=f,stderr=subprocess.STDOUT)
|
|
mark('test_complete' if r.returncode==0 else 'test_failed',exit_code=r.returncode)
|
|
finally:
|
|
_,s=request('/api/v1/status');e=s['endpoint']
|
|
if e['active_requests'] or e['counts']['llm']['loaded']:
|
|
mark('restore_skipped_new_activity')
|
|
else:
|
|
previous=json.loads((STAGE/'base-template.json').read_text())['previous_model']
|
|
status,_=request('/v1/chat/completions',dict(model=previous,messages=[dict(role='user',content='OK')],max_tokens=1,reasoning_effort='none'))
|
|
(OUT/'restore.json').write_text(json.dumps(dict(http_status=status,model=previous)))
|
|
mark('finished',restored=status==200,model=previous)
|
|
if __name__=='__main__':
|
|
try:main()
|
|
except BaseException as e:mark('launcher_failed',error_type=type(e).__name__);raise
|