okami.mom/strata
git clone https://git.nkp.pet/okami.mom/strata
b0fc432ed
main
1"""vision_proto.py - pictures over the engine protocol (GENI / BGENI), no server: the ids come from llama.cpp's own tokenizer 2output (vc1/*.llama.log of vcmp.py), the rows from strata-vision (<picture>.sve). 3 4python q36_vision_proto.py --exe E --args "--model M --max-context 8192 --vision --batch 4" --vc DIR --pics DIR 5 6Checks: 1. a solo GENI answers like llama.cpp's greedy (the first 24 tokens); 2. two pictures and a text prompt decoding 7together (BGENI / BGEN) give each the tokens of its solo run; 3. the conversation cache: the same request again and a 8longer one (the first, its answer and more text) reuse the held state, a different picture does not; a text request after 9a picture request is not disturbed (the rotary offset is back at 0). 10 11Start the engine without --mtp for the cache check: the held tokens of a request that ran with drafts include the drafts accepted past 12its last emitted token, so a prompt that does not repeat them reads from the start (correct, but the check wants the reuse).""" 13from pathlib import Path 14import argparse ,os ,shlex ,sys 15sys .path .insert (0 ,__file__ .rsplit ("/" ,1 )[0 ]if "/" in __file__ else "." ) 16from q36_harness import Eng ,load_prompts 17 18PAD = 248056 19 20 21def case (vc ,pics ,name ,q ): 22log = open (os .path .join (vc ,"%s.q%d.llama.log" % (name ,q ))).read () 23ids ,gen = [], [] 24for l in log .splitlines (): 25if l .startswith ("text:" ): 26ids += [int (x )for x in l .split (":" ,1 )[1 ].split ()] 27elif l .startswith ("image:" ): 28ids += [PAD ]* int (l .split ()[1 ]) 29elif l .startswith ("gen:" ): 30gen = [int (x )for x in l .split (":" ,1 )[1 ].split ()] 31return ids ,gen ,os .path .join (pics ,name + ".sve" ) 32 33 34ap = argparse .ArgumentParser () 35ap .add_argument ("--exe" ,required = True ) 36ap .add_argument ("--args" ,default = "" ) 37ap .add_argument ("--vc" ,required = True ) 38ap .add_argument ("--pics" ,required = True ) 39ap .add_argument ("--n" ,type = int ,default = 24 ) 40ap .add_argument ("--log" ,default = None ) 41a = ap .parse_args () 42eng = Eng (a .exe ,shlex .split (a .args ),log = a .log ) 43"ready" ,eng .ready ,eng .info ,flush = True ) 44ok = True 45S0 ,G0 ,E0 = case (a .vc ,a .pics ,"shapes.png" ,0 ) 46S1 ,G1 ,E1 = case (a .vc ,a .pics ,"shapes.png" ,1 ) 47C0 ,GC0 ,EC0 = case (a .vc ,a .pics ,"code4217.png" ,0 ) 48C1 ,GC1 ,EC1 = case (a .vc ,a .pics ,"code4217.png" ,1 ) 49 50# 1. solo vs llama.cpp's greedy 51solo = {} 52for tag , (ids ,gen ,emb )in {"shapes.q0" : (S0 ,G0 ,E0 ),"shapes.q1" : (S1 ,G1 ,E1 ),"code.q0" : (C0 ,GC0 ,EC0 ), 53"code.q1" : (C1 ,GC1 ,EC1 )}.items (): 54toks ,done ,ttft ,wall = eng .solo (ids ,a .n ,emb = emb ) 55solo [tag ]= toks 56k = next ((i for i in range (min (len (toks ),len (gen )))if toks [i ]!= gen [i ]),None ) 57"solo %-10s %d tokens, vs llama.cpp greedy: %s | %s" % (tag ,len (toks ),"same %d tokens" % len (toks )if k is None else "first difference at %d" % k ,done [:60 ]),flush = True ) 58 59# 2. batch: two pictures + a text prompt 60text = load_prompts (str (Path (__file__ ).resolve ().parent / "parity_prompts.ids" ))[0 ] 61t_toks ,_ ,_ ,_ = eng .solo (text ,a .n ) 62reqs = [{"ids" :S1 ,"n" :a .n ,"slot" :0 ,"emb" :E1 }, {"ids" :C1 ,"n" :a .n ,"slot" :1 ,"emb" :EC1 }, 63 {"ids" :text ,"n" :a .n ,"slot" :2 }] 64r = eng .batch (reqs ) 65eq = [r ["tokens" ][0 ]== solo ["shapes.q1" ],r ["tokens" ][1 ]== solo ["code.q1" ],r ["tokens" ][2 ]== t_toks ] 66"batch (2 pictures + 1 text): identical to solo %s" % eq ,flush = True ) 67ok &= all (eq ) 68# slot reuse: the same again into other slots 69r2 = eng .batch ([{"ids" :C1 ,"n" :a .n ,"slot" :3 ,"emb" :EC1 }, {"ids" :S1 ,"n" :a .n ,"slot" :0 ,"emb" :E1 }]) 70eq2 = [r2 ["tokens" ][0 ]== solo ["code.q1" ],r2 ["tokens" ][1 ]== solo ["shapes.q1" ]] 71"batch again (slot 3 new, slot 0 held): identical %s" % eq2 ,flush = True ) 72ok &= all (eq2 ) 73 74# 3. the conversation cache (solo path) 75def reused (done ): 76return int (done .split ()[8 ]) 77 78toks1 ,done1 ,_ ,_ = eng .solo (S0 ,16 ,emb = E0 ) 79toks1b ,done1b ,_ ,_ = eng .solo (S0 ,16 ,emb = E0 ) 80"same request again (a state that has moved past the prompt cannot step back: no reuse): reused %d of %d, tokens %s" % (reused (done1b ),len (S0 ),"same" if toks1b == toks1 else "DIFFERENT" ),flush = True ) 81ok &= toks1b == toks1 82longer = S0 + toks1 + text [:12 ] 83toks2 ,done2 ,_ ,_ = eng .solo (longer ,16 ,emb = E0 ) 84"longer request (picture + answer + more): reused %d of %d" % (reused (done2 ),len (longer )),flush = True ) 85ok &= reused (done2 )>= len (S0 ) 86toks3 ,done3 ,_ ,_ = eng .solo (C0 ,16 ,emb = EC0 )# a different picture 87"a different picture: reused %d" % reused (done3 ),"tokens vs its solo: %s" % ("same" if toks3 == solo ["code.q0" ][:16 ]else "DIFFERENT" ),flush = True ) 88ok &= toks3 == solo ["code.q0" ][:16 ] 89t2 ,done4 ,_ ,_ = eng .solo (text ,a .n ) 90"a text request after pictures: tokens vs the text solo: %s" % ("identical" if t2 == t_toks else "DIFFERENT" ),flush = True ) 91ok &= t2 == t_toks 92eng .close () 93"GATE" ,"PASS" if ok else "FAIL" ) 94sys .exit (0 if ok else 1 )