Skip to content

Commit a09afd3

Browse files
committed
Resume the frozen final study and automatically prepare complete evidence
1 parent 4ebb150 commit a09afd3

2 files changed

Lines changed: 110 additions & 0 deletions

File tree

‎tests/test_gpu_job_retry.py‎

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

1111

1212
class GpuJobRetryTests(unittest.TestCase):
13+
def test_resume_requires_the_original_quality_gate_bytes(self):
14+
try:
15+
from tools.resume_memory_application import validate_ready
16+
except ImportError:
17+
self.skipTest('Optional NumPy for recovery orchestration')
18+
import hashlib
19+
with tempfile.TemporaryDirectory() as temp:
20+
root=Path(temp);gate=root/'gate.json';gate.write_text('{"status":"complete"}')
21+
family=root/'llm-frontier';family.mkdir();choice=family/'selection.json';choice.write_text('{}')
22+
checksum=lambda p:hashlib.sha256(p.read_bytes()).hexdigest()
23+
(root/'quality-ready.json').write_text(json.dumps({'status':'quality-complete','gates':{'gate.json':checksum(gate)},
24+
'frozen_selections':{'llm-frontier':checksum(choice)}}))
25+
validate_ready(root);choice.write_text('{"changed":true}')
26+
with self.assertRaisesRegex(ValueError,'Frozen choice'):validate_ready(root)
27+
choice.write_text('{}');gate.write_text('{"status":"failed"}')
28+
with self.assertRaisesRegex(ValueError,'quality gate changed'):validate_ready(root)
1329
def test_competing_job_is_discarded_hashed_and_repeated_with_same_command(self):
1430
with tempfile.TemporaryDirectory() as temp:
1531
output=Path(temp)/'job.json'; log=Path(temp)/'job.log'; command=['worker','--requests','32']

‎tools/resume_memory_application.py‎

