Skip to content

Commit b5f9e64

Browse files
committed
Verify concurrent reference provenance and retain negative startup evidence
1 parent ec4c7c3 commit b5f9e64

3 files changed

Lines changed: 46 additions & 1 deletion

File tree

‎tests/test_cpu_parallel_references.py‎

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010

1111
from tools.cpu_parallel_references import run,wait_for_reference
1212
from tools.parallel_cpu_serving import digest
13+
from tools.verify_memory_application import cpu_projection,verify_cpu_schedule
1314

1415

1516
class ParallelReferenceTests(unittest.TestCase):
@@ -61,5 +62,40 @@ def test_dispatcher_wait_returns_only_an_actual_registered_reference(self):
6162
with self.assertRaises(ValueError):wait_for_reference(args)
6263
args.cohort='parallel-shared-host';self.assertFalse(wait_for_reference(args))
6364

65+
def test_public_verifier_checks_actual_reference_execution_and_source(self):
66+
import gzip
67+
with tempfile.TemporaryDirectory() as temp:
68+
root=Path(temp);folder=root/'llm/models/m0';folder.mkdir(parents=True)
69+
phase='retime-llm-cpu';plan={'workers':8,'lanes':{
70+
str(i):{'cpus':[i],'physical_cores':[[0,i]]} for i in range(8)},'model_lanes':{phase:{'m0':'0'}}}
71+
cpu=root/'cpu-serving-parallel-plan.json';cpu.write_text(json.dumps(plan));cpu_hash=digest(cpu)
72+
ref=root/'cpu-parallel-reference-plan.json';ref.write_text(json.dumps({'workers':8,'original_cpu_plan_sha256':cpu_hash}));ref_hash=digest(ref)
73+
worker_hash=digest(Path(__file__).parents[1]/'tools/parallel_cpu_serving.py')
74+
source_hash=digest(Path(__file__).parents[1]/'tools/cpu_parallel_references.py')
75+
request={'model':'m0','name':'raw-fp32','cache':0,'batch':1,'mode':'codec','job':'job'}
76+
a={'decoded_row_sha256':'rows','cpu_affinity':[0],'cpu_lane':'0','cpu_parallel_plan_sha256':cpu_hash,
77+
'measurement_cohort':'parallel-shared-host','worker_source_sha256':worker_hash,'environment':{'commit':'fixture'},
78+
'query':{'test':{'input_hashes':['input'],'output_hashes':['output'],'p50_ms':2.}}}
79+
b={**a,'measurement_cohort':'serial-reference','query':{'test':{'input_hashes':['input'],'output_hashes':['output'],'p50_ms':1.}},
80+
'reference_execution':{'kind':'parallel-fixed-core','workers':8,'plan_sha256':ref_hash,'source_sha256':source_hash}}
81+
def save():
82+
with gzip.open(folder/'serial-references.json.gz','wt') as stream:json.dump([
83+
{'request':request,'report':b,'private_sha256':'ref','parallel_to_serial_p50_ratios':{'test':2.}}],stream)
84+
controller={'status':'complete','workers':8,'serial_reference_workers':8,'reference_execution':'parallel-fixed-core',
85+
'parallel_reference_plan_sha256':ref_hash,'cpu_parallel_plan_sha256':cpu_hash,'model_lanes':plan['model_lanes'][phase],
86+
'lanes':plan['lanes'],'requests':[request],'complete':[{}],'reference_requests':[request],
87+
'serial_references':[{'request':request,'sha256':'ref','parallel_output_sha256':'primary','parallel_to_serial_p50_ratios':{'test':2.}}]}
88+
records=[{'request':request,'report':cpu_projection(a),'private_sha256':'primary'}]
89+
inventory={'fixture':{'files':{'tools/parallel_cpu_serving.py':{'original_sha256':worker_hash},
90+
'tools/cpu_parallel_references.py':{'original_sha256':source_hash}}}}
91+
private={'cpu-serving-parallel-plan.json':cpu_hash,'cpu-parallel-reference-plan.json':ref_hash}
92+
with patch('tools.verify_memory_application.source'),patch('tools.verify_memory_application.llm_timing'):
93+
save();verify_cpu_schedule(root,controller,{'models':[{'name':'m0','choices':[]}]},records,phase,'llm/models',inventory,private)
94+
for field,value in [('workers',1),('source_sha256','changed'),('plan_sha256','changed')]:
95+
original=b['reference_execution'][field];b['reference_execution'][field]=value;save()
96+
with self.subTest(field=field),self.assertRaises(AssertionError):
97+
verify_cpu_schedule(root,controller,{'models':[{'name':'m0','choices':[]}]},records,phase,'llm/models',inventory,private)
98+
b['reference_execution'][field]=original
99+
64100

65101
if __name__=='__main__':unittest.main()

‎tools/cpu_parallel_references.py‎

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,13 @@ def main():
138138
parser.add_argument('--cache',type=int,default=0);parser.add_argument('--requests',type=int,default=32)
139139
parser.add_argument('--cached',type=int,default=0);parser.add_argument('--index',default='datrie')
140140
args=parser.parse_args()
141-
if args.mode=='run':run(args.root,args.phase)
141+
if args.mode=='run':
142+
try:run(args.root,args.phase)
143+
except BaseException as error:
144+
path=args.root/'cpu-parallel-references'/args.phase/'report.json'
145+
if path.exists():
146+
report=load(path);report.update(status='failed',error=repr(error));path.write_text(json.dumps(report,indent=2)+'\n')
147+
raise
142148
else:worker(args)
143149

144150

‎tools/publish_memory_application.py‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -420,6 +420,9 @@ def main():
420420
archive.take(source, 'diagnostics/' + source.name)
421421
for name in ('quality-dispatch.json', 'cpu-quality-dispatch.json', 'final-serving-dispatch.json'):
422422
archive.take(args.root / name, 'diagnostics/' + name)
423+
for name in ('cpu-fork-preflight.json','llm-cpu-fork-preflight.json'):
424+
path=args.root/name
425+
if path.exists():archive.take(path,'diagnostics/'+name)
423426
if (args.root / 'gpu-recovery.json').exists():
424427
archive.take(args.root / 'gpu-recovery.json', 'diagnostics/gpu-recovery.json')
425428
for source in sorted((args.root / 'recovery-20261110').glob('*.json')):

0 commit comments

Comments
 (0)