feat(m0): measure the normal placement with room for the STT and paced STT partials
The gamemode_stt run showed Strata's automatic placement filling the card next to the STT (15.9 of 16.3 GB, first token 1.6 -> 7.5 s) and the STT's back-to-back partial passes cutting LLM output to a third. The new gamemode_tune stage measures both fixes the user chose: - stt_room: one start without experts (STT loaded) gives the LLM's base VRAM; --expert-vram gets what is left after the STT's ten-speaker growth (from this PC's stt stage) and a 768 MiB margin. - stt_pace: a ten-speaker partial pass every 2 s, or none, with finals every 0.5 s and finals first; records final wait and STT GPU share. run_m0_gamemode_tune.bat runs it unattended. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -493,7 +493,7 @@ def _run_levels_stage(tmp_path, monkeypatch, fake_server, gpu, ready=lambda sets
|
||||
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)
|
||||
out.parent.mkdir(parents=True, exist_ok=True)
|
||||
opts = ["--opt", "model=fast", "--opt", f"only={only}"]
|
||||
for o in extra_opts:
|
||||
opts += ["--opt", o]
|
||||
@@ -504,13 +504,14 @@ def _run_levels_stage(tmp_path, monkeypatch, fake_server, gpu, ready=lambda sets
|
||||
|
||||
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)
|
||||
expert budget (which first holds the 1.1 GiB long-prompt staging, so 0 and 1 cost the same), 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((float(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)
|
||||
return int(4506 + max(experts, 1.1) * 1024 + kv + (0 if spec["mtp"] == "off" else 1000) + 1500)
|
||||
|
||||
|
||||
def _vram(running):
|
||||
@@ -655,27 +656,35 @@ def test_normal_placement_answers_one_request_at_a_time(tmp_path, monkeypatch, f
|
||||
# --- gamemode_stt / gamemode_live: the LLM next to the STT that runs with it --
|
||||
|
||||
|
||||
STT_GPU_MIB = 2740 # M0 stt: the model 1300 MiB and 1440 MiB more for ten speakers at once
|
||||
STT_MODEL_MIB = 1300 # M0 stt: the loaded model
|
||||
STT_GROWTH_MIB = 1440 # M0 stt: what ten speakers at once add over the loaded model
|
||||
STT_GPU_MIB = STT_MODEL_MIB + STT_GROWTH_MIB
|
||||
|
||||
|
||||
class _FakeStt:
|
||||
"""Stands in for the STT worker process: on cuda its model holds VRAM while it is loaded."""
|
||||
"""Stands in for the STT worker process: on cuda its model holds VRAM while it is loaded, and
|
||||
ten speakers at once hold more once it is transcribing (with partials on)."""
|
||||
|
||||
def __init__(self, fail_device=None, broken_at_load=False, finish_result=None):
|
||||
self.finish_result = finish_result
|
||||
self.events: list[str] = []
|
||||
self.devices: list[str] = []
|
||||
self.paces: list = []
|
||||
self.loaded: str | None = None
|
||||
self.busy = False
|
||||
self.running: dict = {}
|
||||
self.fail_device = fail_device
|
||||
self.broken_at_load = broken_at_load
|
||||
|
||||
def used_mib(self) -> int:
|
||||
return STT_GPU_MIB if self.loaded == "cuda" else 0
|
||||
if self.loaded != "cuda":
|
||||
return 0
|
||||
return STT_GPU_MIB if self.busy else STT_MODEL_MIB
|
||||
|
||||
def factory(self, python, work, device, log):
|
||||
def factory(self, python, work, device, log, pace=None):
|
||||
fake = self
|
||||
fake.devices.append(device)
|
||||
fake.paces.append(pace)
|
||||
|
||||
class _One:
|
||||
def start(self, timeout=900):
|
||||
@@ -688,17 +697,20 @@ class _FakeStt:
|
||||
def go(self):
|
||||
assert fake.running.get("now") is not None, "STT load must overlap a running LLM"
|
||||
fake.events.append("stt_go")
|
||||
fake.busy = pace is None or pace.get("partial_every") is not None
|
||||
|
||||
def finish(self, timeout=120):
|
||||
fake.events.append("stt_finish")
|
||||
if fake.finish_result is not None:
|
||||
return fake.finish_result
|
||||
errs = ["RuntimeError: CUDA out of memory"] if device == fake.fail_device else []
|
||||
return {"status": "done", "batch10_s": {"n": 4, "median": 0.9}, "single_s": {"n": 4, "median": 0.2},
|
||||
"errors": errs}
|
||||
partials = pace is None or pace.get("partial_every") is not None
|
||||
return {"status": "done", "batch10_s": {"n": 4 if partials else 0, "median": 0.9},
|
||||
"single_s": {"n": 4, "median": 0.2}, "errors": errs, "pace": pace}
|
||||
|
||||
def close(self):
|
||||
fake.loaded = None
|
||||
fake.busy = False
|
||||
|
||||
return _One()
|
||||
|
||||
@@ -883,3 +895,129 @@ def test_stt_worker_that_ignores_stop_is_reported_as_timed_out_and_killed(tmp_pa
|
||||
assert res["status"] == "timeout" and res["errors"]
|
||||
s.close()
|
||||
assert s.proc.poll() is not None
|
||||
|
||||
|
||||
# --- gamemode_tune: room for the STT in the normal placement, fewer partials while the LLM answers --
|
||||
|
||||
|
||||
class _FakeClock:
|
||||
"""time.monotonic/perf_counter/sleep for the STT loop: passes advance it, nothing waits."""
|
||||
|
||||
def __init__(self):
|
||||
self.t = 0.0
|
||||
|
||||
def monotonic(self):
|
||||
return self.t
|
||||
|
||||
perf_counter = monotonic
|
||||
|
||||
def sleep(self, s):
|
||||
self.t += s
|
||||
|
||||
|
||||
def _paced_run(tmp_path, monkeypatch, pace, run_s=10.0):
|
||||
from m0lib import stt
|
||||
clock = _FakeClock()
|
||||
monkeypatch.setattr(stt, "time", clock)
|
||||
go, stop = tmp_path / "go", tmp_path / "stop"
|
||||
go.write_text("")
|
||||
|
||||
def work(seconds):
|
||||
def fn():
|
||||
clock.t += seconds
|
||||
if clock.t >= run_s:
|
||||
stop.write_text("")
|
||||
return fn
|
||||
|
||||
return stt.load_loop(work(0.9), work(0.2), go, stop, pace=pace)
|
||||
|
||||
|
||||
def test_paced_stt_runs_partials_at_their_interval_and_finals_in_between(tmp_path, monkeypatch):
|
||||
res = _paced_run(tmp_path, monkeypatch, {"partial_every": 2.0, "final_every": 0.5})
|
||||
assert res["status"] == "done" and res["pace"] == {"partial_every": 2.0, "final_every": 0.5}
|
||||
assert 5 <= res["batch10_s"]["n"] <= 6 # one ten-speaker pass every 2 s over 10 s
|
||||
assert res["single_s"]["n"] >= 12 # finals keep coming in between
|
||||
# A final waits at most for the partial pass that is running when it is due.
|
||||
assert res["final_wait_s"]["max"] <= 0.9 + 1e-6
|
||||
assert res["busy_share"] < 1.0 # the GPU gets time back for the LLM
|
||||
|
||||
|
||||
def test_stt_without_a_pace_transcribes_back_to_back(tmp_path, monkeypatch):
|
||||
res = _paced_run(tmp_path, monkeypatch, None)
|
||||
assert res["busy_share"] == 1.0 and res["batch10_s"]["n"] == res["single_s"]["n"]
|
||||
|
||||
|
||||
def test_finals_only_stt_runs_no_ten_speaker_pass(tmp_path, monkeypatch):
|
||||
res = _paced_run(tmp_path, monkeypatch, {"partial_every": None, "final_every": 0.5})
|
||||
assert res["batch10_s"]["n"] == 0 and res["single_s"]["n"] >= 15
|
||||
assert res["busy_share"] < 0.5
|
||||
|
||||
|
||||
def test_stt_worker_command_carries_the_pace(tmp_path):
|
||||
s = llm.SttLoad(sys.executable, tmp_path, "cuda", tmp_path / "stt.log",
|
||||
pace={"partial_every": None, "final_every": 0.5})
|
||||
assert "partial_every=none" in s.cmd and "final_every=0.5" in s.cmd
|
||||
plain = llm.SttLoad(sys.executable, tmp_path, "cuda", tmp_path / "stt2.log")
|
||||
assert not any(str(x).startswith(("partial_every=", "final_every=")) for x in plain.cmd)
|
||||
|
||||
|
||||
def _expert_vram(spec):
|
||||
return next((float(s.split("=")[1]) for s in spec["sets"] if s.startswith("expert-vram=")), None)
|
||||
|
||||
|
||||
def test_tune_stage_leaves_the_stt_room_in_the_normal_placement(tmp_path, monkeypatch, fake_server):
|
||||
stt = _FakeStt()
|
||||
r, started, running = _run_levels_stage(tmp_path, monkeypatch, fake_server, _vram, only="tune",
|
||||
extra_opts=["stt_python=py"], stt=stt)
|
||||
assert r["stage"] == "gamemode_tune" and r["status"] == "ok"
|
||||
normal = [lv for lv in llm.TUNED if lv.get("stt_room")]
|
||||
# One start without experts measures what the LLM needs before any expert, with the STT loaded.
|
||||
probes = [x for x in started if _expert_vram(x) == 0 and x["vision"] == normal[0]["vision"]]
|
||||
assert len(probes) == 1 and started[0] is probes[0]
|
||||
rows = {x["key"]: x for x in r["levels"]}
|
||||
budgets = {_expert_vram(x) for x in started[1:] if x["vision"] == normal[0]["vision"]}
|
||||
assert len(budgets) == 1 and budgets.pop() > 0
|
||||
# With the STT at its ten-speaker peak the card keeps the margin free, and not much more.
|
||||
continuous = [rows[lv["key"]] for lv in normal if lv.get("stt_pace") is None]
|
||||
assert continuous
|
||||
for row in continuous:
|
||||
assert llm.STT_ROOM_MARGIN_MIB <= row["vram_free_mib"] < llm.STT_ROOM_MARGIN_MIB + 2 * 103
|
||||
assert row["stt_room"]["stt_growth_mib"] == llm.STT_GROWTH_FALLBACK_MIB
|
||||
# The paces: back to back, fewer partials, finals only; in the normal and the 2 GB game placement.
|
||||
paces = {(lv.get("stt_pace") or {}).get("partial_every", "continuous") for lv in normal}
|
||||
assert paces == {"continuous", 2.0, None}
|
||||
game = [lv for lv in llm.TUNED if lv["key"].startswith("game_")]
|
||||
assert game and all("expert-vram=2" in lv["sets"] for lv in game)
|
||||
assert all(lv.get("stt_pace") for lv in game)
|
||||
assert stt.paces == [lv.get("stt_pace") for lv in llm.TUNED]
|
||||
assert stt.loaded is None and running["now"] is None
|
||||
|
||||
|
||||
def test_stt_room_comes_from_this_pcs_own_stt_measurement(tmp_path, monkeypatch, fake_server):
|
||||
(tmp_path / "results").mkdir(parents=True)
|
||||
(tmp_path / "results" / "stt.json").write_text(json.dumps(
|
||||
{"run_int8_float16": {"batch_speakers": {"vram_added_mib": STT_GROWTH_MIB + 512}}}), encoding="utf-8")
|
||||
r, started, _ = _run_levels_stage(tmp_path, monkeypatch, fake_server, _vram, only="tune",
|
||||
extra_opts=["stt_python=py"], stt=_FakeStt())
|
||||
row = next(x for x in r["levels"] if x.get("stt_room"))
|
||||
assert row["stt_room"]["stt_growth_mib"] == STT_GROWTH_MIB + 512
|
||||
assert row["vram_free_mib"] >= llm.STT_ROOM_MARGIN_MIB + 512
|
||||
|
||||
|
||||
def test_card_without_room_for_any_expert_starts_the_normal_placement_with_none(tmp_path, monkeypatch,
|
||||
fake_server):
|
||||
def small(running):
|
||||
return _vram(running)[0], 12000
|
||||
|
||||
r, started, _ = _run_levels_stage(tmp_path, monkeypatch, fake_server, small, only="tune",
|
||||
extra_opts=["stt_python=py"], stt=_FakeStt())
|
||||
row = next(x for x in r["levels"] if x.get("stt_room"))
|
||||
assert row["stt_room"]["expert_vram_gib"] == 0
|
||||
assert any("no room" in n for n in r["notes"])
|
||||
|
||||
|
||||
def test_tune_stage_runs_with_the_stt_python_and_has_a_one_click_runner(tmp_path, monkeypatch):
|
||||
import m0
|
||||
assert "gamemode_tune" in m0.NEEDS_STT and "gamemode_tune" not in m0.ON_DEMAND
|
||||
bat = (Path(m0.KIT) / "run_m0_gamemode_tune.bat").read_text(encoding="utf-8")
|
||||
assert "-Only gamemode_tune" in bat and "-Redo" in bat
|
||||
|
||||
Reference in New Issue
Block a user