okami.mom/strata
git clone https://git.nkp.pet/okami.mom/strata
fcb0c2d0e
main
1"""Runs the engine side of the DFlash2 experiment for one prompt on strix (foreground; one engine at a time).""" 2import json ,re ,subprocess ,sys ,time 3from pathlib import Path 4 5W = Path (r"C:\dflash2-work" ) 6RW = "C:\\strata-test\\dflash2" 7 8 9def ssh (cmd ,timeout = 1500 ): 10r = subprocess .run (["ssh" ,"-o" ,"ServerAliveInterval=30" ,"strix" ,cmd ],capture_output = True ,text = True ,timeout = timeout ) 11out = "\n" .join (l for l in (r .stdout + r .stderr ).splitlines ()if not l .startswith ("**" )) 12return out 13 14 15def scp_up (local ,remote ): 16subprocess .run (["scp" ,"-q" ,str (local ),"strix:" + remote .replace ("\\" ,"/" )],check = True ,capture_output = True ) 17 18 19def scp_down (remote ,local ): 20subprocess .run (["scp" ,"-q" ,"strix:" + remote .replace ("\\" ,"/" ),str (local )],check = True ,capture_output = True ) 21 22 23def run_mode (mode ,name ,extra = "" ): 24t = time .time () 25out = ssh ('powershell -NoProfile -ExecutionPolicy Bypass -File %s\\run_one.ps1 -Mode %s -Name %s %s' % (RW ,mode ,name ,extra )) 26"[%s %s] %.0f s" % (mode ,name ,time .time ()- t )) 27out ) 28 (W / "logs" ).mkdir (exist_ok = True ) 29 (W / "logs" / ("%s_%s.log" % (mode ,name ))).write_text (out ) 30scp_down ("%s\\out\\%s_%s.txt" % (RW ,mode ,name ),W / "logs" / ("%s_%s.txt" % (mode ,name ))) 31scp_down ("%s\\out\\%s_%s.err" % (RW ,mode ,name ),W / "logs" / ("%s_%s.err" % (mode ,name ))) 32return out 33 34 35def produced_ids (path ): 36txt = Path (path ).read_text () 37m = re .search (r"^output :(.*)$" ,txt ,re .M ) 38return [int (x )for x in m .group (1 ).split ()]if m else [] 39 40 41def main (name ,max_new ,steps ): 42prompts = json .load (open (W / "prompts.json" )) 43pids = prompts [name ]["ids" ] 44if "gen" in steps : 45run_mode ("gen" ,name ,"-MaxNew %d" % max_new ) 46out = produced_ids (W / "logs" / ("gen_%s.txt" % name )) 47name ,"prompt" ,len (pids ),"generated" ,len (out ),"tail" ,out [- 3 :]) 48seq = pids + out 49 (W / "p" / ("%s.out.ids" % name )).write_text ("," .join (map (str ,out ))) 50 (W / "p" / ("%s.first.ids" % name )).write_text ("," .join (map (str ,seq [:2 ]))) 51 (W / "p" / ("%s.rest.ids" % name )).write_text ("," .join (map (str ,seq [2 :]))) 52json .dump ({"prompt" :pids ,"out" :out },open (W / "p" / ("%s.seq.json" % name ),"w" )) 53for k in ("out" ,"first" ,"rest" ): 54scp_up (W / "p" / ("%s.%s.ids" % (name ,k )),"%s\\p\\%s.%s.ids" % (RW ,name ,k )) 55for mode in ("genf" ,"genfm" ,"tap" ): 56if mode in steps : 57run_mode (mode ,name ) 58if "tap" in steps : 59 (W / "taps" ).mkdir (exist_ok = True ) 60scp_down ("%s\\out\\tap_%s.bin" % (RW ,name ),W / "taps" / ("%s.bin" % name )) 61 62 63if __name__ == "__main__" : 64name = sys .argv [1 ] 65max_new = int (sys .argv [2 ]) 66steps = sys .argv [3 ].split ("," )if len (sys .argv )> 3 else ["gen" ,"genf" ,"genfm" ,"tap" ] 67main (name ,max_new ,steps )