okami.mom/strata

git clone https://git.nkp.pet/okami.mom/strata

Niko1221Merge f-q4-metal (ed1f58d27): the Mac (Metal) engine follows the compiled geometry (q4_lite/q4_mid/q4_big kernel parity 40/40, gate 2 like CUDA), plus the PLE row-buffer fix in src/program/generate.cpp (sized by the compiled hidden size, not 2560; it overran 24 KB at hidden 4096 and crashed Metal serve); default build unchanged (CUDA SASS 3573/3573 and 160/160 host objects, HIP gfx1201/gfx1151 string offsets only, SYCL 129/129 objects and 22/22 checksums, Metal per-token functions identical, UD-Q4_K_XL 10/10 tokens, CUDA IQ3_S 26/26 tokens) (Qwen4 prep)7f46672a4

main
3.6 KiB79 linesraw
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
4    python metal/tools/geo_pins.py [REV_BEFORE [REV_AFTER]]         (default: the commit before Q4-METAL's geometry work, and HEAD)
5    python 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):
28    r = subprocess.run(["git", "show", "%s:%s" % (rev, path)], capture_output=True, text=True, encoding="utf-8", errors="replace")
29    return r.stdout if r.returncode == 0 else ""
30
31
32def code_lines(text):
33    out = []
34    for i, ln in enumerate(text.splitlines(), 1):
35        ln = re.sub(r'"(?:\\.|[^"\\])*"', '""', ln)
36        ln = re.sub(r"//.*$", "", ln)
37        out.append((i, ln))
38    return out
39
40
41def count(rev, path, nums):
42    pat = re.compile(r"(?<![\w.])(%s)(?![\w.])" % "|".join(str(n) for n in nums))
43    n = 0
44    hits = []
45    for i, ln in code_lines(show(rev, path)):
46        m = pat.findall(ln)
47        if m:
48            n += len(m)
49            hits.append((i, ln.strip()))
50    return n, hits
51
52
53def main():
54    args = sys.argv[1:]
55    if args and args[0] == "--list":
56        rev = args[1]
57        for f in FILES:
58            for tier, nums in (("specific", SPECIFIC), ("ambiguous", AMBIG)):
59                n, hits = count(rev, f, nums)
60                for i, ln in hits:
61                    print("%s:%d [%s] %s" % (f, i, tier, ln[:170]))
62        return
63    before = args[0] if args else "f6a3b0ce8"
64    after = args[1] if len(args) > 1 else "HEAD"
65    print("%-44s %17s %17s" % ("file", "specific %s->%s" % (before[:7], after[:7]), "ambiguous"))
66    ts = [0, 0, 0, 0]
67    for f in FILES:
68        a1, _ = count(before, f, SPECIFIC)
69        b1, _ = count(after, f, SPECIFIC)
70        a2, _ = count(before, f, AMBIG)
71        b2, _ = count(after, f, AMBIG)
72        if a1 or b1 or a2 or b2:
73            print("%-44s %7d -> %-6d %7d -> %-6d" % (f, a1, b1, a2, b2))
74        ts = [ts[0] + a1, ts[1] + b1, ts[2] + a2, ts[3] + b2]
75    print("%-44s %7d -> %-6d %7d -> %-6d" % ("total", ts[0], ts[1], ts[2], ts[3]))
76
77
78if __name__ == "__main__":
79    main()