Leszek Bukowski commited on
Commit ·
4f6ab5b
1
Parent(s): 9db71b3
Make Drive optional and require confirmation before evaluation shutdown
Browse files139 unmodified lines1401411421431441451461 unmodified line1481491501511521531541551561571581591601611621631641651 unmodified line167168169139 unmodified linesprint("READY — continue to Choose run and save location. Model loading has not started.", flush=True)def prepare_output(RUN_NAME, AUTO_SHUTDOWN):runtime = Nonetry:from google.colab import drive, runtime1 unmodified lineexcept ImportError:IN_COLAB = Falseif IN_COLAB:drive.mount("/content/drive")output_base = Path("/content/drive/MyDrive/TheSystem-runs")else:output_base = Path.cwd() / "thesystem-runs"OUTPUT = Path(os.environ.get("THESYSTEM_OUTPUT", output_base / RUN_NAME)).expanduser().resolve()OUTPUT.mkdir(parents=True, exist_ok=True)# Downloads and feature/model caches stay on fast local runtime disk.CACHE = Path(os.environ.get("THESYSTEM_MODEL_CACHE", "/content/thesystem-model-cache" if IN_COLAB else Path.home() / ".cache/thesystem/models"))CACHE.mkdir(parents=True, exist_ok=True)if IN_COLAB and AUTO_SHUTDOWN and not OUTPUT.is_relative_to(Path("/content/drive")):raise RuntimeError("For automatic Colab shutdown, choose an output folder on mounted Drive, or set AUTO_SHUTDOWN=False and arrange persistent storage first.")probe_file = OUTPUT / ".write-check"probe_file.write_text("Storage check\n")probe_file.unlink()1 unmodified lineprint("Local model cache:", CACHE)return OUTPUT, CACHE, IN_COLAB, runtime139 unmodified lines1401411421431441451461 unmodified line1481491501511521531541551561571581591601611621631 unmodified line165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235139 unmodified linesprint("READY — continue to Choose run and save location. Model loading has not started.", flush=True)def prepare_output(RUN_NAME, USE_DRIVE=False):runtime = Nonetry:from google.colab import drive, runtime1 unmodified lineexcept ImportError:IN_COLAB = Falseif IN_COLAB and USE_DRIVE:drive.mount("/content/drive")output_base = Path("/content/drive/MyDrive/TheSystem-runs")else:output_base = (Path("/content") if IN_COLAB else Path.cwd()) / "thesystem-runs"OUTPUT = Path(os.environ.get("THESYSTEM_OUTPUT", output_base / RUN_NAME)).expanduser().resolve()OUTPUT.mkdir(parents=True, exist_ok=True)# Downloads and feature/model caches stay on fast local runtime disk.CACHE = Path(os.environ.get("THESYSTEM_MODEL_CACHE", "/content/thesystem-model-cache" if IN_COLAB else Path.home() / ".cache/thesystem/models"))CACHE.mkdir(parents=True, exist_ok=True)probe_file = OUTPUT / ".write-check"probe_file.write_text("Storage check\n")probe_file.unlink()1 unmodified lineprint("Local model cache:", CACHE)return OUTPUT, CACHE, IN_COLAB, runtimedef results_html(output):import htmlimport jsonreport = json.loads((Path(output) / "SUMMARY.json").read_text())if not report.get("complete"):raise RuntimeError("Evaluation is incomplete; download partial results and logs.")names = {"vitaminc-dev": "VitaminC", "paws": "PAWS", "squad2": "SQuAD2 answerability", "aegis2": "Aegis2", "pubmedqa": "PubMedQA"}source = html.escape(report["published"]["source_url"], quote=True)if not report["published"]["source_url"].startswith("https://"):raise ValueError("Expected an HTTPS published-results link")rows = []for key, name in names.items():values = report["decisions"][key]published = report["published"]["subsets"][key]cells = [f'<th>{name}<small>{values["qwen"]["rows"]} examples</small></th>']cells += [f'<td>{values[k]["accuracy"] * 100:.2f}%</td>' for k in ("lora_automatic", "probe256_automatic")]cells += [f'<td><a href="{source}" target="_blank" rel="noopener noreferrer">{published[k]["accuracy_percent"]:.1f}% ↗</a></td>' for k in ("nimble", "jev")]rows.append('<tr>' + ''.join(cells) + '</tr>')label = 'QUICK CHECK — small subsets; not full benchmark scores' if report.get('smoke') else 'Benchmark accuracy — this evaluation run'if not report.get('inference_performed', True):label += ' · reconstructed evidence, no new inference'return '''<style>.ts-results{font:14px system-ui;color:#e8ebf0;background:#101318;border:1px solid #303640;border-radius:12px;padding:20px;overflow:auto}.ts-results table{width:100%;border-collapse:collapse}.ts-results th,.ts-results td{padding:16px;text-align:right;border-bottom:1px solid #303640}.ts-results th:first-child{text-align:left}.ts-results thead{background:#1b2028}.ts-results a{color:#9ac9ff}.ts-results small{display:block;color:#a7afbb;font-weight:400;margin-top:5px}</style>''' + f'''<div class="ts-results"><h3>{label}</h3><table><thead><tr><th>Benchmark</th><th><FAST> + LoRA</th><th><FAST> + Probe-256</th><th><a href="https://huggingface.co/bespokelabs/Bespoke-Nimble-9B">Bespoke-Nimble-9B</a></th><th><a href="https://docs.typesafe.ai/models#current-models">Jev 1.13.0</a></th></tr></thead><tbody>{''.join(rows)}</tbody></table><p>Automatic accuracy includes routing errors. Nimble/Jev are published reference scores; prompt wrappers differ. Full Qwen, routing and generation results are in REPORT.html.</p></div>'''def show_results(output):from IPython.display import HTML, displaydisplay(HTML(results_html(output)))def finish_controls(output):import tempfileimport ipywidgets as widgetsfrom IPython.display import display, FileLinkoutput = Path(output).resolve()download = widgets.Button(description="Download results ZIP", icon="download")saved = widgets.Checkbox(value=False, description="I confirmed that my results are saved", indent=False)shutdown = widgets.Button(description="Shut down runtime", disabled=True, button_style="warning")messages = widgets.Output()def download_results(_):saved.value = Falsewith messages:archive = shutil.make_archive(str(Path(tempfile.mkdtemp(prefix="thesystem-results-")) / output.name), "zip", root_dir=output)try:from google.colab import filesexcept ImportError:display(FileLink(archive))else:files.download(archive)print("Download requested. Verify the ZIP is saved before confirming shutdown.")def confirmation(change):shutdown.disabled = not change["new"]def stop(_):if not saved.value:returnwith messages:try:from google.colab import runtimeexcept ImportError:print("This local kernel stays open. Close it when ready.")else:print("You confirmed that results are saved. Releasing Colab.", flush=True)runtime.unassign()download.on_click(download_results)saved.observe(confirmation, names="value")shutdown.on_click(stop)display(widgets.VBox([download, saved, shutdown, messages]))return download, saved, shutdown
prepare_evaluation.py+71-5