This repository has been archived on 2026-11-25. You can view files and clone it. You cannot open issues or pull requests or push a commit.
Files
MeltMind-Archive/artifacts/gpu-concurrency-assessment-2026-11-18/withdrawn-throughput-draft/h2_concurrency_probe_common.py
T

99 lines
3.9 KiB
Python

"""Independent H2 throughput experiment: learning-only, no scientific scoring."""
import json
import math
from pathlib import Path
from phase2_h1_worker_v2 import checked
from phase2_home_freeze_io import verify
BASE = Path('/home/frank14f/optane/MeltMind')
ROOT = BASE / 'artifacts/h2-concurrency-probe-2026-11-18'
GPU1 = 'GPU-f1c9fd5a-e917-56e0-21fb-24035ba44a36'
def read(p):
return json.loads(Path(p).read_text())
def config(root):
root = Path(root)
if root.resolve() != ROOT:
raise PermissionError('Sole labelled probe root')
verify(root, 'implementation')
c = read(root / 'contract.json')
expected = dict(approval='1795006592.506519', gpu_uuid=GPU1,
concurrency=[1, 2, 3], epochs=5, warmup_epochs=1,
seed=0, gpu_seconds_cap=10800, no_retry=True,
training_fold=0, test_reads=False, gpu3_limit=1)
if any(c.get(k) != v for k, v in expected.items()):
raise PermissionError('Frozen experiment scope changed')
for p, h in {**c['code_sha256'], **c['source_sha256']}.items():
checked(p, h)
view = read(root / 'learning-view.json')
f = view['folds'][0]
if (len(view['folds']) != 1 or f['fold'] != 0 or f['validation'] or f['test']
or set(view['parts']) != set(f['learning'])
or set(view['geometry']) != set(f['learning'])):
raise PermissionError('Learning-only view required')
stats = read(c['standardization'])
if stats['parts'] != f['learning'] or stats['nodes'] != f['learning_nodes']:
raise ValueError('Normalization identity')
return c, view, stats
def charge(now, outside_seconds, jobs):
"""Sum each slot's wall seconds, plus coordinator time without slots and60s."""
values = [outside_seconds, now]
amounts = []
for j in jobs:
end = j.get('end', now)
values += [j['start'], end]
if end < j['start']:
raise ValueError('Nonmonotonic job clock')
amounts.append(end - j['start'])
if any(not math.isfinite(x) or x < 0 for x in values):
raise ValueError('Invalid accounting input')
return 60 + outside_seconds + sum(amounts)
def throughput(rows):
if not rows or any(r['completed_epochs'] != 5 for r in rows):
raise ValueError('Five complete epochs per copy required')
starts = [r['measure_start'] for r in rows]
ends = [r['measure_end'] for r in rows]
if any(not math.isfinite(x) for x in starts + ends) or any(b <= a for a, b in zip(starts, ends)):
raise ValueError('Invalid measurement interval')
return dict(total_epochs_per_hour=4 * len(rows) * 3600 / (max(ends) - min(starts)),
per_copy_epochs_per_hour=[4 * 3600 / (b - a) for a, b in zip(starts, ends)])
def choose(rows):
"""A larger N requires every preceding step's >=1.3 gain and margin pass."""
selected = None
for i, row in enumerate(rows, 1):
if row['concurrency'] != i:
raise ValueError('Ordered contiguous measurements required')
rate = row['total_epochs_per_hour']
if not math.isfinite(rate) or rate <= 0:
raise ValueError('Invalid throughput')
if not row['margin_pass'] or (i > 1 and rate < 1.3 * rows[i-2]['total_epochs_per_hour']):
break
selected = i
return selected
def resource_reasons(sample, c):
reasons = []
if sample['device_used'] > .8 * sample['device_total']:
reasons.append('DEVICE_20_PERCENT_MARGIN')
if sample['host_available'] < .2 * sample['host_total']:
reasons.append('HOST_RAM_20_PERCENT_MARGIN')
if sample['host_cpu_percent'] > 80:
reasons.append('HOST_CPU_20_PERCENT_MARGIN')
if sample['temperature'] >= c['temperature_limit_c']:
reasons.append('DEVICE_TEMPERATURE_LIMIT')
if any(v > c['worker_rss_bytes'] for v in sample['rss']):
reasons.append('WORKER_RSS_LIMIT')
if sample['foreign_gpu_pids']:
reasons.append('FOREIGN_GPU_PROCESS')
return reasons