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:
@@ -455,28 +455,31 @@ def test_a_lying_model_fails_the_stage_and_the_next_model_is_measured(tmp_path):
|
||||
|
||||
|
||||
def _run_levels_stage(tmp_path, monkeypatch, fake_server, gpu, ready=lambda sets: True):
|
||||
"""Run the stage with Strata replaced; ``gpu(launched_sets)`` is nvidia-smi's (used, total)."""
|
||||
"""Run the stage with Strata replaced; ``gpu(running)`` is nvidia-smi's (used, total), where
|
||||
``running`` is the started placement ({"sets", "context", "kv", "mtp"}) or None."""
|
||||
port = int(fake_server.rsplit(":", 1)[1].split("/")[0])
|
||||
monkeypatch.setattr(llm, "PORT", port)
|
||||
started = []
|
||||
running = {"sets": None}
|
||||
running = {"now": None}
|
||||
|
||||
def launch(self, preset, context, parallel, vision="on", extra_sets=None, restart=False, timeout=0):
|
||||
started.append({"parallel": parallel, "vision": vision, "sets": list(extra_sets or [])})
|
||||
ok = ready(extra_sets or [])
|
||||
running["sets"] = list(extra_sets or []) if ok else None
|
||||
return {"ready": ok}
|
||||
def launch(self, preset, context, parallel, vision="on", extra_sets=None, restart=False, timeout=0,
|
||||
kv=None, mtp=None):
|
||||
spec = {"parallel": parallel, "vision": vision, "sets": list(extra_sets or []), "context": context,
|
||||
"kv": kv, "mtp": mtp}
|
||||
started.append(spec)
|
||||
running["now"] = spec if ready(extra_sets or []) else None
|
||||
return {"ready": running["now"] is not None}
|
||||
|
||||
def stop(self):
|
||||
running["sets"] = None
|
||||
running["now"] = None
|
||||
|
||||
monkeypatch.setattr(llm.Strata, "install", lambda self: True)
|
||||
monkeypatch.setattr(llm.Strata, "plan", lambda self, preset, context: {})
|
||||
monkeypatch.setattr(llm.Strata, "launch", launch)
|
||||
monkeypatch.setattr(llm.Strata, "stop", stop)
|
||||
monkeypatch.setattr(llm, "port_in_use", lambda p: running["sets"] is not None)
|
||||
monkeypatch.setattr(llm, "gpu_memory_mib", lambda: gpu(running["sets"]))
|
||||
monkeypatch.setattr(common, "gpu_memory_mib", lambda: gpu(running["sets"]))
|
||||
monkeypatch.setattr(llm, "port_in_use", lambda p: running["now"] is not None)
|
||||
monkeypatch.setattr(llm, "gpu_memory_mib", lambda: gpu(running["now"]))
|
||||
monkeypatch.setattr(common, "gpu_memory_mib", lambda: gpu(running["now"]))
|
||||
out = tmp_path / "results" / "gamemode.json"
|
||||
out.parent.mkdir(parents=True)
|
||||
monkeypatch.setattr(sys, "argv", ["llm.py", "--out", str(out), "--work", str(tmp_path),
|
||||
@@ -485,37 +488,97 @@ def _run_levels_stage(tmp_path, monkeypatch, fake_server, gpu, ready=lambda sets
|
||||
return json.loads(out.read_text(encoding="utf-8")), started, running
|
||||
|
||||
|
||||
def _vram(sets):
|
||||
"""16 GB card, 2 GB used by Windows; the model takes less with a smaller expert budget."""
|
||||
if sets is None:
|
||||
return 2000, 16303
|
||||
experts = next((int(s.split("=")[1]) for s in sets if s.startswith("expert-vram=")), None)
|
||||
return (2000 + (13400 if experts is None else 1500 + experts * 1024)), 16303
|
||||
def _model_mib(spec):
|
||||
"""Roughly what the 2026-11-10 game PC showed: 4.4 GiB of weights that never leave the card, the
|
||||
expert budget, the conversation memory (int8, 1.43 GiB per 32K; q4_0 half), about 1 GB for the
|
||||
MTP drafter and 1.5 GB of buffers. With no expert budget Strata fills the card."""
|
||||
experts = next((int(s.split("=")[1]) for s in spec["sets"] if s.startswith("expert-vram=")), None)
|
||||
if experts is None:
|
||||
return 13400
|
||||
kv = 1464 * spec["context"] / 32768 * (0.5 if spec["kv"] == "q4_0" else 1)
|
||||
return int(4506 + experts * 1024 + kv + (0 if spec["mtp"] == "off" else 1000) + 1500)
|
||||
|
||||
|
||||
def _vram(running):
|
||||
"""16 GB card, 2 GB used by Windows."""
|
||||
return (2000 if running is None else 2000 + _model_mib(running)), 16303
|
||||
|
||||
|
||||
def _vram_big_floor(running):
|
||||
"""A card where even the smallest placement leaves the game less than its reserve."""
|
||||
return (2000 if running is None else 2000 + _model_mib(running) + 3000), 16303
|
||||
|
||||
|
||||
def test_gamemode_measures_every_placement_and_returns_to_normal(tmp_path, monkeypatch, fake_server):
|
||||
r, started, running = _run_levels_stage(tmp_path, monkeypatch, fake_server, _vram)
|
||||
assert r["stage"] == "gamemode" and r["status"] == "ok"
|
||||
assert [x["sets"] for x in started] == [lv["sets"] for lv in llm.LEVELS]
|
||||
# Each placement starts with its own context, conversation memory format and drafter.
|
||||
for spec, lv in zip(started, llm.LEVELS):
|
||||
assert spec["context"] == lv.get("context", 32768)
|
||||
assert (spec["kv"], spec["mtp"]) == (lv.get("kv"), lv.get("mtp"))
|
||||
assert started[-1] == started[0] # the last start is the normal placement again
|
||||
for lv in llm.LEVELS:
|
||||
row = next(x for x in r["levels"] if x["key"] == lv["key"])
|
||||
assert row["switch_s"] is not None
|
||||
assert row["voice_first_sentence"]["n"] > 0
|
||||
rows = {x["key"]: x for x in r["levels"]}
|
||||
assert rows["game_experts_2g"]["vram_free_mib"] > rows["game_experts_6g"]["vram_free_mib"] > rows["normal"]["vram_free_mib"]
|
||||
assert running["sets"] is None # the model is not left running after the stage
|
||||
for lv in llm.LEVELS:
|
||||
assert rows[lv["key"]]["switch_s"] is not None
|
||||
assert rows[lv["key"]]["voice_first_sentence"]["n"] > 0
|
||||
# The game placements go below the 2 GB expert budget that still left a 16 GB card only 4 GB.
|
||||
game = [rows[lv["key"]] for lv in llm.LEVELS if lv["key"].startswith("game_")]
|
||||
assert max(x["vram_free_mib"] for x in game) > min(x["vram_free_mib"] for x in game)
|
||||
assert min(x["vram_free_mib"] for x in game) > rows["normal"]["vram_free_mib"]
|
||||
# On this card a smaller placement does leave the reserve, and the choice is one that does.
|
||||
assert r["game_choice"]["vram_free_mib"] >= llm.GAME_RESERVE_MIB
|
||||
assert running["now"] is None # the model is not left running after the stage
|
||||
|
||||
|
||||
def test_when_no_placement_leaves_the_reserve_the_result_says_how_much_is_free(tmp_path, monkeypatch,
|
||||
fake_server):
|
||||
r, _, _ = _run_levels_stage(tmp_path, monkeypatch, fake_server, _vram_big_floor)
|
||||
assert r["game_choice"] is None
|
||||
assert r["status"] == "ok" # every placement was measured; it is the card that is too small
|
||||
most = max(x["vram_free_mib"] for x in r["levels"] if x["key"].startswith("game_"))
|
||||
assert any(str(most) in n for n in r["notes"])
|
||||
|
||||
|
||||
def test_engine_lines_are_only_those_of_the_latest_start(tmp_path):
|
||||
# The engine log is appended across starts: reading it from the top repeated an old start's
|
||||
# placement lines for every placement.
|
||||
s = llm.Strata(tmp_path, tmp_path / "strata.log")
|
||||
log = tmp_path / "strata" / "localappdata" / "Strata" / "launch" / "ud-q4_k_xl-32k.engine.log"
|
||||
log.parent.mkdir(parents=True)
|
||||
log.write_text("strata-q36: hybrid experts: 59 of 256 per layer in VRAM (4.32 GiB)\n", encoding="utf-8")
|
||||
s.mark_engine_logs()
|
||||
with open(log, "a", encoding="utf-8") as f:
|
||||
f.write("strata-q36: hybrid experts: 14 of 256 per layer in VRAM (1.02 GiB)\n")
|
||||
assert s.engine_lines() == ["strata-q36: hybrid experts: 14 of 256 per layer in VRAM (1.02 GiB)"]
|
||||
# A log written again from the start (shorter than the mark) is read whole.
|
||||
log.write_text("strata-q36: context 8192 cells\n", encoding="utf-8")
|
||||
assert s.engine_lines() == ["strata-q36: context 8192 cells"]
|
||||
|
||||
|
||||
def test_placement_memory_format_and_drafter_reach_the_launch_command(tmp_path, monkeypatch):
|
||||
ran = []
|
||||
monkeypatch.setattr(llm, "run_logged", lambda cmd, *a, **k: ran.append(cmd) or 1)
|
||||
s = llm.Strata(tmp_path, tmp_path / "strata.log")
|
||||
monkeypatch.setattr(s, "supported_flags", lambda: {"--family", "--model", "--context", "--kv", "--mtp"})
|
||||
s.launch(llm.PRESETS["fast"], 8192, parallel=1, kv="q4_0", mtp="off")
|
||||
s.launch(llm.PRESETS["fast"], 32768, parallel=1)
|
||||
with_opts, plain = ran
|
||||
assert with_opts[with_opts.index("--kv") + 1] == "q4_0" and with_opts[with_opts.index("--mtp") + 1] == "off"
|
||||
assert with_opts[with_opts.index("--context") + 1] == "8192"
|
||||
assert "--kv" not in plain and "--mtp" not in plain
|
||||
|
||||
|
||||
def test_a_placement_that_does_not_start_is_recorded_and_the_rest_still_run(tmp_path, monkeypatch, fake_server):
|
||||
r, started, _ = _run_levels_stage(tmp_path, monkeypatch, fake_server, _vram,
|
||||
ready=lambda sets: "expert-vram=4" not in sets)
|
||||
ready=lambda sets: "expert-vram=1" not in sets)
|
||||
assert len(started) == len(llm.LEVELS)
|
||||
row = next(x for x in r["levels"] if x["key"] == "game_experts_4g")
|
||||
failed = [lv["key"] for lv in llm.LEVELS if "expert-vram=1" in lv["sets"]]
|
||||
row = next(x for x in r["levels"] if x["key"] == failed[0])
|
||||
assert row["switch_s"] is None and "decode_tok_s" not in row
|
||||
# A placement that never started is a gap in the measurement, not a pass.
|
||||
assert r["status"] == "partial"
|
||||
assert any("game_experts_4g" in e["where"] for e in r["errors"])
|
||||
assert any(failed[0] in e["where"] for e in r["errors"])
|
||||
|
||||
|
||||
def test_only_the_normal_placement_starting_is_not_ok(tmp_path, monkeypatch, fake_server):
|
||||
@@ -523,7 +586,8 @@ def test_only_the_normal_placement_starting_is_not_ok(tmp_path, monkeypatch, fak
|
||||
ready=lambda sets: not any(s.startswith("expert-vram=") for s in sets))
|
||||
assert r["game_choice"] is None
|
||||
assert r["status"] == "partial"
|
||||
assert sum(1 for e in r["errors"] if e["where"].startswith("level game_")) == 4
|
||||
game = [lv for lv in llm.LEVELS if lv["key"].startswith("game_")]
|
||||
assert sum(1 for e in r["errors"] if e["where"].startswith("level game_")) == len(game)
|
||||
|
||||
|
||||
def _row(key, free, tok_s):
|
||||
@@ -542,12 +606,12 @@ def test_no_game_choice_when_no_placement_leaves_the_reserve():
|
||||
assert llm.pick_game_level(rows, reserve_mib=8000) is None
|
||||
|
||||
|
||||
def test_kit_has_a_one_click_runner_for_desktop_and_gamemode():
|
||||
def test_kit_has_a_one_click_runner_for_gamemode():
|
||||
import m0
|
||||
keys = [s[0] for s in m0.STAGES]
|
||||
assert "gamemode" in keys
|
||||
bat = (Path(m0.KIT) / "run_m0_gamemode.bat").read_text(encoding="utf-8")
|
||||
assert "-Only desktop,gamemode" in bat and "-Redo" in bat
|
||||
assert "-Only gamemode" in bat and "-Redo" in bat
|
||||
|
||||
|
||||
def test_a_measurement_error_inside_a_placement_marks_the_stage_partial(tmp_path, monkeypatch, fake_server):
|
||||
|
||||
Reference in New Issue
Block a user