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:
@@ -55,11 +55,11 @@ FAKE_CLI = textwrap.dedent(r'''
|
||||
return args[args.index(name) + 1] if name in args else None
|
||||
|
||||
def windows(s):
|
||||
w = [{"id": "w-1", "app_name": "WINWORD", "title": SECRET + ".docx - Word", "accessible": True}]
|
||||
w = [{"id": "w-1", "app_name": "WINWORD.EXE", "title": SECRET + ".docx - Word", "accessible": True}]
|
||||
if s.get("calc"):
|
||||
w.append({"id": "w-200", "app_name": "CalculatorApp", "title": "계산기", "accessible": True})
|
||||
w.append({"id": "w-200", "app_name": "CalculatorApp.exe", "title": "계산기", "accessible": True})
|
||||
if s.get("browser"):
|
||||
w.append({"id": "w-100", "app_name": "chrome", "title": s["browser"] + " - Google Chrome",
|
||||
w.append({"id": "w-100", "app_name": "chrome.exe", "title": s["browser"] + " - Google Chrome",
|
||||
"accessible": True})
|
||||
return w
|
||||
|
||||
@@ -96,7 +96,11 @@ FAKE_CLI = textwrap.dedent(r'''
|
||||
return ok(cmd, {"platform": "windows", "permissions": {"accessibility": {"state": "granted"}},
|
||||
"supported_surfaces": ["window", "menu"]})
|
||||
if cmd == "list-apps":
|
||||
return ok(cmd, {"apps": [{"name": "Discord"}, {"name": "explorer"}, {"name": "WINWORD"}]})
|
||||
# Windows lists the process image names of window owners. A UWP
|
||||
# app's windows belong to ApplicationFrameHost, so the calculator
|
||||
# is not listed under its own name.
|
||||
return ok(cmd, {"apps": [{"name": "ApplicationFrameHost.exe"}, {"name": "Discord.exe"},
|
||||
{"name": "explorer.exe"}, {"name": "WINWORD.EXE"}]})
|
||||
if cmd == "list-windows":
|
||||
if MODE == "cli_fail":
|
||||
fail(cmd, "PLATFORM_ERROR", SECRET)
|
||||
@@ -108,13 +112,15 @@ FAKE_CLI = textwrap.dedent(r'''
|
||||
return ok(cmd, {"app": "calc", "pid": 1})
|
||||
fail(cmd, "APP_NOT_FOUND", "no such app")
|
||||
if cmd == "close-app":
|
||||
if a[1].lower() == "calculatorapp.exe":
|
||||
fail(cmd, "APP_NOT_FOUND", "no running app named " + a[1])
|
||||
s["calc"] = False
|
||||
save(s)
|
||||
return ok(cmd, {"app": a[1]})
|
||||
if cmd == "find":
|
||||
if opt(a, "--native-id"):
|
||||
nid = opt(a, "--native-id")
|
||||
if opt(a, "--app") != "CalculatorApp" or not s.get("calc"):
|
||||
if opt(a, "--app") != "CalculatorApp.exe" or not s.get("calc"):
|
||||
return ok(cmd, {"matches": [], "total_matches": 0})
|
||||
name = ("표시는 %s입니다" % s["display"]) if nid == "CalculatorResults" else nid
|
||||
return ok(cmd, {"matches": [{"ref_id": "@s1:" + nid, "name": name, "role": "button"}]})
|
||||
@@ -144,9 +150,16 @@ FAKE_CLI = textwrap.dedent(r'''
|
||||
return ok(cmd, {"action": "set-value"})
|
||||
if cmd == "get":
|
||||
return ok(cmd, {"property": "value", "ref": a[1], "value": s.get("value", "")})
|
||||
if cmd == "force-close": # stands in for taskkill /IM <image>
|
||||
if a[-1] == "CalculatorApp.exe":
|
||||
s["calc"] = False
|
||||
save(s)
|
||||
return
|
||||
if cmd == "snapshot":
|
||||
app = opt(a, "--app")
|
||||
if app == "explorer":
|
||||
if app not in ("Discord.exe", "explorer.exe"):
|
||||
fail(cmd, "APP_NOT_FOUND", "no running app named " + str(app))
|
||||
if app == "explorer.exe":
|
||||
fail(cmd, "AMBIGUOUS_TARGET", "windows: " + SECRET + ".docx")
|
||||
return ok(cmd, {"app": app, "ref_count": 120, "complete": True,
|
||||
"tree": {"role": "window", "name": SECRET + " DM"}})
|
||||
@@ -165,6 +178,8 @@ def fake(tmp_path, monkeypatch):
|
||||
monkeypatch.setenv("FAKE_AD_SECRET", SECRET)
|
||||
monkeypatch.delenv("FAKE_AD_MODE", raising=False)
|
||||
|
||||
monkeypatch.setattr(desktop, "FORCE_CLOSE", [sys.executable, str(script), "force-close"])
|
||||
|
||||
class Fake:
|
||||
cmd = [sys.executable, str(script)]
|
||||
log = tmp_path / "desktop.log"
|
||||
@@ -279,3 +294,19 @@ def test_an_already_open_calculator_is_left_alone(fake, tmp_path):
|
||||
assert result["ok"] is False and result["skipped"]
|
||||
s = json.loads(state.read_text(encoding="utf-8"))
|
||||
assert s["calc"] is True and s["display"] == "777" # not pressed, not closed
|
||||
|
||||
|
||||
def test_running_apps_are_read_by_the_process_name_windows_lists(fake):
|
||||
result = desktop.check_apps(fake.desk())
|
||||
assert result["Discord"]["running"] is True and result["Discord"]["ok"] is True
|
||||
assert result["Discord"]["ref_count"] == 120
|
||||
assert result["explorer"]["running"] is True
|
||||
assert result["explorer"]["error"] == "AMBIGUOUS_TARGET"
|
||||
|
||||
|
||||
def test_the_launched_calculator_is_closed_when_close_app_cannot_find_it(fake, tmp_path):
|
||||
result = desktop.check_calculator(fake.desk())
|
||||
assert result["ok"] is True
|
||||
assert result["close_error"] == "APP_NOT_FOUND"
|
||||
assert result["closed"] is True
|
||||
assert json.loads((tmp_path / "state.json").read_text(encoding="utf-8"))["calc"] is False
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user