"""Kaggle kernel entry point: install HADES from the attached code dataset and run pretraining. Attached datasets (private): hades-code (repo snapshot), hades-corpus-v1 (processed shards + manifest), optionally hades-checkpoints (checkpoints from the previous session). All training logic lives in the repo; this script only wires paths together. Environment overrides: HADES_CONFIG (default configs/small.yaml), HADES_TIME_LIMIT (default 11.5h), HADES_MAX_STEPS (unset = full run). """ import os import shutil import subprocess import sys from pathlib import Path INPUT = Path("/kaggle/input") WORK = Path("/kaggle/working") def find_dir_with(root: Path, marker: str) -> Path | None: """First directory under `root` containing `marker` (Kaggle mount layouts vary).""" if not root.exists(): return None for path in sorted(root.rglob(marker)): return path.parent return None def checkpoint_files(root: Path) -> list[Path]: return [p for p in root.rglob("*.pt") if p.name == "best.pt" or p.name.startswith("step_")] def main() -> None: code = find_dir_with(INPUT, "pyproject.toml") corpus = find_dir_with(INPUT, "manifest.json") if code is None or corpus is None: sys.exit(f"missing input: code={code} corpus={corpus}") repo = WORK / "hades" if not repo.exists(): shutil.copytree(code, repo) # Kaggle images ship torch/numpy/tokenizers/yaml; regex may be missing. Best effort, works offline if present. subprocess.run([sys.executable, "-m", "pip", "install", "-q", "regex", "pyyaml"], check=False) env = {**os.environ, "PYTHONPATH": str(repo)} run_dir = WORK / "runs" / "small" run_dir.mkdir(parents=True, exist_ok=True) previous = INPUT if find_dir_with(INPUT, "log.jsonl") else None if previous is not None: for f in checkpoint_files(previous): shutil.copy2(f, run_dir / f.name) shutil.copy2(find_dir_with(INPUT, "log.jsonl") / "log.jsonl", run_dir / "log.jsonl") print("resuming from", sorted(p.name for p in run_dir.glob("*.pt"))) cmd = [ sys.executable, "-m", "hades.train.pretrain", "--config", os.environ.get("HADES_CONFIG", "configs/small.yaml"), "--out", str(run_dir), "--data-dir", str(corpus), "--resume", "auto", "--time-limit", os.environ.get("HADES_TIME_LIMIT", "11.5h"), ] if os.environ.get("HADES_MAX_STEPS"): cmd += ["--max-steps", os.environ["HADES_MAX_STEPS"]] print(" ".join(cmd), flush=True) subprocess.run(cmd, check=True, cwd=repo, env=env) if __name__ == "__main__": main()