Lines changed: 94 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,94 @@
1+
"""Resume failed final serving with unchanged quality gates and retained evidence."""
2+
import argparse
3+
import fcntl
4+
import json
5+
import os
6+
from pathlib import Path
7+
import subprocess
8+
import sys
9+
import time
10+
11+
from .finish_memory_application import load, sha
12+
from .tree_node_quality import write
13+
14+
15+
def validate_ready(root):
16+
ready = load(root / 'quality-ready.json')
17+
if ready['status'] != 'quality-complete': raise ValueError('Complete original quality gate required')
18+
for name, checksum in ready['gates'].items():
19+
path = root / name
20+
if sha(path) != checksum or load(path)['status'] != 'complete':
21+
raise ValueError('Original quality gate changed: ' + name)
22+
for family, checksum in ready['frozen_selections'].items():
23+
if sha(root / family / 'selection.json') != checksum: raise ValueError('Frozen choice changed')
24+
return ready
25+
26+
27+
def run(args):
28+
root = args.root; validate_ready(root)
29+
old = load(root / 'final-serving-dispatch.json')
30+
if old['status'] != 'failed': raise ValueError('Only a failed, inactive final dispatch may be resumed')
31+
backup = root / 'recovery-20261110'; backup.mkdir(exist_ok=True); stamp = str(time.time_ns())
32+
snapshots = {}
33+
for name in ('final-serving-dispatch.json', 'retime-llm-gpu/report.json', 'gpu-spare-lanes/report.json',
34+
'publication-prepared/report.json'):
35+
path = root / name
36+
if path.exists():
37+
target = backup / (name.replace('/', '-') + '-' + stamp + '.json')
38+
target.write_bytes(path.read_bytes()); snapshots[name] = {'path': str(target), 'sha256': sha(target)}
39+
commit = subprocess.check_output(['git', 'rev-parse', 'HEAD'], text=True).strip()
40+
write(root / 'gpu-recovery.json', {'source_commit': commit, 'source_sha256': sha(Path(__file__)),
41+
'registered': time.time(), 'snapshots': snapshots,
42+
'reason': 'Externally competing GPU programs interrupted measurements; passed outputs are retained and interrupted attempts are archived'})
43+
report = {'status': 'resuming-final-serving', 'started': time.time(), 'source_commit': commit,
44+
'complete': [v for v in old['complete'] if v['name'] not in ('retime-llm-gpu', 'retime-llm-cpu', 'retime-long')],
45+
'failures': [], 'previous_failures': old.get('previous_failures', []) + old.get('failures', [])}
46+
write(root / 'final-serving-dispatch.json', report)
47+
env = dict(os.environ, CUDA_VISIBLE_DEVICES='', OMP_NUM_THREADS='1', OPENBLAS_NUM_THREADS='1',
48+
MKL_NUM_THREADS='1', CUBLAS_WORKSPACE_CONFIG=':4096:8', HF_HUB_OFFLINE='1', TRANSFORMERS_OFFLINE='1', TOKENIZERS_PARALLELISM='false')
49+
def phase(name, cmd):
50+
log = root / (name + '-resume-' + stamp + '.log')
51+
with log.open('w') as stream: result = subprocess.run(cmd, env=env, stdout=stream, stderr=subprocess.STDOUT)
52+
item = {'name': name, 'command': cmd, 'returncode': result.returncode, 'log': str(log), 'finished': time.time()}
53+
if result.returncode:
54+
report['failures'].append(item); raise RuntimeError('Recovery phase failed: ' + str(log))
55+
report['complete'].append(item); write(root / 'final-serving-dispatch.json', report)
56+
common = ['--controls', str(root / 'independent-controls'), '--ready', str(root / 'quality-ready.json'),
57+
'--upstream', str(args.upstream), '--requests', '32']
58+
spare = None
59+
try:
60+
with (root / ('spare-gpu-resume-' + stamp + '.log')).open('w') as stream:
61+
spare = subprocess.Popen([sys.executable, '-m', 'tools.gpu_spare_lanes', '--plan', str(root / 'gpu-spare-lane-plan.json')],
62+
env=env, stdin=subprocess.DEVNULL, stdout=stream, stderr=subprocess.STDOUT)
63+
phase('retime-llm-gpu', [sys.executable, '-m', 'tools.finalize_memory_application', 'retime-llm-gpu',
64+
'--frontier', str(root / 'llm-frontier'), '--output', str(root / 'retime-llm-gpu'),
65+
'--gpu-addendum', str(Path.cwd() / 'benchmarks/memory_application_serving_addendum_v1.json'),
66+
'--gpu-affinity', str(root / 'gpu-worker-affinity.json'), *common])
67+
if spare.wait() != 0 or load(root / 'gpu-spare-lanes/report.json')['status'] != 'complete':
68+
raise RuntimeError('Complete spare cohort required before CPU timing')
69+
(root / 'all-compute-finished').write_text('All registered GPU measurements completed.\n')
70+
for name, family in (('retime-llm-cpu', 'llm-frontier'), ('retime-long', 'long-frontier')):
71+
report['status'] = 'running-' + name; write(root / 'final-serving-dispatch.json', report)
72+
phase(name, [sys.executable, '-m', 'tools.finalize_memory_application', name, '--frontier', str(root / family),
73+
'--output', str(root / name), *common])
74+
report.update(status='complete', finished=time.time()); write(root / 'final-serving-dispatch.json', report)
75+
except BaseException as error:
76+
report.update(status='failed', error=repr(error), finished=time.time()); write(root / 'final-serving-dispatch.json', report)
77+
raise
78+
output = root / 'publication-prepared'
79+
if output.exists(): output.rename(root / ('publication-prepared-before-resume-' + stamp))
80+
with (root / ('publication-resume-' + stamp + '.log')).open('w') as stream:
81+
subprocess.run([sys.executable, '-m', 'tools.finish_memory_application', '--root', str(root),
82+
'--sources', str(args.sources), '--output', str(output), '--path-map', str(root / 'publication-path-map.json'),
83+
'--release-url', args.release_url], cwd=args.publication_source, env=env, stdout=stream, stderr=subprocess.STDOUT, check=True)
84+
85+
86+
def main():
87+
parser = argparse.ArgumentParser(description=__doc__)
88+
for name in ('root', 'sources', 'upstream', 'publication-source'): parser.add_argument('--' + name, type=Path, required=True)
89+
parser.add_argument('--release-url', required=True); args = parser.parse_args()
90+
with (args.root / 'final-serving-recovery.lock').open('w') as lock:
91+
fcntl.flock(lock, fcntl.LOCK_EX | fcntl.LOCK_NB); run(args)
92+
93+
94+
if __name__ == '__main__': main()

0 commit comments

Comments
 (0)