File size: 6,911 Bytes
fdcbc89 39e4cd4 fdcbc89 39e4cd4 fdcbc89 7746322 fdcbc89 7746322 fdcbc89 7746322 fdcbc89 7746322 fdcbc89 7746322 39e4cd4 7746322 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 | """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","freeze","evaluate","report","dashboard","publish","audit-hub","progress","verify"):
sub = parsers.add_parser(action)
if action in {"prepare","study"}:
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"}:
sub.add_argument("--device",default="cuda")
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=="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"}:
sub.add_argument("--publish",action="store_true",help="Publish results to the configured project accounts")
if action=="evaluate":
sub.add_argument("run_id")
if action=="dashboard":
sub.add_argument("--port",type=int,default=8765)
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-hub":
from .hub_archive import audit_archive
print(json.dumps(audit_archive(project),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)
progress(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 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
run_hybrids(project,storage,device,args.publish)
else:
run_study(project,storage,stages,device,args.publish,with_hybrid=args.with_hybrid)
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()
|