Publish the reviewed accumulated runtime, scheduler, profile, UI, native recipes and historical maintenance evidence. Includes Qwen GPU ASR correction and shared Anna/atelier ownership. Validated with 784 local tests, Python/JSON parsing and eight JavaScript syntax checks. Live GPU acceptance and full fresh-host restore limits remain documented.
75 lines
7.5 KiB
Python
75 lines
7.5 KiB
Python
#!/usr/bin/env python3
|
|
"""Athena host: GPU-ASR overlay; requires explicit Go and regular GUI drain."""
|
|
import argparse,hashlib,importlib.util,json,shutil,subprocess,time
|
|
from pathlib import Path
|
|
ROOT=Path('/opt/athena-deck-dev/asr-gpu-activation');BASE=Path('/opt/athena-deck-dev/runtime');STATE=BASE/'state';SOURCE=Path('/opt/athena-deck-dev/source');IMAGE='athena-deck-standalone:qwen-asr-gpu'
|
|
FILES=('profiles.py','profiles-ui.js','backup.py','stt.py','inference.py','server.py','audio_policy.py','video.py','video_comfy.py','deploy/QWEN_ASR_GPU.md','deploy/qwen-asr-3060-profile.json','deploy/install.py')
|
|
SETTINGS=('profiles.json','endpoint.json','audio-policy.json','cpu-partition.json','reasoning-budget.json')
|
|
def sha(p):return hashlib.sha256(p.read_bytes()).hexdigest() if p.is_file() else None
|
|
def info():return json.loads(subprocess.check_output(['docker','inspect','athena-deck-dev'],text=True))[0]
|
|
def save(a):
|
|
p=ROOT/'activation.json';p.write_text(json.dumps(a,indent=2));p.chmod(0o600);assert json.loads(p.read_text())==a
|
|
|
|
def prepare():
|
|
assert not (ROOT/'activation.json').exists()
|
|
d=info();tag=d['Config']['Image'];assert subprocess.check_output(['docker','image','inspect','--format','{{.Id}}',tag],text=True).strip()==d['Image']
|
|
app=ROOT/'image/app';original=(SOURCE/'deploy/install.py').read_text();anchor="FILES += ['cpu_partition.py']";assert anchor in original
|
|
(app/'deploy/install.py').write_text(original.replace(anchor,anchor+"\nFILES += ['deploy/QWEN_ASR_GPU.md','deploy/qwen-asr-3060-profile.json']",1))
|
|
before={n:sha(SOURCE/n) for n in FILES};after={n:sha(app/n) for n in FILES};assert all(after.values())
|
|
for n in FILES:
|
|
(app/n).chmod(0o644)
|
|
if before[n]:
|
|
p=ROOT/'before'/n;p.parent.mkdir(parents=True,exist_ok=True);shutil.copy2(SOURCE/n,p)
|
|
(ROOT/'image/Dockerfile').write_text('FROM '+tag+'\nUSER root\nCOPY app/ /app/\nUSER 65534:65534\n')
|
|
(ROOT/'image/.dockerignore').write_text('*\n!Dockerfile\n!app/\n!app/**\n')
|
|
with (ROOT/'build.log').open('w') as f:subprocess.run(['docker','build','--network','none','--pull=false','-t',IMAGE,ROOT/'image'],stdout=f,stderr=subprocess.STDOUT,check=True,timeout=180)
|
|
probe="from pathlib import Path;import tempfile;from server import Server;from stt import qwen_asr_request;assert 'Transcribe audio' not in str(qwen_asr_request(b'fixture','de'));t=tempfile.TemporaryDirectory();s=Server(0,state_dir=Path(t.name));s.endpoint.close();s.video.close();s.dashboard.close();s.server_close();t.cleanup();print('Isolated full Server and ASR protocol passed')"
|
|
subprocess.run(['docker','run','--rm','--network','none','--read-only','--user','65534:65534','--memory','512m','--pids-limit','256','--cap-drop','ALL','-e','NVIDIA_VISIBLE_DEVICES=void','-e','DECK_REQUIRE_SETUP=0','-e','DECK_NETWORK_MODE=disabled','-e','TMPDIR=/test-tmp','--mount','type=bind,src='+str(STATE/'basalt-runtime/tmp')+',dst=/test-tmp','--entrypoint','python3',IMAGE,'-B','-c',probe],check=True,timeout=45)
|
|
assert info()['State']['StartedAt']==d['State']['StartedAt']
|
|
save(dict(phase='prepared',image_before=tag,image_id_before=d['Image'],started_before=d['State']['StartedAt'],source_before=before,source_after=after,config=json.loads((BASE/'installation.json').read_text()),settings={n:(STATE/n).read_text() for n in SETTINGS}))
|
|
print('GPU-ASR image prepared and constructor verified; production unchanged')
|
|
def apply():
|
|
a=json.loads((ROOT/'activation.json').read_text());assert a['phase']=='prepared';d=json.loads((ROOT/'drained.json').read_text());assert time.time()-d['checked_at']<60 and d['state']=='stopped' and type(d['active_requests']) is int and d['active_requests']==0
|
|
assert all(type(d['scheduler'][k]) is int and d['scheduler'][k]==0 for k in ('active_requests','waiting_requests','tts_waiting_requests')) and d['scheduler']['switching'] is False
|
|
assert info()['Image']==a['image_id_before'] and all(sha(SOURCE/n)==a['source_before'][n] for n in FILES)
|
|
assert all((STATE/n).read_text()==a['settings'][n] for n in SETTINGS if n!='endpoint.json')
|
|
subprocess.run(['docker','stop','--timeout','45','athena-deck-dev'],check=True)
|
|
assert not subprocess.check_output(['nvidia-smi','--query-compute-apps=pid','--format=csv,noheader,nounits'],text=True).strip()
|
|
for n in FILES:
|
|
(SOURCE/n).parent.mkdir(parents=True,exist_ok=True);shutil.copy2(ROOT/'image/app'/n,SOURCE/n)
|
|
(STATE/'endpoint.json').write_text(a['settings']['endpoint.json'])
|
|
code="""import json,pathlib,os
|
|
from types import SimpleNamespace
|
|
from catalog import Catalog
|
|
from profiles import Profiles
|
|
from runtime import Runtime
|
|
from inference import Scheduler
|
|
from stt import STT
|
|
from endpoint import Endpoint
|
|
class RegistrationCatalog(Catalog):
|
|
def _save_history(self):pass
|
|
root=pathlib.Path(os.environ.get('DECK_ASR_STATE','/var/lib/deck'));catalog=RegistrationCatalog(root/'models');profiles=Profiles(root/'profiles.json',catalog)
|
|
worker=SimpleNamespace(status=lambda:{'state':'stopped'},stop=lambda:None);scheduler=Scheduler(worker);stt=STT(profiles,catalog,Runtime(root/'runtime'));stt.acquire=scheduler.stt_reservation;profiles.stt_blockers=stt.blockers
|
|
data=json.loads(pathlib.Path('/app/deploy/qwen-asr-3060-profile.json').read_text());assert not any(p.get('api_id')==data['api_id'] for p in profiles.rows);p=profiles.save(data)
|
|
ep=Endpoint(root,profiles,worker,scheduler,SimpleNamespace(status=lambda:{'job':None}),SimpleNamespace(read=lambda:None),8108);ep.stt=stt
|
|
for old in profiles.rows:
|
|
if old['kind']=='stt' and old['id']!=p['id'] and old['id'] in ep.config['enabled_profiles']:ep.enable({'id':old['id'],'enabled':False})
|
|
ep.enable({'id':p['id'],'enabled':True});actual=json.loads((root/'endpoint.json').read_text());assert p['id'] in actual['enabled_profiles'];assert json.loads((root/'profiles.json').read_text())[-1]['parameters']['stt_device']==data['parameters']['stt_device']
|
|
print('GPU-ASR profile saved and published via maintained classes; no model loaded')
|
|
"""
|
|
mounts=[]
|
|
for v in [a['config'].get('strata_storage'),*a['config'].get('strata_storage_mounts',[]),*a['config'].get('external_model_roots',[])]:
|
|
if not v:continue
|
|
p=Path(v);assert p.is_absolute() and p.is_dir() and not {'vpn','vpn.auth','OpenVPN-KIT','GluetunVPN'}&set(p.parts);mounts+=['--mount','type=bind,src='+str(p)+',dst='+str(p)+',readonly']
|
|
subprocess.run(['docker','run','--rm','--network','none','--read-only','--user','65534:65534','--cap-drop','ALL','-e','NVIDIA_VISIBLE_DEVICES=void','--mount','type=bind,src='+str(STATE)+',dst=/var/lib/deck',*mounts,'--entrypoint','python3',IMAGE,'-B','-c',code],check=True,timeout=45)
|
|
assert all((STATE/n).read_text()==a['settings'][n] for n in SETTINGS if n not in ('endpoint.json','profiles.json'))
|
|
subprocess.run(['docker','rm','athena-deck-dev'],check=True)
|
|
spec=importlib.util.spec_from_file_location('deck_install',SOURCE/'deploy/install.py');assert spec and spec.loader;i=importlib.util.module_from_spec(spec);spec.loader.exec_module(i);c=dict(a['config'],image=IMAGE,previous_image=a['image_before']);i.launch(c);i.ready(c)
|
|
end=time.monotonic()+90
|
|
while info()['State'].get('Health',{}).get('Status')=='starting' and time.monotonic()<end:time.sleep(1)
|
|
assert info()['State']['Health']['Status']=='healthy';i.write_manifest(BASE,c);assert all(sha(SOURCE/n)==a['source_after'][n] for n in FILES)
|
|
a.update(phase='activated; GPU-ASR functional acceptance pending',activated_at=time.time());save(a);print('GPU-ASR activated and healthy; restore Basalt and check real ASR now')
|
|
if __name__=='__main__':
|
|
p=argparse.ArgumentParser();p.add_argument('operation',choices=('prepare','apply'));p.add_argument('--go',action='store_true');a=p.parse_args();assert a.go,'Explicit Michael Go required'
|
|
prepare() if a.operation=='prepare' else apply()
|