okami.mom/strata
git clone https://git.nkp.pet/okami.mom/strata
2b36e8a02
main
1import json 2import numpy as np 3import sys 4sys .path .insert (0 ,r"C:\dflash2-work" ) 5exec (open (r"C:\dflash2-work\analyze2.py" ).read ().split ("print(\"check" )[0 ])# TV, PROD, A8, A4, walk, conf_T, names 6 7fixed8 = {n :walk (A8 [n ],lambda r :8 ,8 ,n )[0 ]for n in names } 8fixed4 = {n :walk (A4 [n ],lambda r :4 ,8 ,n )[0 ]for n in names } 9fixed5 = {n :walk (A8 [n ],lambda r :5 ,8 ,n )[0 ]for n in names } 10"| prompt | MTP+lookup (default) tokens/round, tok/s | MTP only tokens/round, tok/s | DFlash2 block 4 | block 8 |" ) 11"| --- | --- | --- | --- | --- |" ) 12for n in names : 13p = PROD [n ] 14"| %s | %.2f, %.1f | %.2f, %.1f | %.2f | %.2f |" % (n ,p [0 ],p [1 ],p [2 ],p [3 ],fixed4 [n ],fixed8 [n ])) 15"| mean | %.2f, %.1f | %.2f, %.1f | %.2f | %.2f |" % (np .mean ([PROD [n ][0 ]for n in names ]),np .mean ([PROD [n ][1 ]for n in names ]), 16np .mean ([PROD [n ][2 ]for n in names ]),np .mean ([PROD [n ][3 ]for n in names ]),np .mean (list (fixed4 .values ())),np .mean (list (fixed8 .values ())))) 17"gain of block-4 tokens/round over MTP default: mean of ratios %+.1f%%, per prompt %s" % ( 18100 * (np .mean ([fixed4 [n ]/ PROD [n ][0 ]for n in names ])- 1 ), {n :round (100 * (fixed4 [n ]/ PROD [n ][0 ]- 1 ))for n in names })) 19"gain of block-8 tokens/round over MTP default: mean of ratios %+.1f%%" % (100 * (np .mean ([fixed8 [n ]/ PROD [n ][0 ]for n in names ])- 1 ))) 20 21# conditional acceptance by draft position (block 8, all anchors, conditional on all earlier correct) 22cond = np .zeros (7 );cn = np .zeros (7 ) 23for n in names : 24for r in A8 [n ]: 25for i in range (7 ): 26cn [i ]+= 1 27if r ["ok" ][i ]: 28cond [i ]+= 1 29else : 30break 31"block-8 conditional acceptance by position (all prompts):" , (cond / cn ).round (3 ).tolist ()) 32cond4 = np .zeros (3 );cn4 = np .zeros (3 ) 33for n in names : 34for r in A4 [n ]: 35for i in range (3 ): 36cn4 [i ]+= 1 37if r ["ok" ][i ]: 38cond4 [i ]+= 1 39else : 40break 41"block-4 conditional acceptance by position (all prompts):" , (cond4 / cn4 ).round (3 ).tolist ()) 42 43"\nspeed estimate table (tok/s), D = drafter cost per round" ) 44pol = [("fixed 4 (block-4 drafter)" ,A4 ,lambda r :4 ), ("fixed 5 (block-8 drafter)" ,A8 ,lambda r :5 ), ("confidence>=0.5, up to 8" ,A8 ,conf_T (0.5 ,8 )), 45 ("confidence>=0.4, up to 6" ,A8 ,conf_T (0.4 ,6 ))] 46for label ,A ,f in pol : 47for D in (5.0 ,8.0 ,12.0 ): 48r_ = [] 49tps_ = [] 50for n in names : 51tau ,ms ,tps ,hist = walk (A [n ],f ,D ,n ) 52r_ .append (tps / PROD [n ][1 ]) 53tps_ .append (tps ) 54"%-28s D=%4.0f ms: mean %.1f tok/s (default %.1f): mean-of-ratios %+.1f%%, best %+.0f%% (%s), worst %+.0f%% (%s)" % ( 55label ,D ,np .mean (tps_ ),np .mean ([PROD [n ][1 ]for n in names ]),100 * (np .mean (r_ )- 1 ), 56100 * (max (r_ )- 1 ),names [int (np .argmax (r_ ))],100 * (min (r_ )- 1 ),names [int (np .argmin (r_ ))])) 57# window histogram of the confidence policy 58for n in names : 60tau ,ms ,tps ,hist = walk (A8 [n ],conf_T (0.5 ,8 ),8.0 ,n ) 61n ,"conf>=0.5 cap 8: windows" , {int (i ):int (h )for i ,h in enumerate (hist )if h },"tau %.2f" % tau )