okami.mom/strata
git clone https://git.nkp.pet/okami.mom/strata
fcb0c2d0e
main
1"""Per-anchor drafter results at EVERY generated position (stride 1), resumable: the exact path and the selector's confidences.""" 2import json ,sys ,time 3from pathlib import Path 4import numpy as np 5import torch 6sys .path .insert (0 ,r"C:\dflash2-work" ) 7import dflash2_ref as R 8 9W = Path (r"C:\dflash2-work" ) 10names = sys .argv [1 ].split ("," ) 11b = int (sys .argv [2 ]) 12threads = int (sys .argv [3 ]) 13budget = float (sys .argv [4 ])# seconds this call may spend before it saves and stops 14t_start = time .time () 15embed = R .load_dequant (str (W / "embd_iq4xs.bin" ),248320 ,2560 ,R .gguf .GGMLQuantizationType .IQ4_XS ) 16head = R .load_dequant (str (W / "head_q6k.bin" ),248320 ,2560 ,R .gguf .GGMLQuantizationType .Q6_K ) 17d = R .Drafter (str (W / "drafter.safetensors" ),str (W / "drafter_config.json" ),embed ,head ,threads = threads ) 18d .enable_fast_head () 19out_path = W / ("anchors1_b%d.json" % b ) 20res = json .load (open (out_path ))if out_path .exists ()else {} 21for name in names : 22if res .get (name + "#done" ): 23continue 24seqj = json .load (open (W / "p" / ("%s.seq.json" % name ))) 25seq = seqj ["prompt" ]+ seqj ["out" ] 26layers ,pos ,tok ,taps = R .read_taps (str (W / "taps" / ("%s.bin" % name ))) 27keep = pos < len (seq ) 28pos ,tok ,taps = pos [keep ],tok [keep ],taps [keep ] 29n = int (pos .max ())+ 1 30feats = np .zeros ((n ,taps .shape [1 ]),np .float32 ) 31for i in range (len (pos )): 32feats [pos [i ]]= taps [i ] 33feats [0 ]= feats [1 ] 34d .set_context (torch .from_numpy (feats )) 35rows = res .get (name , []) 36s0 = rows [- 1 ]["s" ]+ 1 if rows else len (seqj ["prompt" ]) 37t1 = time .time () 38finished = True 39with torch .no_grad (): 40for s in range (s0 ,len (seq )- b ): 41path ,top1 = d .draft (s ,seq [s ],b ) 42truth = seq [s + 1 :s + b ] 43rows .append ({"s" :s ,"ok" : [int (path [i ]== truth [i ])for i in range (b - 1 )],"p" : [round (x ,4 )for x in d .last_probs ]}) 44if time .time ()- t_start > budget : 45finished = False 46break 47res [name ]= rows 48if finished : 49res [name + "#done" ]= True 50json .dump (res ,open (out_path ,"w" )) 51name ,b ,len (rows ),"anchors so far, %.0f s" % (time .time ()- t1 ),"done" if finished else "PAUSED" ,flush = True ) 52if not finished : 53break