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 / ribbon / check_evidence.py
| 1 | #!/usr/bin/env python3 |
| 2 | # SPDX-License-Identifier: Apache-2.0 |
| 3 | """Receipt integrity checks. Does not rerun or pretend to qualify hardware.""" |
| 4 | import gzip |
| 5 | import hashlib |
| 6 | import json |
| 7 | from datetime import datetime, timezone |
| 8 | from pathlib import Path |
| 9 | from zoneinfo import ZoneInfo |
| 10 | |
| 11 | from summarize_trace import summarize |
| 12 | |
| 13 | root = Path(__file__).resolve().parents[2] |
| 14 | here = Path(__file__).resolve().parent |
| 15 | sha = lambda data: hashlib.sha256(data).hexdigest() |
| 16 | qualification = json.loads((here/'qualification-samples.json').read_text()) |
| 17 | assert not qualification.get('control_correction'), 'obsolete control receipt' |
| 18 | for name, expected in qualification['source_files_sha256'].items(): |
| 19 | followup = qualification.get('post_measurement_changes', {}).get(name) |
| 20 | measured = root/followup['measured_source_snapshot'] if followup else root/name |
| 21 | assert sha(measured.read_bytes()) == expected, ('measured source drift', name) |
| 22 | if followup: |
| 23 | assert sha((root/name).read_bytes()) == followup['current_sha256'], ('reviewed source drift', name) |
| 24 | accepted = [s for s in qualification['samples'] if s['timing_accepted']] |
| 25 | assert len(accepted) == 10 |
| 26 | assert sum(s['mode'] == '1' for s in accepted) == 5 |
| 27 | assert sum(s['mode'] == '2' for s in accepted) == 5 |
| 28 | tokens = accepted[0]['prompt']['chip'] |
| 29 | assert len(tokens) == 16 |
| 30 | work = None |
| 31 | for sample in qualification['samples']: |
| 32 | p = sample['prompt'] |
| 33 | assert sample['pass'] and sample['same_tokens'] and p['first_diff'] is None |
| 34 | assert p['chip'] == tokens |
| 35 | io = {k:p['ribbon'][k] for k in ('hit','miss','bytes_loaded','device_read_bytes','reads_submitted')} |
| 36 | if work is None: work = io |
| 37 | assert io == work, 'different expert workload' |
| 38 | |
| 39 | driver = json.loads((here/'driver-observations.json').read_text()) |
| 40 | messages = [datetime.fromisoformat(e['utc']) for e in driver['events']] |
| 41 | def gpu_utc(text): |
| 42 | stamp = text.split(',')[0] |
| 43 | return datetime.strptime(stamp, '%Y/%m/%d %H:%M:%S.%f').replace(tzinfo=ZoneInfo('America/Chicago')).astimezone(timezone.utc) |
| 44 | for sample in accepted: |
| 45 | start, end = gpu_utc(sample['gpu_before']), gpu_utc(sample['gpu_after']) |
| 46 | assert not any(start <= t <= end for t in messages), 'driver message during accepted trial' |
| 47 | short_start, short_end = map(datetime.fromisoformat, driver['short_window_utc']) |
| 48 | assert not any(short_start <= t <= short_end for t in messages) |
| 49 | |
| 50 | traces = [json.loads(line) for line in (here/'chip-trace.jsonl').read_text().splitlines()] |
| 51 | unions = [json.loads(line) for line in (here/'chip-unions.jsonl').read_text().splitlines()] |
| 52 | assert len(traces) == len(unions) == 12 |
| 53 | for trace, union in zip(traces, unions): |
| 54 | assert not trace['failed'] |
| 55 | assert summarize(trace) == union |
| 56 | assert trace['completed'] + trace['rejected'] == 32 |
| 57 | if trace['mutant']: |
| 58 | assert trace['rejected'] == 1 |
| 59 | else: |
| 60 | assert trace['rejected'] == 0 |
| 61 | if trace['buffers'] == 1: |
| 62 | assert union['read_verify_compute_overlap_ns'] == 0 |
| 63 | |
| 64 | pack = root/'docs/qwen38/qualification-20261101' |
| 65 | index = json.loads((pack/'index.json').read_text()) |
| 66 | assert {r['stage'] for r in index['runs']} == {'short','long32','long64','long128'} |
| 67 | expected_count = {'long32':32768,'long64':65536,'long128':128000} |
| 68 | for run in index['runs']: |
| 69 | assert run['verdict'] == 'PASS' |
| 70 | directory = pack/run['stage'] |
| 71 | for category in ('request_and_response_files','additional_evidence','reconstructed_input_ids'): |
| 72 | for name, metadata in run[category].items(): |
| 73 | raw = gzip.decompress((directory/name).read_bytes()) |
| 74 | assert sha(raw) == metadata['uncompressed_sha256'], name |
| 75 | if 'uncompressed_bytes' in metadata: |
| 76 | assert len(raw) == metadata['uncompressed_bytes'] |
| 77 | if category == 'reconstructed_input_ids': |
| 78 | assert len(raw) == 4*metadata['tokens'] |
| 79 | events = [json.loads(line) for line in (directory/'events.jsonl').read_text().splitlines()] |
| 80 | assert any(e.get('event') == 'completed' and e.get('verdict') == 'PASS' for e in events) |
| 81 | assert any(e.get('event') == 'cleanup' and e.get('server_exit') == 0 for e in events) |
| 82 | assert run['reconstructed_input_ids'], 'missing exact input reconstruction' |
| 83 | for event in events: |
| 84 | if event.get('event') == 'request': |
| 85 | response = json.loads(gzip.decompress((directory/(event['name']+'.response.json.gz')).read_bytes())) |
| 86 | ids = response['usage']['aien_token_ids'] |
| 87 | assert sha(json.dumps(ids).encode()) == event['token_ids_sha256'] |
| 88 | if run['stage'] in expected_count: |
| 89 | first = next(e for e in events if e.get('name') == 'long-cold') |
| 90 | assert first['usage']['prompt_tokens'] == expected_count[run['stage']] |
| 91 | assert run['reconstructed_input_ids']['long-cold.request.u32le.gz']['tokens'] == expected_count[run['stage']] |
| 92 | resumed = next(e for e in events if e.get('name') == 'long-resumed') |
| 93 | cold = next(e for e in events if e.get('name') == 'long-follow-cold') |
| 94 | assert resumed['token_ids_sha256'] == cold['token_ids_sha256'] |
| 95 | else: |
| 96 | assert run['timing_qualified'] |
| 97 | selected = run['timing_samples'] |
| 98 | assert len(selected) == len(set(selected)) == 5 |
| 99 | assert not set(selected).intersection(run['timing_excluded']) |
| 100 | assert sum(e.get('name') in selected for e in events) == 5 |
| 101 | golden = json.loads((root/'crates/aien-inference-abi/fixtures/qwen38/decode-lighthouses-256.json').read_text())['ids'] |
| 102 | for name in selected: |
| 103 | reply = json.loads(gzip.decompress((directory/(name+'.response.json.gz')).read_bytes())) |
| 104 | assert reply['usage']['aien_token_ids'] == golden |
| 105 | stream = next(e for e in events if e.get('event') == 'stream') |
| 106 | assert 0 < stream['first_visible_s'] <= stream['completed_s'] |
| 107 | assert stream['usage']['aien_token_ids'] == golden |
| 108 | quality = json.loads(gzip.decompress((directory/'quality-results.json.gz').read_bytes())) |
| 109 | assert quality['coding']['grade']['pass'] and quality['coding']['repeat_tokens_identical'] |
| 110 | assert quality['prose']['repeat_tokens_identical'] and quality['prose']['word_count'] <= 120 |
| 111 | review = json.loads(gzip.decompress((directory/'quality-prose-review.json.gz').read_bytes())) |
| 112 | assert review['pass'] and all(review['criteria'].values()) |
| 113 | print('PASS controller/model receipt integrity, source digests, exact tokens and input-file digests') |