feat(m0): measure the one model's game placements and fix desktop app matching

Add a gamemode stage that restarts Qwen3.6-35B-A3B with a smaller routed
expert VRAM budget (6, 4, 2 GiB, and 2 GiB with half the CPU workers), then
the normal placement again, and records switch time, free VRAM, output speed,
first spoken sentence and 8K-context first token for each. It names the
fastest placement that leaves the game its 8 GB reserve. Strata 0.1.59's
qwen36 engine cannot shrink VRAM while running, so each placement is a restart.

The desktop stage now matches running apps by the process image name Windows
lists (Discord.exe) and closes the calculator it launched by image name when
close-app cannot find a UWP app.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
javis-bot
2026-11-10 17:39:42 +09:00
parent c63a859ced
commit 13de978cf9
8 changed files with 302 additions and 17 deletions

View File

@@ -449,3 +449,91 @@ def test_a_lying_model_fails_the_stage_and_the_next_model_is_measured(tmp_path):
llm.try_candidates(r, "fast", summary, lambda p: tried.append(p["model"]) or _summary(24, 24), free_gb=lambda: 999)
assert tried == [llm.CANDIDATES["fast"][0]["model"]]
assert r["tools_verdict"]["chosen"] == llm.CANDIDATES["fast"][0]["label"]
# --- gamemode stage: the one model in each placement the app switches to ----
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)."""
port = int(fake_server.rsplit(":", 1)[1].split("/")[0])
monkeypatch.setattr(llm, "PORT", port)
started = []
running = {"sets": 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 stop(self):
running["sets"] = 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"]))
out = tmp_path / "results" / "gamemode.json"
out.parent.mkdir(parents=True)
monkeypatch.setattr(sys, "argv", ["llm.py", "--out", str(out), "--work", str(tmp_path),
"--opt", "model=fast", "--opt", "only=levels"])
llm.main()
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 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]
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
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)
assert len(started) == len(llm.LEVELS)
row = next(x for x in r["levels"] if x["key"] == "game_experts_4g")
assert row["switch_s"] is None and "decode_tok_s" not in row
def _row(key, free, tok_s):
return {"key": key, "vram_free_mib": free, "decode_tok_s": {"median": tok_s}, "switch_s": 50.0}
def test_game_choice_is_the_fastest_placement_that_leaves_the_reserve_free():
rows = [_row("normal", 900, 82.0), _row("game_experts_6g", 6000, 70.0),
_row("game_experts_4g", 8100, 60.0), _row("game_experts_2g", 10100, 45.0)]
choice = llm.pick_game_level(rows, reserve_mib=8000)
assert choice["key"] == "game_experts_4g" and choice["decode_tok_s"] == 60.0
def test_no_game_choice_when_no_placement_leaves_the_reserve():
rows = [_row("normal", 900, 82.0), _row("game_experts_2g", 7000, 45.0)]
assert llm.pick_game_level(rows, reserve_mib=8000) is None
def test_kit_has_a_one_click_runner_for_desktop_and_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