okami.mom/strata
git clone https://git.nkp.pet/okami.mom/strata
7f46672a4
main
1#!/usr/bin/env python3 2"""geo_pins.py - the Metal sources' literals that are Flash-Next's shape, counted per file at two git revisions. 3 4python metal/tools/geo_pins.py [REV_BEFORE [REV_AFTER]] (default: the commit before Q4-METAL's geometry work, and HEAD) 5python metal/tools/geo_pins.py --list REV every remaining hit of REV, one line each 6 7A "pin" is a code token (comments and string literals are dropped before matching) from the list below. Specific numbers are the values only 8Flash-Next's shape has; ambiguous ones (48 = layers or GDN heads, 24 = query heads, 36, 33, 65) are counted separately because the same digits 9also mean thread counts and tile sizes elsewhere. The tool cannot tell a hit that is a shape from one that is not: the classes of the 10remaining hits are in phaseA-tests/qwen4/RESULTS-Q4-METAL.md, section Inventory. 11""" 12import re 13import subprocess 14import sys 15 16SPECIFIC = [2560 ,10240 ,6144 ,12288 ,2051 ,16480 ,1280 ,640 ,320 ,248320 ] 17AMBIG = [48 ,36 ,24 ,33 ,65 ,258 ] 18FILES = ["metal/src/engine/window.cpp" ,"metal/src/engine/prompt_chain.inc" ,"metal/src/engine/stream.cpp" ,"metal/src/engine/dflash2.inc" , 19"metal/src/engine/iq_host.cpp" ,"metal/src/engine/mmvq_host.cpp" , 20"metal/kernels/qsa.metal" ,"metal/kernels/qsa2.metal" ,"metal/kernels/qsab.metal" ,"metal/kernels/qsa_prompt.metal" , 21"metal/kernels/gdn.metal" ,"metal/kernels/gdn_prompt.metal" ,"metal/kernels/gr.metal" ,"metal/kernels/gr2.metal" , 22"metal/kernels/hcf.metal" ,"metal/kernels/glue.metal" ,"metal/kernels/router.metal" ,"metal/kernels/moe.metal" , 23"metal/kernels/moe_mm.metal" ,"metal/kernels/prompt.metal" ,"metal/kernels/sample.metal" ,"metal/kernels/gemv.metal" , 24"metal/src/engine/msl/ple.metal" ,"metal/src/engine/msl/mtp.metal" ,"metal/src/engine/msl/mtp_chain.metal" ,"metal/src/engine/msl/dflash2.metal" ] 25 26 27def show (rev ,path ): 28r = subprocess .run (["git" ,"show" ,"%s:%s" % (rev ,path )],capture_output = True ,text = True ,encoding = "utf-8" ,errors = "replace" ) 29return r .stdout if r .returncode == 0 else "" 30 31 32def code_lines (text ): 33out = [] 34for i ,ln in enumerate (text .splitlines (),1 ): 35ln = re .sub (r'"(?:\\.|[^"\\])*"' ,'""' ,ln ) 36ln = re .sub (r"//.*$" ,"" ,ln ) 37out .append ((i ,ln )) 38return out 39 40 41def count (rev ,path ,nums ): 42pat = re .compile (r"(?<![\w.])(%s)(?![\w.])" % "|" .join (str (n )for n in nums )) 43n = 0 44hits = [] 45for i ,ln in code_lines (show (rev ,path )): 46m = pat .findall (ln ) 47if m : 48n += len (m ) 49hits .append ((i ,ln .strip ())) 50return n ,hits 51 52 53def main (): 54args = sys .argv [1 :] 55if args and args [0 ]== "--list" : 56rev = args [1 ] 57for f in FILES : 58for tier ,nums in (("specific" ,SPECIFIC ), ("ambiguous" ,AMBIG )): 59n ,hits = count (rev ,f ,nums ) 60for i ,ln in hits : 61"%s:%d [%s] %s" % (f ,i ,tier ,ln [:170 ])) 62return 63before = args [0 ]if args else "f6a3b0ce8" 64after = args [1 ]if len (args )> 1 else "HEAD" 65"%-44s %17s %17s" % ("file" ,"specific %s->%s" % (before [:7 ],after [:7 ]),"ambiguous" )) 66ts = [0 ,0 ,0 ,0 ] 67for f in FILES : 68a1 ,_ = count (before ,f ,SPECIFIC ) 69b1 ,_ = count (after ,f ,SPECIFIC ) 70a2 ,_ = count (before ,f ,AMBIG ) 71b2 ,_ = count (after ,f ,AMBIG ) 72if a1 or b1 or a2 or b2 : 73"%-44s %7d -> %-6d %7d -> %-6d" % (f ,a1 ,b1 ,a2 ,b2 )) 74ts = [ts [0 ]+ a1 ,ts [1 ]+ b1 ,ts [2 ]+ a2 ,ts [3 ]+ b2 ] 75"%-44s %7d -> %-6d %7d -> %-6d" % ("total" ,ts [0 ],ts [1 ],ts [2 ],ts [3 ])) 76 77 78if __name__ == "__main__" : 79main ()