Skip to content

Commit 35da9bc

Browse files
committed
Consume completed reference outputs before enforcing fresh numerical workers
1 parent c262655 commit 35da9bc

2 files changed

Lines changed: 31 additions & 2 deletions

File tree

‎tests/test_parallel_cpu_serving.py‎

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22
import hashlib
33
import importlib.util
44
import json
5+
import os
6+
import socket
57
from pathlib import Path
68
import tempfile
79
import threading
@@ -14,6 +16,25 @@
1416

1517

1618
class CpuParallelTests(unittest.TestCase):
19+
def test_cli_consumes_reference_that_finished_before_process_start(self):
20+
from tools.parallel_cpu_serving import main
21+
with tempfile.TemporaryDirectory() as temp:
22+
root=Path(temp);job=root/'job.json';job.write_text('{}')
23+
plan=root/'cpu-serving-parallel-plan.json';plan.write_text('{}')
24+
registered=root/'cpu-parallel-reference-plan.json'
25+
registered.write_text(json.dumps({'measurement_host':socket.gethostname()}))
26+
output=root/'reference.json'
27+
output.write_text(json.dumps({'reference_execution':{'plan_sha256':digest(registered)}}))
28+
argv=['worker','--phase','retime-long','--job',str(job),'--output',str(output),
29+
'--plan',str(plan),'--lane','0','--cohort','serial-reference']
30+
before=output.read_bytes()
31+
with patch('sys.argv',['worker',*argv]),patch.dict(os.environ,{'CUDA_VISIBLE_DEVICES':''}), \
32+
patch('tools.parallel_cpu_serving.worker') as numerical:main();numerical.assert_not_called()
33+
self.assertEqual(output.read_bytes(),before)
34+
argv[-1]='parallel-shared-host'
35+
with patch('sys.argv',['worker',*argv]),patch.dict(os.environ,{'CUDA_VISIBLE_DEVICES':''}), \
36+
self.assertRaises(SystemExit):main()
37+
1738
def test_smt_siblings_are_not_independent_physical_lanes(self):
1839
plan = {'schema_version': 1, 'workers': 2, 'lanes': {
1940
'0': {'cpus': [0], 'physical_cores': [[0, 0]]},

‎tools/parallel_cpu_serving.py‎

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,8 @@ def run_queue(args, requests, ready, plan_path):
110110
or prior['frozen_selection_sha256'] != selection_hash):
111111
raise ValueError('Existing CPU schedule differs')
112112
report = {'status': 'running', 'phase': args.phase, 'environment': environment(),
113-
'requests': requests, 'complete': [], 'failures': prior.get('failures', []),
113+
'requests': requests, 'complete': [], 'failures': [],
114+
'previous_failures': prior.get('previous_failures', []) + prior.get('failures', []),
114115
'workers': plan['workers'], 'workers_per_physical_core': 1,
115116
'cpu_parallel_plan_sha256': plan_hash, 'cpu_parallel_plan': str(plan_path),
116117
'model_lanes': plan['model_lanes'][args.phase], 'lanes': plan['lanes'],
@@ -242,7 +243,14 @@ def main():
242243
parser.add_argument('--index', choices=('datrie', 'hash'), default='datrie')
243244
parser.add_argument('--requests', type=int, default=32)
244245
args = parser.parse_args()
245-
if args.output.exists() or os.environ.get('CUDA_VISIBLE_DEVICES') != '':
246+
if os.environ.get('CUDA_VISIBLE_DEVICES') != '':
247+
parser.error('Empty CUDA_VISIBLE_DEVICES required')
248+
# A reference coordinator can finish between the dispatcher's existence
249+
# check and this CLI starting. Consume its verified output before enforcing
250+
# the fresh-output requirement that applies to numerical workers.
251+
from .cpu_parallel_references import wait_for_reference
252+
if wait_for_reference(args):return
253+
if args.output.exists():
246254
parser.error('Fresh output and empty CUDA_VISIBLE_DEVICES required')
247255
from .cpu_fork_serving import submit
248256
if submit(args):return

0 commit comments

Comments
 (0)