Files
digital-drosophila/models/male-cns-lif/conditioning-acceleration-v1/finalize_report.py
T

110 lines
8.7 KiB
Python
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
"""Aggregate measured replay-only results; never estimate unmeasured full-training acceleration."""
import argparse
from datetime import datetime, timezone
import hashlib
import json
from pathlib import Path
import statistics
import subprocess
BASE = Path('/home/qishizhe/phase4ar-v100-acceleration-20261001')
SOURCE = Path(__file__).resolve().parent
def read(path): return json.loads(Path(path).read_text())
def sha(path):
h = hashlib.sha256()
with Path(path).open('rb') as f:
for c in iter(lambda: f.read(8 << 20), b''): h.update(c)
return h.hexdigest()
def save(path, data):
with Path(path).open('x') as f: json.dump(data, f, indent=2, sort_keys=True, allow_nan=False)
p = argparse.ArgumentParser()
p.add_argument('--run', action='append', required=True)
a = p.parse_args()
assert len(a.run) == len(set(a.run)) == 3
integrity = read(BASE / 'integrity-after-gpu.json')
assert integrity['status'] == 'PASS'
devices = []
pins = set()
for name in a.run:
path = BASE / name
assert path.parent == BASE and path.is_dir()
s = read(path / 'summary.json')
assert s['status'] == 'PASS-ELIGIBILITY-UPDATE-REPLAY-EQUIVALENCE'
assert s['fixtures'] == 30 and s['rejected_invalid_cases'] == 6 and s['all_fixture_repeats_bitwise_exact']
process = read(BASE / 'jobs' / (name + '.exit.json'))
assert process['observed_exit'] and process['exit_code'] == 0 and not process['timed_out']
pins.add(s['candidate_commit'])
real = [read(f) for f in sorted(path.glob('fixtures--*.json'))]
assert len(real) == 14
medians = [r['summaries']['replay_wall_including_preparation_and_comparison_seconds']['median'] for r in real]
kernels = [statistics.median(t['kernel_seconds'] for t in r['resident_timing']['resident_kernel_samples']) for r in real]
cpu = [r['reference_timing']['warm_update_seconds'] for r in real]
cpu_cold = [r['reference_timing']['cold_update_seconds'] for r in real]
devices.append(dict(run=name, device=s['device'], real_fixture_count=len(real),
median_real_fixture_cpu_original_update_api_seconds=statistics.median(cpu),
median_real_fixture_cpu_cold_update_api_seconds=statistics.median(cpu_cold),
median_real_fixture_candidate_replay_seconds=statistics.median(medians),
median_real_fixture_resident_kernel_seconds=statistics.median(kernels),
mean_real_fixture_candidate_replay_seconds=statistics.mean(medians),
original_update_api_to_candidate_replay_ratio=statistics.median([x/y for x,y in zip(cpu,medians)]),
ratio_warning='Different API overhead boundaries: original U checks/AST every call; candidate authenticates sources/mapping once. NOT pure CPU/GPU hardware ratio.',
cpu_baseline_sample_warning='One cold plus ONE warm original API sample per fixture; GPU 3 warmups +20 repeats per fixture.',
first_use_compile_seconds=real[0]['first_call_timing']['cold_compile_seconds'],
context_initialization_seconds=s['device']['initialization_seconds'],
observed_cuda_pool_reserved_peak_bytes=s['observed_cuda_pool_reserved_peak_bytes'],
positive_fixtures=30, invalid_inputs_rejected=6, bitwise_exact=True,
benchmark_wall_seconds=s['wall_seconds'], result_sha256=sha(path / 'summary.json')))
assert len(pins) == 1, 'GPU runs used different candidate commits'
summary = dict(status='PASS-ELIGIBILITY-UPDATE-REPLAY-EQUIVALENCE',
created_utc=datetime.now(timezone.utc).isoformat(), benchmark_candidate_commit=next(iter(pins)),
report_code_commit=subprocess.check_output(['git','-C',str(SOURCE),'rev-parse','HEAD'],text=True).strip(),
devices=devices, frozen_integrity=integrity,
scientific_experiment_status='STOPPED, unchanged:1033/30000 CPU-verified training epochs and138/3920 probes',
original_experiment_resumed=False, full_training_acceleration_measured=False, weights_installed=False,
full_brain_gpu_event_equivalence_tested=False, learned_candidate_created=False,
limitations=['Replay module only, not a production training backend',
'The sampled committed prefix covers7arms but only available physiological/PAM15/reinforce_A subset',
'Repeated kernel calculations reset state and replay identical saved inputs, not additional learning trials',
'Original CPU verification remains independent and required',
'No simultaneous two-V100 training/scheduling benchmark; devices tested separately',
'Original9.07-day estimate is not replaced by this component benchmark'],
fixes_preserved=['Initial candidate pip22 lacked--report; upgraded pip only in new venv',
'First GPU compile rejected conflictingFTZ options; no kernel executed; explicit nvcc compilation retains original precision'],
next_work='Separately validate persistent training/update/verification workers and complete chain timing before authorizing a new scientific execution version')
save(BASE / 'final-summary.json', summary)
lines = ['# V100 conditioning acceleration — engineering replay result', '',
'Status: **PASS-ELIGIBILITY-UPDATE-REPLAY-EQUIVALENCE**. This is not a learning result or a production-training promotion.', '',
f'Benchmark code commit: `{next(iter(pins))}`.', '',
'| Device | Real-fixture replay median (prep + transfers + comparison) | Resident CUDA kernel median |',
'|---|---:|---:|']
for d in devices:
lines.append(f"| {d['device']['runtime_name']} ({d['run']}) | {d['median_real_fixture_candidate_replay_seconds']*1000:.3f} ms | {d['median_real_fixture_resident_kernel_seconds']*1000:.3f} ms |")
lines += ['', 'Each GPU passed14sealed real fixtures +16fixed synthetic cases, with sampled trace, final trace, allUS snapshots and delta byte-identical to the original independent CPU oracle. Six invalid inputs were rejected on each GPU.', '',
'CPU warm reference includes the original API\'s repeated provenance checks and AST parsing; it is only one warm sample perfixture. GPU authenticates the source and complete anatomical mapping once. Therefore ratios in JSON describe API implementation replay, not pure hardware acceleration.', '',
'The CUDA kernels preserve every timestep, float32 separate round-to-nearest operations, exact US timing, noUS zeros, compartment/frozen/D0 identity and the depression floor. No gain/learning-rate/tau/threshold/connectome/sign changes. No dense time×neuron matrix.', '',
'A new candidate-only CuPy environment and explicit CUDA12.6 nvcc compilation are used. Original science and ComfyUI environments are unchanged. All three ComfyUI queues were checked before each fixture; no services were stopped.', '',
f"Integrity: {integrity['files_checked']} saved files, {integrity['bytes_checked']} bytes, {integrity['sources_checked']} registered source files checked; no mismatch. This is the saved Phase4AR inventory, not a new Phase1–4AQ numerical regression.", '',
'Phase4AR remains stopped at1033/30000CPU-verified epochs and138/3920probes. No weights were installed and no training was resumed.', '',
'Next: a separately validated persistent-worker pipeline and end-to-end benchmark. This local optimization does not justify dividing the9-day estimate by the kernel speedup. Independent-seed V100 parallelism is not yet measured.', '',
'Preserved failures: candidate packaging incompatibility (--report unsupported bypip22); first CuPy compile FTZ flag conflict (before any kernel ran). Both were corrected only in the independent branch.', '',
'Compiler references: [CuPy precompiled RawModule](https://docs.cupy.dev/en/v13.6.0/reference/generated/cupy.RawModule.html), [CUDA12.6 compiler options](https://docs.nvidia.com/cuda/archive/12.6.3/cuda-compiler-driver-nvcc/index.html).', '']
with (BASE / 'RESULTS.md').open('x') as f: f.write('\n'.join(lines))
# Exclude installed environment, reproducible compiler caches and final manifests themselves;
# environment packages/wheel hashes are retained in pip-install-report + freeze.
excluded = {'.venv'}
files = {}
for path in sorted(BASE.rglob('*')):
rel = path.relative_to(BASE)
if path.is_file() and not path.is_symlink() and not any(part in excluded for part in rel.parts):
files[rel.as_posix()] = dict(sha256=sha(path), bytes=path.stat().st_size)
save(BASE / 'artifact-manifest.json', dict(schema='independent-acceleration-artifacts-v1',
code_commit=summary['report_code_commit'], source_files={p.name:sha(p) for p in SOURCE.iterdir() if p.is_file()},
files=files, excluded=['.venv (package versions and downloaded wheel hashes are in installation receipts)'],
no_frozen_source_modified=True, no_training_run=True))
with (BASE / 'SHA256SUMS').open('x') as f:
for rel, info in files.items(): f.write(info['sha256'] + ' ' + rel + '\n')
f.write(sha(BASE/'artifact-manifest.json') + ' artifact-manifest.json\n')
print(json.dumps(summary), flush=True)