Skip to content

Commit 422f4e7

Browse files
committed
Batch CPU receipt checkpoints while preserving every sample audit
1 parent 35da9bc commit 422f4e7

2 files changed

Lines changed: 24 additions & 3 deletions

File tree

‎tests/test_parallel_cpu_serving.py‎

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,16 @@ def arg(name): return command[command.index('--' + name) + 1]
147147
self.assertEqual(seen[24:], ['serial-reference'] * 16)
148148
self.assertEqual(json.loads((args.output / 'report.json').read_text())['status'], 'complete')
149149
execution.reset_mock()
150-
run_queue(args, requests, {'status': 'quality-complete'}, plan_path)
150+
from tools.tree_node_quality import write as persist
151+
with patch('tools.parallel_cpu_serving.time.monotonic', return_value=1000.), \
152+
patch('tools.tree_node_quality.write', wraps=persist) as checkpoints:
153+
run_queue(args, requests, {'status': 'quality-complete'}, plan_path)
154+
# Initial state, reference boundary and final state remain
155+
# durable while retained receipts avoid per-item rewrites.
156+
self.assertEqual(checkpoints.call_count, 3)
157+
saved=json.loads((args.output / 'report.json').read_text())
158+
self.assertEqual(len(saved['complete']), 24)
159+
self.assertEqual(len(saved['serial_references']), 16)
151160
execution.assert_not_called()
152161
output = args.output / '00000.json'; value = json.loads(output.read_text()); value['decoded_row_sha256'] = 'corrupt'; write(output, value)
153162
with self.assertRaisesRegex(RuntimeError, 'grid incomplete'):

‎tools/parallel_cpu_serving.py‎

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,18 @@ def run_queue(args, requests, ready, plan_path):
124124
report.update(measurement_host=socket.gethostname(),parallel_with_gpu_shards=plan.get('parallel_with_gpu_shards',False))
125125
retained = {e['output']: e['sha256'] for e in prior.get('complete', []) + prior.get('serial_references', [])}
126126
lock = threading.Lock(); failures = []
127+
last_checkpoint = time.monotonic()
128+
def checkpoint():
129+
# Samples are separately persisted and checked before a receipt is
130+
# added. Rewriting the complete growing receipt list on every retained
131+
# sample makes recovery quadratic in shared-filesystem traffic. Keep
132+
# progress at one-second intervals; failures and phase boundaries
133+
# always save immediately.
134+
nonlocal last_checkpoint
135+
now = time.monotonic()
136+
if now - last_checkpoint >= 1.:
137+
write(controller, report)
138+
last_checkpoint = now
127139
def measure(index, request, cohort):
128140
lane = report['model_lanes'][request['model']]; cpus = plan['lanes'][lane]['cpus']
129141
folder = args.output if cohort == 'parallel-shared-host' else args.output / 'serial-reference'
@@ -160,7 +172,7 @@ def lane_work(lane):
160172
try:
161173
result = measure(index, request, 'parallel-shared-host')
162174
with lock:
163-
report['complete'].append(result); write(controller, report)
175+
report['complete'].append(result); checkpoint()
164176
if len(report['complete']) % 20 == 0:
165177
print({'phase': args.phase, 'complete': len(report['complete']), 'expected': len(requests)}, flush=True)
166178
except Exception as error:
@@ -187,7 +199,7 @@ def lane_work(lane):
187199
original = originals[json.dumps(request, sort_keys=True)]
188200
result['parallel_output_sha256'] = original['sha256']
189201
result['parallel_to_serial_p50_ratios'] = compare_outputs(load(original['output']), load(result['output']))
190-
report['serial_references'].append(result); write(controller, report)
202+
report['serial_references'].append(result); checkpoint()
191203
if index % 20 == 0:
192204
print({'phase': args.phase, 'serial_references': index + 1, 'expected': len(refs)}, flush=True)
193205
if digest(selection) != selection_hash or digest(plan_path) != plan_hash:

0 commit comments

Comments
 (0)