The source-port runtime no longer builds on macOS, so the pure arithmetic and its
golden tests live in a platform-independent crate shared by the driver and runtime.
leleka_runtime::{rope_scaling,memory_plan,context_policy} stay as re-exports.
geometry.rs derives every frozen 262144-cell byte literal from the cell count.
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
63 lines
3.5 KiB
Python
63 lines
3.5 KiB
Python
#!/usr/bin/env python3
|
|
"""Offline fixture generator (Python is allowed for offline tooling, AGENTS.md): builds the Original's
|
|
`strata-plan` CLI (header-only) and the `kv_pool_bytes` harness, runs a table of configurations and writes
|
|
memory_plan_golden.json. Usage: gen_plan_golden.py <out.json> <engine/strata dir> <work dir>."""
|
|
import json, subprocess, sys, os, re
|
|
|
|
out, strata, work = sys.argv[1:4]
|
|
cxx = os.environ.get("CXX", "clang++")
|
|
here = os.path.dirname(os.path.abspath(__file__))
|
|
flags = ["-std=c++17", "-O2", "-I" + os.path.join(strata, "include"), "-I" + work]
|
|
|
|
subprocess.check_call([cxx, *flags, os.path.join(strata, "src/plan/plan_main.cpp"), "-o", os.path.join(work, "strata-plan")])
|
|
with open(os.path.join(strata, "src/core/layer.cpp")) as f:
|
|
src = f.read().split("\n")
|
|
start = next(i for i, l in enumerate(src) if l.startswith("uint64_t kv_pool_bytes("))
|
|
end = next(i for i in range(start, len(src)) if src[i].startswith("}"))
|
|
with open(os.path.join(work, "kv_pool_bytes.inc"), "w") as f:
|
|
f.write("\n".join(src[start:end + 1]) + "\n")
|
|
subprocess.check_call([cxx, *flags, os.path.join(here, "gen_kv_pool_golden.cpp"), "-o", os.path.join(work, "kvgen")])
|
|
kv_pool = json.loads(subprocess.check_output([os.path.join(work, "kvgen")]))
|
|
|
|
G = 1000 ** 3
|
|
GIB = 1024 ** 3
|
|
state_default = 36 * (128 * 48 * 128 * 4 + 3 * 10240 * 4)
|
|
cases = []
|
|
def add(*args): cases.append([str(a) for a in args])
|
|
|
|
for ctx in (20480, 65536, 131072, 262144, 393216, 524288):
|
|
for vram in (12 * G, 16 * G, 24 * G, 32 * G, 32 * GIB, 48 * G):
|
|
add("--max-context", ctx, "--vram", vram)
|
|
# charter profiles with their state (x2 slots for 2x256K), on 32 GiB with and without resident weights
|
|
for (ctx, slots) in ((524288, 1), (524288, 2), (262144, 1), (262144, 2)):
|
|
st = state_default * slots
|
|
for vram in (16 * G, 24 * G, 32 * GIB):
|
|
add("--max-context", ctx, "--vram", vram, "--state", st)
|
|
add("--max-context", ctx, "--vram", vram, "--state", st, "--dense", 4 * G, "--embd", 500_000_000, "--workspace", 300_000_000)
|
|
# small cards: the planner must refuse
|
|
for ctx in (262144, 524288):
|
|
for vram in (3 * G, 4 * G, 6 * G, 7 * G):
|
|
add("--max-context", ctx, "--vram", vram)
|
|
# resident weights larger than the card: derived pool 0 falls back to the default pool
|
|
add("--max-context", 4096, "--vram", 5 * G, "--dense", 6 * G)
|
|
add("--max-context", 20480) # CLI defaults
|
|
add("--pool", 5943000000, "--max-context", 20480)
|
|
add("--pool", 3 * G, "--max-context", 100000)
|
|
add("--pool", 20 * G, "--max-context", 100000, "--dense", 5 * G, "--embd", G) # --pool still subtracts dense/embd
|
|
add("--max-context", 1000, "--vram", 1_000_000) # does not close
|
|
add("--max-context", 1, "--vram", 13056 + 117_669_888 + 1_382_399) # no room for one slot (default state)
|
|
add("--max-context", 1, "--vram", 13056 + 117_669_888 + 1_382_400) # exactly one slot
|
|
add("--max-context", 100, "--vram", 10 * G, "--state", 0)
|
|
add("--max-context", 100, "--vram", 10 * G, "--workspace", 123456789)
|
|
add("--help")
|
|
add("--bogus")
|
|
add("--max-context")
|
|
|
|
runs = []
|
|
for args in cases:
|
|
p = subprocess.run([os.path.join(work, "strata-plan"), *args], capture_output=True, text=True)
|
|
runs.append({"args": args, "exit": p.returncode, "stdout": p.stdout, "stderr": p.stderr})
|
|
|
|
json.dump({"generator": "strata-plan built from engine/strata/src/plan/plan_main.cpp (unmodified) + extracted layer.cpp kv_pool_bytes",
|
|
"state_bytes_default": state_default, "cli": runs, "kv_pool": kv_pool}, open(out, "w"), indent=1)
|