|
10 | 10 |
|
11 | 11 | from tools.cpu_parallel_references import run,wait_for_reference |
12 | 12 | from tools.parallel_cpu_serving import digest |
| 13 | +from tools.verify_memory_application import cpu_projection,verify_cpu_schedule |
13 | 14 |
|
14 | 15 |
|
15 | 16 | class ParallelReferenceTests(unittest.TestCase): |
@@ -61,5 +62,40 @@ def test_dispatcher_wait_returns_only_an_actual_registered_reference(self): |
61 | 62 | with self.assertRaises(ValueError):wait_for_reference(args) |
62 | 63 | args.cohort='parallel-shared-host';self.assertFalse(wait_for_reference(args)) |
63 | 64 |
|
| 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 | + |
64 | 100 |
|
65 | 101 | if __name__=='__main__':unittest.main() |
0 commit comments