aien-sovereign-core-mv
AienOS host runtime: inference scheduling, paged KV state, the aien CLI and Spark verification tooling. Its inference engine is in alpha testing (DGX Spark GB10); Omega is the implementation destination.
Brought by drakestapleton
aien-sovereign-core-mv / om / q38-head / replay.py
| 1 | #!/usr/bin/env python3 |
| 2 | # SPDX-License-Identifier: Apache-2.0 |
| 3 | """External replay against independently captured full GPU scores.""" |
| 4 | import ctypes as C |
| 5 | import json |
| 6 | from pathlib import Path |
| 7 | import statistics |
| 8 | import sys |
| 9 | import time |
| 10 | |
| 11 | N,H=248320,5120 |
| 12 | lib=C.CDLL(str(Path(sys.argv[1]).resolve())) |
| 13 | call=lib.omega_q38select |
| 14 | call.restype=C.c_uint32 |
| 15 | call.argtypes=[C.POINTER(C.c_uint64),C.c_void_p,C.c_uint64,C.c_void_p,C.c_uint64,C.c_void_p,C.c_uint64,C.c_void_p,C.c_uint64,C.c_uint64] |
| 16 | cap,data=Path(sys.argv[2]),Path(sys.argv[3]) |
| 17 | def read(path,n): |
| 18 | b=path.read_bytes() |
| 19 | assert len(b)==n*4 |
| 20 | return (C.c_float*n).from_buffer_copy(b) |
| 21 | coef=read(data/'coef.f32',N) |
| 22 | rows=[] |
| 23 | meta=json.loads((cap/'capture.json').read_text()) |
| 24 | assert not meta['mismatches'] |
| 25 | for item in meta['rows']: |
| 26 | pos=item['pos'] |
| 27 | h=read(cap/f'{pos}-hidden.f32',H) |
| 28 | s=read(data/f'{pos}-screen.f32',N) |
| 29 | gpu=read(cap/f'{pos}-logits.f32',N) |
| 30 | mask=(C.c_ubyte*N)(); result=C.c_uint64() |
| 31 | t=time.perf_counter_ns() |
| 32 | rc=call(C.byref(result),h,H,s,N,coef,N,mask,N,N) |
| 33 | elapsed=time.perf_counter_ns()-t |
| 34 | assert rc==0 |
| 35 | candidates=[i for i in range(N) if mask[i]] |
| 36 | assert len(candidates)==result.value and candidates |
| 37 | # max retains the first index on ties because candidates are ascending. |
| 38 | picked=max(candidates,key=lambda i:gpu[i]) |
| 39 | assert picked==item['argmax'] and picked==max(range(N),key=lambda i:gpu[i]) |
| 40 | rows.append({'position':pos,'candidates':len(candidates),'winner_retained':True,'selector_ns':elapsed}) |
| 41 | print(json.dumps({'status':'PASS','scope':'native Omega selector with host compact scores and captured full GPU scores', |
| 42 | 'rows':rows,'median_selector_ns':statistics.median(r['selector_ns'] for r in rows), |
| 43 | 'calculation':'median wall nanoseconds over eight replay calls; host overhead only; not end-to-end or uncontended timing'},indent=2)) |