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 / crates / aien-omega-q38 / om / check.py
| 1 | # SPDX-License-Identifier: Apache-2.0 |
| 2 | # Independent external oracle: enumerate all possible cuts and count actual chunks. |
| 3 | import ctypes,json,random,sys |
| 4 | M=(1<<64)-1 |
| 5 | f=ctypes.CDLL(sys.argv[1]).omega_native_pfcut |
| 6 | f.argtypes=[ctypes.POINTER(ctypes.c_uint64)]+[ctypes.c_uint64]*5;f.restype=ctypes.c_uint32 |
| 7 | cases=0 |
| 8 | def actual(n,c,m): |
| 9 | if n<m:return n |
| 10 | count=0 |
| 11 | while n: |
| 12 | take=n if n<=c else n-m if n-c<m else c |
| 13 | n-=take;count+=1 |
| 14 | return count |
| 15 | def call(a,h,t,c,m): |
| 16 | global cases |
| 17 | r=ctypes.c_uint64(71);assert f(ctypes.byref(r),a,h,t,c,m)==0 |
| 18 | cases+=1;return r.value |
| 19 | for minimum in [1,2,3,4]: |
| 20 | for chunk in sorted(set([2*minimum,2*minimum+1,12,31,512])): |
| 21 | if chunk<2*minimum:continue |
| 22 | for n in range(1,97): |
| 23 | costs=[actual(k,chunk,minimum) for k in range(n+1)] |
| 24 | eligible=[k for k in range(n) if costs[k]+costs[n-k]<=costs[n]] |
| 25 | for header in range(n): |
| 26 | want=header if 0<header<minimum or n-header<minimum else max(k for k in eligible if k<=header and (k==0 or k>=minimum) and n-k>=minimum) |
| 27 | for offset in [0,37,M-200]: |
| 28 | got=call(offset,offset+header,offset+n,chunk,minimum) |
| 29 | assert got==offset+want,(offset,header,n,chunk,minimum,got,offset+want) |
| 30 | # Wider contexts, independently enumerate all cut candidates. |
| 31 | rng=random.Random(710) |
| 32 | for _ in range(160): |
| 33 | n=rng.randrange(3,9000);c=rng.choice([6,31,64,128,512,1024,32768]);h=rng.randrange(n) |
| 34 | costs=[actual(k,c,3) for k in range(n+1)] |
| 35 | want=h if 0<h<3 or n-h<3 else max(k for k in range(h+1) if (k==0 or k>=3) and n-k>=3 and costs[k]+costs[n-k]<=costs[n]) |
| 36 | assert call(0,h,n,c,3)==want,(h,n,c,want) |
| 37 | # Unbounded Python integer arithmetic checks the u64 overflow boundaries. |
| 38 | for n in [M-1,M,M-512,M-513]: |
| 39 | for c in [6,512,32768]: |
| 40 | for h in [0,1,n//2,n-2,n-1]: |
| 41 | got=call(0,h,n,c,3) |
| 42 | cost=lambda k:k if k<3 else (k+c-1)//c |
| 43 | assert (got==h if 0<h<3 or n-h<3 else got<=h and (got==0 or got>=3) and n-got>=3 and cost(got)+cost(n-got)<=cost(n)),(n,c,h,got) |
| 44 | assert call(M-1,M-1,M,512,3)==M-1 |
| 45 | for args in [(1,0,5,512,3),(0,5,5,512,3),(0,6,5,512,3),(0,0,0,512,3),(0,3,5,5,3),(0,3,5,32769,3),(0,3,5,512,0),(0,3,5,32768,16385),(0,3,5,512,M)]: |
| 46 | assert call(*args)==M,args |
| 47 | assert f(None,0,23,30,512,3)==32 |
| 48 | print(json.dumps({'pass':True,'cases':cases,'oracle':'preserve scalar pieces; enumerate latest batch-only cut with no additional chunks','large_integer_boundaries':True})) |