Files
Athena-Deck/docs/maintenance/shared-qwen/restore.py
T
Mikei386 c0bc5d3a1b Integrate Basalt telemetry and shared GPU speech runtimes
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.
2026-11-03 21:16:41 +01:00

42 lines
3.2 KiB
Python

#!/usr/bin/env python3
"""NAS: bounded model restoration and synthetic shared-Qwen GUI references.
No management bypass or profile-publication change. Credentials stay in memory.
"""
import importlib.util,io,json,os,subprocess,time,urllib.request,wave
from pathlib import Path
HERE=Path(__file__).resolve().parent
spec=importlib.util.spec_from_file_location('managed_transport',HERE.parent/'basalt-candidate-2026-11-01/paired_transport.py');assert spec and spec.loader
transport=importlib.util.module_from_spec(spec);spec.loader.exec_module(transport)
KEY=transport.key();START=time.monotonic();BASE='http://192.168.1.212:8120';OUT=Path(os.environ['TMPDIR'])/'shared-qwen-acceptance';OUT.mkdir(mode=0o700,exist_ok=True)
def call(path,data,binary=False):
assert time.monotonic()-START<900,'Bounded acceptance window exceeded'
req=urllib.request.Request(BASE+path,data=json.dumps(data).encode(),headers={'Authorization':'Bearer '+KEY,'Content-Type':'application/json'})
with urllib.request.urlopen(req,timeout=180) as r:return r.read() if binary else json.load(r)
def speech(name,voice,text):
data=call('/v1/audio/speech',dict(model='qwen-anna-gpu-3060',voice=voice,input=text,response_format='wav'),True)
with wave.open(io.BytesIO(data)) as w:meta=dict(rate=w.getframerate(),channels=w.getnchannels(),seconds=w.getnframes()/w.getframerate())
assert meta['rate']==24000 and meta['channels']==1 and meta['seconds']>0
p=OUT/name;p.write_bytes(data);p.chmod(0o600);return meta
def gpu_snapshot():
raw=subprocess.check_output(['athena-ssh','nvidia-smi --query-compute-apps=gpu_uuid,pid,process_name,used_gpu_memory --format=csv,noheader,nounits'],text=True,timeout=15)
result=[]
for line in raw.splitlines():
gpu,pid,path,mib=[s.strip() for s in line.split(',')]
role='tts' if '/tts-runtime/' in path else 'vision' if path.endswith('basalt-vision') else 'chat' if path.endswith('/basalt') else 'stt' if path.endswith('llama-server') else 'other'
result.append(dict(gpu=gpu,pid=int(pid),role=role,mib=int(mib)))
return result
def main():
result={}
response=call('/v1/chat/completions',dict(model='flash-next-basalt',messages=[dict(role='user',content='Antworte nur mit BEREIT.')],temperature=0,max_tokens=16,chat_template_kwargs={'enable_thinking':False}))
assert 'BEREIT' in (response['choices'][0]['message'].get('content') or '').upper();result['basalt_restored']=True;print('Basalt restored and actual answer verified',flush=True)
result['anna_before']=speech('anna-before.wav','default','Die gemeinsame Stimme wird im Atelier getestet.');print('Anna speech API passed',flush=True)
result['reference_text']='Dies ist eine synthetische Referenz für den Stimmtest.'
result['reference']=speech('reference.wav','Ryan',result['reference_text']);print('Synthetic Ryan reference prepared; no default voice changed',flush=True)
result['gpu_before_clone']=gpu_snapshot();assert len([r for r in result['gpu_before_clone'] if r['role']=='tts'])==1
result.update(stage='models restored; authenticated atelier acceptance pending',seconds=time.monotonic()-START)
p=OUT/'restoration.json';p.write_text(json.dumps(result,indent=2));assert json.loads(p.read_text())==result
print(json.dumps(result),flush=True)
if __name__=='__main__':main()