feat(m0): measure the LLM next to the STT, the STT on the CPU and a real game
gamemode now also starts the 2 GB expert placement with a 16K context and drops the --kv q4_0 and --mtp off rows the Strata 0.1.59 qwen36 engine ignores; the normal placement answers one request at a time. gamemode_stt loads the STT worker (stt.py mode=load) before the LLM picks its placement and keeps it transcribing ten speakers at once while the LLM is measured, so the VRAM left is the real game share. The game placements run with the STT on the GPU and on the CPU. gamemode_live repeats the game rows while the user runs a real game; it only runs when asked for (run_m0_game_live.bat) and is skipped when nobody is at the PC. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -2,6 +2,11 @@
|
||||
|
||||
Runs inside its own venv (faster-whisper, nvidia-cublas-cu12, nvidia-cudnn-cu12).
|
||||
Audio: the synthetic Korean samples in assets/ko_samples (MeloTTS voice).
|
||||
|
||||
With --opt mode=load it is instead the STT load the gamemode stages put next to
|
||||
the LLM: load the model on device=cuda|cpu, write {"status": "loaded"} to --out,
|
||||
wait for the file go=PATH, then transcribe ten speakers at once (and one final
|
||||
clip) on a loop until the file stop=PATH appears, and write the timings.
|
||||
"""
|
||||
|
||||
from __future__ import annotations
|
||||
@@ -14,7 +19,8 @@ import time
|
||||
from pathlib import Path
|
||||
|
||||
sys.path.insert(0, str(Path(__file__).resolve().parent.parent))
|
||||
from m0lib.common import GpuSampler, StageResult, cer, gpu_memory_mib, say, stage_args, stats # noqa: E402
|
||||
from m0lib.common import (GpuSampler, StageResult, cer, gpu_memory_mib, say, stage_args, stats, # noqa: E402
|
||||
write_json)
|
||||
|
||||
SR = 16000
|
||||
ASSETS = Path(__file__).resolve().parent.parent / "assets" / "ko_samples"
|
||||
@@ -71,8 +77,60 @@ def batch_transcribe(model, audios: list, beam: int = 1) -> tuple[list[str], flo
|
||||
return texts, time.perf_counter() - t0
|
||||
|
||||
|
||||
def load_loop(batch, single, go: Path, stop: Path, wait_s: float = 3600, max_s: float = 600) -> dict:
|
||||
"""Wait for ``go``, then run ``batch()`` (ten speakers) and ``single()`` (one final clip)
|
||||
in turn until ``stop`` appears. An error (out of memory) ends the loop and is kept."""
|
||||
t0 = time.monotonic()
|
||||
while not go.exists():
|
||||
if stop.exists() or time.monotonic() - t0 > wait_s:
|
||||
return {"status": "not_started", "batch10_s": stats([]), "single_s": stats([]), "errors": []}
|
||||
time.sleep(0.2)
|
||||
b, one, errors = [], [], []
|
||||
t1 = time.monotonic()
|
||||
while not stop.exists() and time.monotonic() - t1 < max_s:
|
||||
try:
|
||||
for fn, into in ((batch, b), (single, one)):
|
||||
s0 = time.perf_counter()
|
||||
fn()
|
||||
into.append(time.perf_counter() - s0)
|
||||
except Exception as e:
|
||||
errors.append(f"{type(e).__name__}: {str(e)[:300]}")
|
||||
break
|
||||
return {"status": "done", "batch10_s": stats(b), "single_s": stats(one), "errors": errors,
|
||||
"seconds": round(time.monotonic() - t1, 1)}
|
||||
|
||||
|
||||
def load_worker(out: Path, work: Path, opts: dict) -> int:
|
||||
device = opts.get("device", "cuda")
|
||||
ctype = opts.get("compute", "int8_float16" if device == "cuda" else "int8")
|
||||
threads = int(opts.get("threads", "8"))
|
||||
res: dict = {"device": device, "compute_type": ctype, "cpu_threads": threads if device == "cpu" else None}
|
||||
try:
|
||||
if device == "cuda":
|
||||
add_cuda_dll_dirs()
|
||||
from faster_whisper import WhisperModel
|
||||
refs = json.loads((ASSETS / "refs.json").read_text(encoding="utf-8"))["samples"]
|
||||
clips = [read_wav(ASSETS / refs[i % len(refs)]["file"]) for i in range(10)]
|
||||
t0 = time.perf_counter()
|
||||
model = WhisperModel(opts.get("model", "large-v3-turbo"), device=device, compute_type=ctype,
|
||||
cpu_threads=threads if device == "cpu" else 0,
|
||||
download_root=str(work / "models" / "stt"))
|
||||
transcribe(model, clips[0], 1) # warm-up
|
||||
res["load_s"] = round(time.perf_counter() - t0, 2)
|
||||
except Exception as e:
|
||||
write_json(out, dict(res, status="failed", errors=[f"load: {type(e).__name__}: {str(e)[:300]}"]))
|
||||
return 0
|
||||
write_json(out, dict(res, status="loaded"))
|
||||
res.update(load_loop(lambda: batch_transcribe(model, clips), lambda: transcribe(model, clips[0], 1),
|
||||
Path(opts["go"]), Path(opts["stop"])))
|
||||
write_json(out, res)
|
||||
return 0
|
||||
|
||||
|
||||
def main() -> int:
|
||||
out, work, opts = stage_args()
|
||||
if opts.get("mode") == "load":
|
||||
return load_worker(out, work, opts)
|
||||
r = StageResult("stt", out)
|
||||
r["cuda_dll_dirs"] = len(add_cuda_dll_dirs())
|
||||
os.environ.setdefault("HF_HOME", str(work / "models" / "hf"))
|
||||
|
||||
Reference in New Issue
Block a user