File size: 9,206 Bytes
fdcbc89 39e4cd4 fdcbc89 39e4cd4 fdcbc89 f317f35 fdcbc89 419a44e fdcbc89 419a44e fdcbc89 419a44e 82872ac 7746322 6c9c630 a3552f9 fdcbc89 6c9c630 fdcbc89 2624061 fdcbc89 f317f35 fdcbc89 f317f35 6c9c630 fdcbc89 2624061 fdcbc89 419a44e 82872ac 419a44e 7746322 39e4cd4 7746322 3a06c2e 6c9c630 7746322 a3552f9 fdcbc89 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 | """User-facing commands for one arm, the full research pipeline, and a live local explorer."""
import argparse
import json
from functools import partial
from http.server import SimpleHTTPRequestHandler, ThreadingHTTPServer
from pathlib import Path
from .records import HORIZONS, METHODS, storage_root
def dashboard(project, port):
"""Serve the same Pages application locally with a live view of atomically recorded events."""
from .live_hub import live_snapshot
storage=storage_root(project)
class Handler(SimpleHTTPRequestHandler):
def do_GET(self):
if self.path.split("?",1)[0] == "/live.json":
study = live_snapshot(project,storage)
data = json.dumps(study,ensure_ascii=False,allow_nan=False).encode()
self.send_response(200)
self.send_header("Content-Type","application/json; charset=utf-8")
self.send_header("Cache-Control","no-store")
self.send_header("Content-Length",str(len(data)))
self.end_headers()
self.wfile.write(data)
else:
super().do_GET()
server = ThreadingHTTPServer(("127.0.0.1",port),partial(Handler,directory=str(project/"docs")))
print(f"Live study dashboard http://127.0.0.1:{port}/",flush=True)
server.serve_forever()
def parser():
p = argparse.ArgumentParser(description=__doc__)
p.add_argument("--project",type=Path,default=Path.cwd())
parsers = p.add_subparsers(dest="action",required=True)
for action in ("prepare","train","study","hybrid","flatness","freeze","evaluate","seed-sensitivity","report","dashboard","publish","audit-hub","audit-restart","audit-science","progress","verify"):
sub = parsers.add_parser(action)
if action in {"prepare","study","flatness"}:
sub.add_argument("--stage",choices=(*HORIZONS,"both"),default="both")
if action in {"train","freeze"}:
sub.add_argument("--stage",choices=HORIZONS,required=True)
if action in {"train","study","hybrid","evaluate","flatness"}:
sub.add_argument("--device",default="cuda")
if action=="flatness":
sub.add_argument("--phase",choices=("pilot","confirm","hybrid","all"),default="all")
sub.add_argument("--run-id",help="Measure a single completed run in the selected phase")
if action=="study":
sub.add_argument("--with-hybrid",action="store_true",help="Include the registered TinyStories hybrid follow-up on the same GPU")
if action=="hybrid":
sub.add_argument("--cohort",choices=("example","replications","all"),default="all",
help="Run the first seed, the remaining seeds and cyclic replay, or the standalone full follow-up")
if action in {"study","hybrid"}:
sub.add_argument("--with-flatness",action="store_true",help="Measure comparable training-window geometry at each completed checkpoint")
if action=="verify":
sub.add_argument("--pretrained",action="store_true",help="Also compare a full joint derivative on the prepared adapter training corpus")
sub.add_argument("--reference",action="store_true",help="Compute the FP64 pretrained reference using the original CUDA signs")
sub.add_argument("--scoring-batches",action="store_true",help="Benchmark Pythia inference grouping on training windows")
sub.add_argument("--device",default="cuda",help="Device for the optional full pretrained cross-check")
if action=="train":
sub.add_argument("--method",choices=(*METHODS,"unigram","initial"),required=True)
sub.add_argument("--phase",choices=("pilot","control","confirm","smoke"),default="pilot")
sub.add_argument("--seed",type=int,default=0)
sub.add_argument("--ratio",type=float,default=0.03)
sub.add_argument("--microbatch",type=int)
if action in {"train","study","hybrid","evaluate","flatness","seed-sensitivity"}:
sub.add_argument("--publish",action="store_true",help="Publish results to the configured project accounts")
if action in {"evaluate","audit-restart"}:
sub.add_argument("run_id")
if action=="dashboard":
sub.add_argument("--port",type=int,default=8765)
if action=="audit-science":
sub.add_argument("--restore",action="store_true",help="Restore the required public archive files into study storage")
sub.add_argument("--archive-revision",help="Use a particular thirdloss-study Hub revision when restoring")
sub.add_argument("--report",action="store_true",help="Rebuild the study publications after verification")
if action=="publish":
sub.add_argument("--message",default="Update third-derivative study records")
sub.add_argument("--checkpoints",action="store_true",help="Republish the fitted checkpoints and restart states in the collection")
return p
def main(argv=None):
args = parser().parse_args(argv)
project = args.project.resolve()
storage = storage_root(project)
if args.action=="audit-science":
from .scientific_audit import scientific_audit
if args.restore:
from .hub_archive import restore_audit_inputs
restore_audit_inputs(project,storage,args.archive_revision)
print(scientific_audit(project,storage),flush=True)
if args.report:
from .reporting import build_report
build_report(project)
return
if args.action=="seed-sensitivity":
from .seed_sensitivity import finish_seed_sensitivity
finish_seed_sensitivity(project,args.publish)
return
if args.action=="audit-hub":
from .hub_archive import audit_archive
print(json.dumps(audit_archive(project),indent=2))
return
if args.action=="audit-restart":
from .verification import audit_restart
print(json.dumps(audit_restart(project,args.run_id),indent=2))
return
if args.action=="verify":
from .verification import verify
verify(project)
if args.pretrained:
from .probe_check import verify_pretrained
from .records import setup_device
verify_pretrained(project,setup_device(args.device))
if args.reference:
from .precision import reference_gradient
from .records import setup_device
reference_gradient(project,setup_device(args.device))
if args.scoring_batches:
from .probe_check import benchmark_scoring
from .records import setup_device
benchmark_scoring(project,setup_device(args.device))
return
if args.action=="dashboard":
return dashboard(project,args.port)
if args.action in {"report","progress","publish"}:
from .progress import progress
if args.action == "progress":
print(progress(project))
return
from .reporting import build_report
build_report(project)
if args.action == "publish":
from .release import publish_snapshot, publish_weights
if args.checkpoints:
from .records import read_json
for path in sorted((project/"results").glob("*/summary.json")):
publish_weights(project,storage,read_json(path))
print(publish_snapshot(project,args.message))
return
from .study import evaluate_one,freeze,milestone,prepare_stage,run_study
if args.action=="freeze":
print(freeze(project,storage,args.stage)["freeze_id"])
return
stages = list(HORIZONS) if getattr(args,"stage",None)=="both" else [getattr(args,"stage",None)]
if args.action=="prepare":
for stage in stages:
prepare_stage(project,storage,stage)
return
from .records import setup_device
device = setup_device(args.device)
if args.action=="flatness":
from .checkpoint_flatness import flatness_study
flatness_study(project,storage,stages,args.phase,device,args.publish,run_id=args.run_id)
return
if args.action in {"study","hybrid"}:
from contextlib import nullcontext
from .live_hub import publish_live
with publish_live(project,storage) if args.publish else nullcontext():
if args.action=="hybrid":
from .hybrid import run_hybrids
prepare_stage(project,storage,"stories")
run_hybrids(project,storage,device,args.publish,with_flatness=args.with_flatness,cohort=args.cohort)
else:
run_study(project,storage,stages,device,args.publish,with_hybrid=args.with_hybrid,with_flatness=args.with_flatness)
return
if args.action=="evaluate":
summary = evaluate_one(project,storage,args.run_id,device)
else:
from .train import run_one
summary = run_one(project,storage,args.stage,args.method,args.phase,args.seed,args.ratio,device,args.microbatch)
milestone(project,storage,summary,args.publish)
if __name__=="__main__":
main()
|