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:
javis-bot
2026-11-10 21:35:23 +09:00
parent a2e4f064d2
commit 2a85b6afa5
6 changed files with 342 additions and 39 deletions

View File

@@ -10,12 +10,15 @@ Options (--opt key=value):
only=together the same with the STT loaded next to it and transcribing ten
speakers at once, on the GPU and on the CPU (needs stt_python=)
only=live game placements and the STT while the user runs a real game
only=tune the normal placement with room left for the STT, and the STT
doing fewer partial passes while the LLM answers
stt_python=PATH the Python of the stt venv (m0.py passes it)
"""
from __future__ import annotations
import json
import math
import os
import re
import shutil
@@ -96,7 +99,31 @@ TOGETHER = [
]
# With a real game running: only game placements (the normal one would take the game's VRAM).
LIVE = [lv for lv in TOGETHER if lv["key"].startswith("game_")]
LEVEL_SETS = {"levels": LEVELS, "together": TOGETHER, "live": LIVE}
# The fixes for what gamemode_stt showed (user decision, 2026-11-10):
# - Strata's automatic placement filled the card with experts and left the STT no room (15.9 of
# 16.3 GB with the STT busy; the first token after a long context went from 1.6 to 7.5 s). The
# qwen36 engine ignores --vram-reserve-mib, so "stt_room" sets --expert-vram from what this PC
# measures: one start without experts (with the STT loaded) gives what the LLM needs before any
# expert; the experts get what is left after the STT's ten-speaker growth and a margin.
# - The STT's partial passes took the GPU from the LLM (output 1/2.5 to 1/3). "stt_pace" is what
# the app would do while the LLM answers: a ten-speaker partial pass every 2 s, or none, and the
# finals at once. The LLM is measured the whole time, so the pace holds for the whole run.
# The 2 GB expert placement is the game minimum on a 16 GB card (faster than 0 GB in a real game).
STT_ROOM_MARGIN_MIB = 768 # what Strata's qwen36 engine itself keeps free when it places experts
STT_GROWTH_FALLBACK_MIB = 1440 # M0 stt on the game PC: ten speakers at once over the loaded model
_PARTIAL_2S = {"partial_every": 2.0, "final_every": 0.5}
_FINALS_ONLY = {"partial_every": None, "final_every": 0.5}
_ROOM = {"parallel": 1, "vision": "gpu", "sets": ["prefill=2048"], "stt": "cuda", "stt_room": True}
TUNED = [
{"key": "normal_stt_room_stt_gpu", **_ROOM},
{"key": "normal_stt_room_partial_2s", **_ROOM, "stt_pace": _PARTIAL_2S},
{"key": "normal_stt_room_finals_only", **_ROOM, "stt_pace": _FINALS_ONLY},
{"key": "game_experts_2g_16k_partial_2s", **_GAME, "context": 16384, "sets": _EXP2, "stt": "cuda",
"stt_pace": _PARTIAL_2S},
{"key": "game_experts_2g_16k_finals_only", **_GAME, "context": 16384, "sets": _EXP2, "stt": "cuda",
"stt_pace": _FINALS_ONLY},
]
LEVEL_SETS = {"levels": LEVELS, "together": TOGETHER, "live": LIVE, "tune": TUNED}
INSTALL_URL = "https://github.com/Niko1221/Strata/releases/latest/download/install.ps1"
@@ -255,7 +282,7 @@ class Strata:
class SttLoad:
"""The STT worker (stt.py mode=load in the stt venv) as a separate process next to the LLM."""
def __init__(self, python: str, work: Path, device: str, log: Path):
def __init__(self, python: str, work: Path, device: str, log: Path, pace: dict | None = None):
d = work / "cache" / f"stt_load_{device}"
shutil.rmtree(d, ignore_errors=True)
d.mkdir(parents=True)
@@ -264,6 +291,10 @@ class SttLoad:
self.cmd = [python, str(Path(__file__).resolve().parent / "stt.py"), "--out", str(self.out),
"--work", str(work), "--opt", "mode=load", "--opt", f"device={device}",
"--opt", f"go={self.go_file}", "--opt", f"stop={self.stop_file}"]
if pace is not None:
for key in ("partial_every", "final_every"):
v = pace.get(key)
self.cmd += ["--opt", f"{key}={'none' if v is None else v}"]
self.proc: subprocess.Popen | None = None
def _read(self) -> dict:
@@ -307,15 +338,17 @@ class SttLoad:
self._logf.close()
def stt_gaps(busy: dict) -> list[str]:
def stt_gaps(busy: dict, pace: dict | None = None) -> list[str]:
"""Why an STT load next to the LLM did not measure what it should: its errors, a worker that
did not finish (timed out, died, never started), or no ten-speaker or single-clip timings."""
did not finish (timed out, died, never started), or no ten-speaker or single-clip timings
(no ten-speaker ones are expected when the pace turns the partials off)."""
gaps = list(busy.get("errors") or [])
if busy.get("status") != "done":
if not gaps:
gaps.append(f"stt worker ended as {busy.get('status') or 'nothing written'}")
return gaps
for key in ("batch10_s", "single_s"):
partials = pace is None or pace.get("partial_every") is not None
for key in (("batch10_s", "single_s") if partials else ("single_s",)):
if not (busy.get(key) or {}).get("n"):
gaps.append(f"stt worker measured no {key}")
return gaps
@@ -406,6 +439,7 @@ def measure_levels(r: StageResult, s: Strata, preset: dict, context: int, levels
base = f"http://127.0.0.1:{PORT}/v1"
rows: list[dict] = []
r["levels"] = rows
rooms: dict = {} # one probe per placement that leaves the STT room
for lv in levels:
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")}
@@ -419,14 +453,24 @@ def measure_levels(r: StageResult, s: Strata, preset: dict, context: int, levels
with GpuSampler(interval=1) as g:
try:
if lv.get("stt"):
stt = SttLoad(stt_python, s.log.parent.parent, lv["stt"], s.log.with_name("stt_load.log"))
row["stt"] = {"device": lv["stt"], "load": stt.start()}
stt = SttLoad(stt_python, s.log.parent.parent, lv["stt"], s.log.with_name("stt_load.log"),
pace=lv.get("stt_pace"))
row["stt"] = {"device": lv["stt"], "pace": lv.get("stt_pace"), "load": stt.start()}
if row["stt"]["load"].get("status") != "loaded":
r.error(f"level {lv['key']}", "; ".join(row["stt"]["load"].get("errors") or [])
or "the STT did not load")
continue
sets = list(lv["sets"])
if lv.get("stt_room"):
where = (row["context"], lv["parallel"], lv["vision"])
if where not in rooms:
rooms[where] = stt_room(r, s, preset, row, lv, base)
row["stt_room"] = rooms[where]
sets.append(f"expert-vram={row['stt_room']['expert_vram_gib']}")
row["sets"] = sets
t0 = time.perf_counter() # the probe is not part of the switch
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)
extra_sets=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()
@@ -446,8 +490,9 @@ def measure_levels(r: StageResult, s: Strata, preset: dict, context: int, levels
if stt:
busy = stt.finish()
row["stt"].update({k: busy.get(k) for k in ("status", "batch10_s", "single_s", "errors",
"seconds")})
for err in stt_gaps(busy):
"seconds", "busy_share", "final_wait_s")
if k in busy})
for err in stt_gaps(busy, lv.get("stt_pace")):
r.error(f"level {lv['key']} stt", err)
else:
r.error(f"level {lv['key']}", "the placement did not start")
@@ -476,6 +521,64 @@ def measure_levels(r: StageResult, s: Strata, preset: dict, context: int, levels
f"{most['key']}: {most['vram_free_mib']} MiB")
def stt_growth_mib(work: Path) -> int:
"""What ten speakers at once add over the loaded STT model, from this PC's own stt stage."""
try:
return int(read_json(work / "results" / "stt.json")["run_int8_float16"]["batch_speakers"]["vram_added_mib"])
except (OSError, ValueError, KeyError, TypeError):
return STT_GROWTH_FALLBACK_MIB
def staging_gib(lines: list[str], default: float = 1.10) -> float:
"""The long-prompt staging the expert budget holds first (engine log: "(1.10 GiB staging)")."""
for line in lines:
m = re.search(r"([0-9.]+) GiB staging", line)
if m:
return float(m.group(1))
return default
def expert_budget_gib(total_mib: int, used_mib: int, probe_model_mib: int, staging: float, growth_mib: int,
margin_mib: int = STT_ROOM_MARGIN_MIB) -> float:
"""--expert-vram (GiB, rounded down to 0.1) that leaves the STT's growth and the margin free.
The budget first holds the staging, which the start without experts already has."""
spare = total_mib - used_mib - probe_model_mib - growth_mib - margin_mib
if spare <= 0:
return 0.0
return math.floor((staging * 1024 + spare) / 1024 * 10) / 10
def stt_room(r: StageResult, s: Strata, preset: dict, row: dict, lv: dict, base: str) -> dict:
"""Start the placement once without experts (the STT model already loaded), see what the LLM
holds, stop it, and work out the expert budget that leaves the STT's ten-speaker growth free."""
room: dict = {"stt_growth_mib": stt_growth_mib(s.log.parent.parent), "margin_mib": STT_ROOM_MARGIN_MIB,
"expert_vram_gib": 0.0}
say(" STT 자리 계산: 전문가 층 없이 한 번 켜서 LLM 기본 VRAM을 잽니다")
before = gpu_memory_mib()
launch = s.launch(preset, row["context"], parallel=lv["parallel"], vision=lv["vision"],
extra_sets=["expert-vram=0"] + [x for x in lv["sets"] if not x.startswith("expert-vram=")],
timeout=3600)
room["probe_ready"] = bool(launch.get("ready"))
if launch.get("ready"):
try:
ChatClient(base).chat([{"role": "user", "content": "안녕"}], max_tokens=8)
except Exception as e:
r.error(f"level {lv['key']} stt room", e)
after = gpu_memory_mib()
lines = s.engine_lines()
if before and after:
room.update(probe_model_mib=after[0] - before[0], used_before_mib=before[0], total_mib=before[1],
staging_gib=staging_gib(lines))
room["expert_vram_gib"] = expert_budget_gib(before[1], before[0], room["probe_model_mib"],
room["staging_gib"], room["stt_growth_mib"])
if room["expert_vram_gib"] == 0:
r.note(f"{lv['key']}: no room for experts next to the STT; started with --expert-vram 0")
else:
r.error(f"level {lv['key']} stt room", "the start without experts did not come up; --expert-vram 0")
s.stop()
return room
def ask_for_a_game() -> bool:
"""The live stage needs someone to start a game first. False when nobody is there or they say no."""
if not interactive():
@@ -540,7 +643,8 @@ def measure_strata(r: StageResult, work: Path, which: str, context: int, only: s
r["skipped"] = "no game started"
return
r.note("measured while the user's game was running")
measure_levels(r, s, preset, context, LEVEL_SETS[only], stt_python=stt_python, choose=only != "live")
measure_levels(r, s, preset, context, LEVEL_SETS[only], stt_python=stt_python,
choose=only in ("levels", "together"))
if only == "live":
say("\a 게임 중 측정이 끝났습니다. 게임을 꺼도 됩니다.")
try:
@@ -618,7 +722,7 @@ def main() -> int:
context = int(opts.get("context", "32768"))
only = opts.get("only", "")
name = {"tools": f"tools_{which}", "levels": "gamemode", "together": "gamemode_stt",
"live": "gamemode_live"}.get(only, f"llm_{which}")
"live": "gamemode_live", "tune": "gamemode_tune"}.get(only, f"llm_{which}")
r = StageResult(name, out)
try:
if opts.get("url"):