fix(m0): measure smaller game placements and read only the latest engine start
The first game PC run showed that a 2 GB expert budget still left a 16 GB card only 4.3 GB free: the weights, the 32K int8 conversation memory, the MTP drafter and buffers take about 8.7 GB on their own. The game placements now also shrink the memory format (q4_0), the context (16K, 8K) and the drafter, with half the CPU workers (no speed cost measured). The engine log is appended across starts, so each placement now reads only its own lines; when no placement leaves the reserve the result names the most free one. The gamemode runner skips the desktop stage, which is already measured. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -57,17 +57,28 @@ PORT = 8080
|
||||
# Strata's qwen36 engine cannot give VRAM back while it runs (POST /v1/vram
|
||||
# answers 400), so each placement is a restart with --expert-vram (GiB for the
|
||||
# routed experts; the rest stay in RAM) and a matching prompt chunk. A game
|
||||
# placement also reads pictures on the CPU and answers one request at a time.
|
||||
# placement also reads pictures on the CPU, answers one request at a time and
|
||||
# leaves the game half the CPU (8 engine workers cost nothing on the 9950X3D).
|
||||
# The first game PC run (2026-11-10) showed that the expert budget is not the
|
||||
# floor: at 2 GB the model still held 10.8 GB and a 16 GB card kept only
|
||||
# 4.3 GB free. The rest is 4.4 GiB of weights that never leave the card, the
|
||||
# conversation memory (1.43 GiB per 32K in int8; q4_0 is half), the MTP
|
||||
# drafter (about 1 GB) and buffers, so the smaller placements also shrink those.
|
||||
# The last row starts the normal placement again: what returning after a game costs.
|
||||
GAME_RESERVE_MIB = 8000
|
||||
_GAME = {"parallel": 1, "vision": "cpu"}
|
||||
_W8 = "pool-workers=8"
|
||||
LEVELS = [
|
||||
{"key": "normal", "parallel": 2, "vision": "gpu", "sets": []},
|
||||
{"key": "game_experts_6g", **_GAME, "sets": ["expert-vram=6", "prefill=2048"]},
|
||||
{"key": "game_experts_4g", **_GAME, "sets": ["expert-vram=4", "prefill=2048"]},
|
||||
{"key": "game_experts_2g", **_GAME, "sets": ["expert-vram=2", "prefill=2048"]},
|
||||
# A game also wants CPU cores: the same placement with half the engine's CPU workers.
|
||||
{"key": "game_experts_2g_8_workers", **_GAME, "sets": ["expert-vram=2", "prefill=2048", "pool-workers=8"]},
|
||||
{"key": "game_experts_2g", **_GAME, "sets": ["expert-vram=2", "prefill=2048", _W8]},
|
||||
{"key": "game_experts_1g_kv_q4_16k", **_GAME, "context": 16384, "kv": "q4_0",
|
||||
"sets": ["expert-vram=1", "prefill=2048", _W8]},
|
||||
{"key": "game_experts_1g_kv_q4_16k_no_mtp", **_GAME, "context": 16384, "kv": "q4_0", "mtp": "off",
|
||||
"sets": ["expert-vram=1", "prefill=2048", _W8]},
|
||||
{"key": "game_experts_0g_kv_q4_16k_no_mtp", **_GAME, "context": 16384, "kv": "q4_0", "mtp": "off",
|
||||
"sets": ["expert-vram=0", "prefill=2048", _W8]},
|
||||
{"key": "game_experts_0g_kv_q4_8k_no_mtp", **_GAME, "context": 8192, "kv": "q4_0", "mtp": "off",
|
||||
"sets": ["expert-vram=0", "prefill=2048", _W8]},
|
||||
{"key": "normal_again", "parallel": 2, "vision": "gpu", "sets": []},
|
||||
]
|
||||
INSTALL_URL = "https://github.com/Niko1221/Strata/releases/latest/download/install.ps1"
|
||||
@@ -118,13 +129,17 @@ class Strata:
|
||||
return self._flags
|
||||
|
||||
def launch_args(self, preset: dict, context: int, parallel: int, vision: str, extra_sets: list[str],
|
||||
restart: bool) -> tuple[list[str], list[str]]:
|
||||
restart: bool, kv: str | None = None, mtp: str | None = None) -> tuple[list[str], list[str]]:
|
||||
want = [("--family", preset["family"]), ("--model", preset["model"]), ("--data-dir", str(self.models)),
|
||||
("--context", str(context)), ("--vision", vision), ("--parallel", str(parallel)),
|
||||
("--access", "local"), ("--port", str(PORT)), ("--no-api-key", None), ("--yes", None),
|
||||
("--no-tui", None)]
|
||||
if preset.get("drafting"):
|
||||
want.append(("--drafting", preset["drafting"]))
|
||||
if kv:
|
||||
want.append(("--kv", kv))
|
||||
if mtp:
|
||||
want.append(("--mtp", mtp))
|
||||
if restart:
|
||||
want.append(("--restart", None))
|
||||
for s in extra_sets:
|
||||
@@ -151,8 +166,9 @@ class Strata:
|
||||
return {"exit": p.returncode, "text": scrub(p.stdout[-3000:] + p.stderr[-2000:])}
|
||||
|
||||
def launch(self, preset: dict, context: int, parallel: int, vision: str = "on",
|
||||
extra_sets: list[str] | None = None, restart: bool = False, timeout: float = 4 * 3600) -> dict:
|
||||
args, dropped = self.launch_args(preset, context, parallel, vision, extra_sets or [], restart)
|
||||
extra_sets: list[str] | None = None, restart: bool = False, timeout: float = 4 * 3600,
|
||||
kv: str | None = None, mtp: str | None = None) -> dict:
|
||||
args, dropped = self.launch_args(preset, context, parallel, vision, extra_sets or [], restart, kv, mtp)
|
||||
last = [0.0]
|
||||
|
||||
def progress(line: str) -> bool:
|
||||
@@ -163,6 +179,7 @@ class Strata:
|
||||
last[0] = time.monotonic()
|
||||
return True
|
||||
|
||||
self.mark_engine_logs()
|
||||
t0 = time.perf_counter()
|
||||
rc = run_logged(self.cmd("launch", *args), self.log, timeout=timeout, env=self.env, echo=True,
|
||||
echo_filter=progress)
|
||||
@@ -187,12 +204,23 @@ class Strata:
|
||||
dest = self.log.with_name(f"{self.log.stem}_engine_{src.name.removesuffix('.engine.log')}.log")
|
||||
dest.write_text(scrub(text), encoding="utf-8")
|
||||
|
||||
def mark_engine_logs(self) -> None:
|
||||
"""Remember how long each engine log is, so engine_lines() reads only what the next start writes."""
|
||||
self._log_marks = {p: p.stat().st_size for p in self.home.rglob("*.engine.log")}
|
||||
|
||||
def engine_lines(self, prefix: str = "strata-q36:", limit: int = 20) -> list[str]:
|
||||
"""The newest engine log's placement lines (how much went to VRAM and RAM), scrubbed."""
|
||||
"""The placement lines (how much went to VRAM and RAM) the newest engine log got since the
|
||||
last start, scrubbed. The log is appended across starts; one written again is read whole."""
|
||||
found = sorted(self.home.rglob("*.engine.log"), key=lambda p: p.stat().st_mtime)
|
||||
if not found:
|
||||
return []
|
||||
text = found[-1].read_text(encoding="utf-8", errors="replace")[-400_000:]
|
||||
src = found[-1]
|
||||
start = getattr(self, "_log_marks", {}).get(src, 0)
|
||||
if src.stat().st_size < start:
|
||||
start = 0
|
||||
with open(src, "rb") as f:
|
||||
f.seek(start)
|
||||
text = f.read()[-400_000:].decode("utf-8", errors="replace")
|
||||
return [scrub(x.strip())[:400] for x in text.splitlines() if x.lstrip().startswith(prefix)][:limit]
|
||||
|
||||
def stop(self) -> None:
|
||||
@@ -291,7 +319,8 @@ def measure_levels(r: StageResult, s: Strata, preset: dict, context: int, levels
|
||||
rows: list[dict] = []
|
||||
r["levels"] = rows
|
||||
for lv in levels:
|
||||
row: dict = {"key": lv["key"], "parallel": lv["parallel"], "vision": lv["vision"], "sets": lv["sets"]}
|
||||
row: dict = {"key": lv["key"], "parallel": lv["parallel"], "vision": lv["vision"], "sets": lv["sets"],
|
||||
"context": lv.get("context", context), "kv": lv.get("kv"), "mtp": lv.get("mtp")}
|
||||
rows.append(row)
|
||||
say(f" - 배치 {lv['key']}: 다시 시작해서 재는 중")
|
||||
t0 = time.perf_counter()
|
||||
@@ -299,8 +328,8 @@ def measure_levels(r: StageResult, s: Strata, preset: dict, context: int, levels
|
||||
idle = gpu_memory_mib()
|
||||
row["vram_idle_mib"] = idle[0] if idle else None
|
||||
with GpuSampler(interval=1) as g:
|
||||
row["launch"] = s.launch(preset, context, parallel=lv["parallel"], vision=lv["vision"],
|
||||
extra_sets=lv["sets"], timeout=3600)
|
||||
row["launch"] = s.launch(preset, row["context"], parallel=lv["parallel"], vision=lv["vision"],
|
||||
extra_sets=lv["sets"], kv=lv.get("kv"), mtp=lv.get("mtp"), timeout=3600)
|
||||
ready = row["launch"].get("ready")
|
||||
row["switch_s"] = round(time.perf_counter() - t0, 1) if ready else None
|
||||
row["engine"] = s.engine_lines()
|
||||
@@ -330,6 +359,11 @@ def measure_levels(r: StageResult, s: Strata, preset: dict, context: int, levels
|
||||
r.save()
|
||||
s.stop()
|
||||
r["game_choice"] = pick_game_level(rows)
|
||||
measured = [x for x in rows if x["key"].startswith("game_") and x.get("vram_free_mib") is not None]
|
||||
if r["game_choice"] is None and measured:
|
||||
most = max(measured, key=lambda x: x["vram_free_mib"])
|
||||
r.note(f"no game placement leaves {GAME_RESERVE_MIB} MiB free; the most free is "
|
||||
f"{most['key']}: {most['vram_free_mib']} MiB")
|
||||
|
||||
|
||||
def pick_game_level(rows: list[dict], reserve_mib: int = GAME_RESERVE_MIB) -> dict | None:
|
||||
|
||||
Reference in New Issue
Block a user