interplane.Get Omega
Read in your language

aien-architecture-mv

Canonical architecture for the AIEN ecosystem: flows, boundaries, ADRs, and the map from design to implementation repositories.

Brought by drakestapleton

branch main Branches Tags History

aien-architecture-mv / evidence / QUANTUM_EFFICIENCY / 2026-10-22 / validate_probe.py

58 lines · 2643 bytes Raw Blame History
1#!/usr/bin/env python3
2"""Independent CPU oracle checks of the throwaway probe, never inference.
3Run: uv run --with numpy --with ml-dtypes validate_probe.py
4Synthetic bytes only. No SSH, GPU, model loading, or timing.
5"""
6import base64
7import hashlib
8import json
9import pathlib
10from unittest.mock import patch
11import numpy as np
12import ml_dtypes
13import weight_probe as probe
14
15
16def payload(codes):
17 name = 'model.language_model.layers.0.mlp.experts.0.gate_proj'
18 raw = codes.tobytes()
19 scale = np.array([0x3F80], dtype='<u2').tobytes() # exact BF16 1
20 return json.dumps({
21 name+'.weight': {'meta': {'dtype': 'F8_E4M3', 'shape': [128, 128],
22 'data_offsets': [0, len(raw)]},
23 'raw': base64.b64encode(raw).decode(),
24 'sha256': hashlib.sha256(raw).hexdigest()},
25 name+'.weight_scale_inv': {'meta': {'dtype': 'BF16', 'shape': [1, 1],
26 'data_offsets': [len(raw), len(raw)+2]},
27 'raw': base64.b64encode(scale).decode(),
28 'sha256': hashlib.sha256(scale).hexdigest()}
29 }).encode()
30
31
32finite = np.array([i for i in range(256) if i not in (127, 255)], dtype=np.uint8)
33codes = np.resize(finite, (128, 128))
34reference = codes.view(ml_dtypes.float8_e4m3fn).astype(np.float64)
35with patch.object(probe.subprocess, 'check_output', return_value=payload(codes)):
36 actual, _ = probe.fetch(0, 0, 'gate_proj')
37assert np.array_equal(actual, reference)
38assert np.array_equal(np.signbit(actual), np.signbit(reference))
39refusals = []
40for bad in (127, 255):
41 broken = codes.copy()
42 broken[0, 0] = bad
43 with patch.object(probe.subprocess, 'check_output', return_value=payload(broken)):
44 try:
45 probe.fetch(0, 0, 'gate_proj')
46 except AssertionError as exc:
47 assert str(exc) == 'NaN FP8 code'
48 refusals.append(bad)
49 else:
50 raise AssertionError('NaN decoder mutant escaped')
51result = {'verdict': 'PASS', 'finite_fp8_codes_compared': len(finite),
52 'signed_zero_checked': True, 'nan_codes_refused': refusals,
53 'transform_controls': probe.selfcheck(), 'numpy': np.__version__,
54 'ml_dtypes': ml_dtypes.__version__,
55 'probe_sha256': hashlib.sha256(pathlib.Path(probe.__file__).read_bytes()).hexdigest(),
56 'scope': 'Independent library FP8 oracle plus synthetic controls, not inference quality or speed'}
57pathlib.Path(__file__).with_name('probe-validation.json').write_text(json.dumps(result, indent=2)+'\n')
58print(json.dumps(result, indent=2))