NOEON / scripts /make_gpu_notebook.py
openhands
openhands
Connect Hugging Face NOEON repo to Colab via Git LFS
fc1c423
Raw History Blame Contribute Delete
4.89 kB
#!/usr/bin/env python3
"""Generate notebooks/NOEON_TRAIN_GPU.ipynb — the GPU-host (Colab) run book.
Kept as a generator so the notebook is reproducible and diff-stable, exactly like
the NOEON_LAB notebooks. The notebook is honest: the first cell refuses to
proceed without a GPU, and it never prints a training result it did not produce.
"""
from __future__ import annotations
import json
from pathlib import Path
OUT = Path(__file__).resolve().parent.parent / "notebooks" / "NOEON_TRAIN_GPU.ipynb"
KERNEL = {"display_name": "Python 3", "language": "python", "name": "python3"}
def md(t):
return {"cell_type": "markdown", "metadata": {}, "source": t.splitlines(True)}
def code(t):
return {"cell_type": "code", "execution_count": None, "metadata": {},
"outputs": [], "source": t.strip("\n").splitlines(True)}
CELLS = [
md("""# NOEON — unified training on a GPU host (Colab)
This run book trains **NOEON's own parameters** — the bridge adapters, the
FusionCore and the GenerationHead — against the three **frozen** sources. The
sources are never modified.
It is honest by construction:
* the first cell **refuses to proceed without a GPU** (NOEON has no GPU in its
development environment; this notebook is where the real training runs);
* it never prints a training result it did not produce;
* the frozen sources are loaded in eval mode with every parameter frozen.
If a cell prints "NO GPU DETECTED", nothing was trained — run this notebook on a
GPU runtime (Runtime â–¸ Change runtime type â–¸ GPU)."""),
code("""# 1. Verify the GPU. This is the gate: no GPU, no training.
!nvidia-smi | head -12 || echo "NO GPU DETECTED"
import torch
print("cuda available:", torch.cuda.is_available())
if not torch.cuda.is_available():
raise SystemExit("NO GPU DETECTED — switch the Colab runtime to a GPU and re-run.")
print("device:", torch.cuda.get_device_name(0))"""),
code("""# 2. Dependencies
!pip -q install "torch>=2.2" transformers safetensors huggingface_hub pyyaml accelerate bitsandbytes"""),
code("""# 3. Get NOEON from Hugging Face. The repo is PUBLIC — no token needed.
import os, pathlib, subprocess
ROOT = pathlib.Path("/content/NOEON")
if not ROOT.exists():
# Skip the LFS smudge so the ~43.5 GB of weights are NOT pulled here:
# this fetches code, configs and LFS *pointers* only (a few MB).
env = dict(os.environ, GIT_LFS_SKIP_SMUDGE="1")
subprocess.run(
["git", "clone", "https://huggingface.co/Frankenstein-Labs/NOEON", str(ROOT)],
check=True, env=env,
)
subprocess.run(["git", "-C", str(ROOT), "lfs", "install", "--local"], check=False)
print("repo:", ROOT.exists())
os.chdir(ROOT)
# Fetch only the weights this run needs, e.g.:
# !git lfs pull --include="weights/noeon-init/*"
# !git lfs pull --include="weights/upstream/vision/*"
print("cwd:", os.getcwd())
!git lfs ls-files | wc -l"""),
code("""# 4. Resource + dependency check before any big download
!python scripts/attach_sources.py | tail -25"""),
code("""# 5. Run the real training.
# Sources are frozen; only NOEON's 698M parameters move.
# --amp and --grad-accum keep it inside a single T4/L4.
!python scripts/train_unified.py --steps 200 --batch 1 --grad-accum 4 --amp --resume"""),
code("""# 6. Inspect the checkpoint that was written (if any)
import json, pathlib
steps = sorted(pathlib.Path("weights/checkpoints").glob("step-*")) if pathlib.Path("weights/checkpoints").exists() else []
print("checkpoints:", [p.name for p in steps])
run = pathlib.Path("reports/training_run.json")
if run.exists():
print(json.dumps(json.loads(run.read_text()), indent=2)[:800])"""),
code("""# 7. (Optional) push the checkpoint back to the Hub — never paste tokens inline.
# import subprocess
# subprocess.run(["python", "scripts/publish_to_hf.py", "--repo",
# "Frankenstein-Labs/NOEON"], check=True)"""),
md("""## After a successful run
* `UnifiedBrain.status(state_dir="weights/checkpoints")` reports
`trained@step-N` instead of `initialized-untrained`.
* The evaluation suite's *quality* checks become meaningful (there is now a
trained model to answer); today only mechanism checks are reported.
* Re-run `scripts/run_alignment_experiment.py` with last-layer hidden states
(now that the trunks can run) to move from the embedding-row probe to full
hidden-state alignment."""),
]
def main() -> int:
doc = {"cells": CELLS,
"metadata": {"kernelspec": KERNEL,
"language_info": {"name": "python", "version": "3.11"}},
"nbformat": 4, "nbformat_minor": 5}
for i, c in enumerate(doc["cells"]):
c["id"] = f"cell-{i}"
OUT.write_text(json.dumps(doc, indent=1, ensure_ascii=False) + "\n")
print("wrote", OUT, "cells:", len(CELLS))
return 0
if __name__ == "__main__":
raise SystemExit(main())