aien-architecture-mv
Canonical architecture for the AIEN ecosystem: flows, boundaries, ADRs, and the map from design to implementation repositories.
Brought by drakestapleton
aien-architecture-mv / evidence / QUANTUM_EFFICIENCY / 2026-10-22 / independent_byte_check.py
| 1 | #!/usr/bin/env python3 |
| 2 | """Read-only byte-level zero-channel confirmation; no FP8 decoder or GPU.""" |
| 3 | import json |
| 4 | import pathlib |
| 5 | import shlex |
| 6 | import subprocess |
| 7 | |
| 8 | REMOTE = r''' |
| 9 | import hashlib,json,pathlib,struct |
| 10 | p=pathlib.Path('/home/drakestapleton/models/qwen3.6-35b-a3b-fp8-95a723d0/layers-0.safetensors') |
| 11 | zeros={};hashes={} |
| 12 | with p.open('rb') as f: |
| 13 | n=struct.unpack('<Q',f.read(8))[0] |
| 14 | header=json.loads(f.read(n)) |
| 15 | for proj in ('gate_proj','up_proj','down_proj'): |
| 16 | key='model.language_model.layers.0.mlp.experts.0.'+proj+'.weight' |
| 17 | m=header[key] |
| 18 | assert m['dtype']=='F8_E4M3' |
| 19 | rows,cols=m['shape'] |
| 20 | a,b=m['data_offsets']; f.seek(8+n+a); raw=f.read(b-a) |
| 21 | assert len(raw)==rows*cols==b-a |
| 22 | hashes[proj]=hashlib.sha256(raw).hexdigest() |
| 23 | if proj=='down_proj': |
| 24 | assert (rows,cols)==(2048,512) |
| 25 | zeros[proj]=[j for j in range(cols) if all((raw[i*cols+j]&127)==0 for i in range(rows))] |
| 26 | else: |
| 27 | assert (rows,cols)==(512,2048) |
| 28 | zeros[proj]=[i for i in range(rows) if all((v&127)==0 for v in raw[i*cols:(i+1)*cols])] |
| 29 | print(json.dumps({'zero_counts':{k:len(v) for k,v in zeros.items()}, |
| 30 | 'identical_support':zeros['gate_proj']==zeros['up_proj']==zeros['down_proj'], |
| 31 | 'zero_indices':zeros['gate_proj'],'tensor_hashes':hashes})) |
| 32 | ''' |
| 33 | result=json.loads(subprocess.check_output(['ssh','-o','BatchMode=yes','spark','python3 -c '+shlex.quote(REMOTE)])) |
| 34 | expected=json.loads(pathlib.Path(__file__).with_name('zero-support-byte-confirm.json').read_text()) |
| 35 | assert result==expected, 'Checkpoint bytes/support changed since the original probe' |
| 36 | out={'verdict':'PASS','method':'raw E4M3 byte magnitude bits, independent of floating-point decoder', |
| 37 | 'scope':'one selected expert only; no generation or timing','result':result} |
| 38 | pathlib.Path(__file__).with_name('byte-confirm-replay.json').write_text(json.dumps(out,indent=2)+'\n') |
| 39 | print(json.dumps({k:out[k] for k in ('verdict','method','scope')})) |
| 40 | print(json.dumps(result['zero_counts']), 'identical_support=',result['identical_support']) |