Interplane page as plain text, for reading tools and agents. English is the reference text: translate it with your own tool. Text in backticks and in ``` blocks (commands, fingerprints, file names) and link targets in <...> are exact: copy them, never translate them. Page: /drakestapleton/aien-sovereign-core-mv/blob/main/om/ribbon/model_check.py # 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 Sign in to star 0 stars 0 watching About Files History Releases Proposed changes Issues For developers branch `main` Branches Tags History `aien-sovereign-core-mv / om / ribbon / model_check.py` 92 lines ยท 4545 bytes Raw Blame History 1 #!/usr/bin/env python3 2 # SPDX-License-Identifier: Apache-2.0 3 """External full-model qualification instrument; never part of serving.""" 4 import argparse 5 import hashlib 6 import json 7 import os 8 from pathlib import Path 9 import subprocess 10 import sys 11 import time 12 13 parser = argparse.ArgumentParser(description=__doc__) 14 parser.add_argument('binary', type=Path) 15 parser.add_argument('checkpoint', type=Path) 16 parser.add_argument('golden', type=Path) 17 parser.add_argument('output', type=Path) 18 parser.add_argument('--gpu-library', required=True, type=Path) 19 parser.add_argument('--omega-revision', required=True) 20 parser.add_argument('--bridge-library', required=True, type=Path) 21 parser.add_argument('--pairs', type=int, default=5) 22 parser.add_argument('--no-warmup', action='store_true') 23 args = parser.parse_args() 24 assert 1 <= args.pairs <= 20 25 root = args.output 26 root.mkdir(parents=True, exist_ok=False) 27 binary, model, golden, library = args.binary, args.checkpoint, args.golden, args.gpu_library 28 sha = lambda p: hashlib.sha256(p.read_bytes()).hexdigest() 29 (root / 'instrument.py').write_bytes(Path(__file__).read_bytes()) 30 (root / 'identity.json').write_text(json.dumps({ 31 'binary': str(binary), 'binary_sha256': sha(binary), 32 'gpu_library': str(library), 'gpu_library_sha256': sha(library), 33 'omega': args.omega_revision, 34 'golden': str(golden), 'golden_sha256': sha(golden), 35 'native_bridge_sha256': sha(args.bridge_library), 36 'window': os.environ.get('SPARK_WINDOW_DIR'), 37 }, indent=2)+'\n') 38 rows = [] 39 reference = None 40 reference_io = None 41 def gpu_snapshot(path): 42 result = subprocess.run(['nvidia-smi', '--query-gpu=timestamp,pstate,temperature.gpu,clocks.sm,clocks.mem,power.draw,memory.used,utilization.gpu', 43 '--format=csv,noheader'], text=True, capture_output=True, timeout=10) 44 path.write_text(result.stdout + result.stderr) 45 if result.returncode: 46 raise RuntimeError('GPU telemetry unavailable') 47 48 # Warmups are retained and explicitly excluded from paired statistics. 49 warmup = [] if args.no_warmup else ['grouped', '1', '2'] 50 measured = [mode for pair in range(args.pairs) 51 for mode in (['1', '2'] if pair % 2 == 0 else ['2', '1'])] 52 for i, mode in enumerate(warmup + measured): 53 dest = root / ('%02d-%s' % (i, mode)) 54 env = os.environ.copy() 55 env['LD_LIBRARY_PATH'] = str(args.bridge_library.resolve().parent) 56 env.pop('AIEN_RIBBON_OMEGA_BUFFERS', None) 57 if mode != 'grouped': 58 env['AIEN_RIBBON_OMEGA_BUFFERS'] = mode 59 cmd = [str(binary), 'chip', str(model), str(golden), str(dest), 60 '--tokens-only', '--prompts', '1', '--new', '16', '--weights', 'fp8', 61 '--attn', 'fused', '--router', 'device', '--lm-head', 'gemv', 62 '--prefill', 'auto', '--paged-experts', '768', 63 '--manifest', str(root / 'manifest.json'), 64 '--read-workers', '8', '--read-depth', '8'] 65 gpu_snapshot(root / ('%02d-gpu-before.csv' % i)) 66 t = time.monotonic() 67 with (root / ('%02d.log' % i)).open('w') as log: 68 p = subprocess.run(cmd, env=env, stdout=log, stderr=subprocess.STDOUT, timeout=240) 69 finished = time.monotonic() 70 gpu_snapshot(root / ('%02d-gpu-after.csv' % i)) 71 run = json.loads((dest / 'run.json').read_text()) if (dest / 'run.json').exists() else {} 72 assert run.get('engine', {}).get('native') is True, 'not native GPU' 73 assert run['native_identity']['archive_sha256'] == sha(library), 'linked GPU library differs' 74 prompt = run.get('prompts', [{}])[0] 75 tokens = prompt.get('chip') 76 assert tokens and prompt.get('first_diff') is None, 'golden token mismatch' 77 if reference is None: 78 reference = tokens 79 io = {k: prompt['ribbon'][k] for k in ('hit', 'miss', 'bytes_loaded', 'device_read_bytes', 'reads_submitted')} 80 if reference_io is None: 81 reference_io = io 82 assert io == reference_io, 'expert workload changed between modes' 83 row = {'trial': i, 'mode': mode, 'warmup': i < len(warmup), 84 'exit': p.returncode, 'wall_s': finished-t, 85 'pass': run.get('pass') is True, 'same_tokens': tokens == reference, 86 'prompt': prompt} 87 rows.append(row) 88 (root / 'summary.json').write_text(json.dumps(rows, indent=2)+'\n') 89 print(json.dumps({k:v for k,v in row.items() if k != 'prompt'}), flush=True) 90 if p.returncode or not row['pass'] or not row['same_tokens']: 91 raise SystemExit('full-model correctness failed; see retained trial') 92 print('PASS full-model exact tokens,', args.pairs, 'pairs, warmups excluded', flush=True)