routing-lead: static tier hit rates for N slots
This commit is contained in:
@@ -18,7 +18,11 @@ Predictors (all causal):
|
||||
lastlayer experts of layer L-1 in the current window -> experts that co-occurred with them at layer L in the first half (a co-occurrence table); known one layer ahead
|
||||
Metrics per predictor: recall = |pred & actual| / |actual| (actual = union of the window's rows at layer L), mean candidates per layer, lead ms.
|
||||
|
||||
usage: routing-lead.py ROUTING.bin [--window-ms 11.0] [--selftest]
|
||||
Second part (--profile expert-profile.bin): the share of expert uses that a STATIC tier of the top-N experts of the shipped ranking would serve from VRAM, for
|
||||
N = today's slot counts and for the counts a compressed tier (level-2 KAR, 0.7506 of the IQ3_S bytes: 1.332x the slots) would hold. The adaptive tier and the lent
|
||||
slots move this number; the static figure bounds the gain of "more slots" from below/above only roughly, and it is the same arithmetic for both sides.
|
||||
|
||||
usage: routing-lead.py ROUTING.bin [--window-ms 11.0] [--profile expert-profile.bin] [--selftest]
|
||||
"""
|
||||
import struct, sys, collections, random
|
||||
|
||||
@@ -122,6 +126,32 @@ def analyse(wins, window_ms):
|
||||
print("lead time of a start-of-window prediction at layer L = L x %.3f ms (window %.1f ms / 48); the layer's own router result gives ~0 lead (the same layer runs next)." % (t_layer, window_ms))
|
||||
|
||||
|
||||
def tier_hit_rates(wins, profile_path):
|
||||
d = open(profile_path, "rb").read()
|
||||
magic, ver, layers, experts, n1, n2 = struct.unpack_from("<4sIIIII", d, 0)
|
||||
assert magic == b"STRP" and n1 == layers * experts, (magic, n1)
|
||||
flat = struct.unpack_from("<%dH" % (2 * n1), d, 24)
|
||||
rank = {}
|
||||
for i in range(n1):
|
||||
rank[(flat[2 * i], flat[2 * i + 1])] = i
|
||||
uses, uniq = [], []
|
||||
for w in wins:
|
||||
seen = set()
|
||||
for l, rows in w.items():
|
||||
for ids in rows:
|
||||
for e in ids:
|
||||
r = rank.get((l, e))
|
||||
uses.append(r if r is not None else n1)
|
||||
for e in set(e for ids in rows for e in ids):
|
||||
seen.add((l, e))
|
||||
uniq.extend(rank.get(k, n1) for k in seen)
|
||||
print("static tier (top-N of the shipped ranking) over %d expert uses, %d window-unique (layer, expert) pairs:" % (len(uses), len(uniq)))
|
||||
for n, label in ((8000, "replay shape"), (11280, "today, seed-off 245k slots"), (12192, "today, auto slots (product)"), (15028, "compressed, same VRAM as 11,280"),
|
||||
(16243, "compressed, same VRAM as 12,192"), (20000, "")):
|
||||
print(" N=%6d %-34s uses in tier %5.1f %% window-unique pairs in tier %5.1f %%" % (
|
||||
n, label, 100 * sum(1 for r in uses if r < n) / len(uses), 100 * sum(1 for r in uniq if r < n) / len(uniq)))
|
||||
|
||||
|
||||
def selftest():
|
||||
import tempfile, os
|
||||
rnd = random.Random(1)
|
||||
@@ -146,4 +176,7 @@ if __name__ == "__main__":
|
||||
ms = 11.0
|
||||
if "--window-ms" in sys.argv:
|
||||
ms = float(sys.argv[sys.argv.index("--window-ms") + 1])
|
||||
analyse(windows(sys.argv[1]), ms)
|
||||
w = windows(sys.argv[1])
|
||||
analyse(w, ms)
|
||||
if "--profile" in sys.argv:
|
||||
tier_hit_rates(w, sys.argv[sys.argv.index("--profile") + 1])
|
||||
|
||||
Reference in New Issue
Block a user