fix(m0): measure smaller game placements and read only the latest engine start
The first game PC run showed that a 2 GB expert budget still left a 16 GB card only 4.3 GB free: the weights, the 32K int8 conversation memory, the MTP drafter and buffers take about 8.7 GB on their own. The game placements now also shrink the memory format (q4_0), the context (16K, 8K) and the drafter, with half the CPU workers (no speed cost measured). The engine log is appended across starts, so each placement now reads only its own lines; when no placement leaves the reserve the result names the most free one. The gamemode runner skips the desktop stage, which is already measured. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -64,6 +64,6 @@ LLM 단계는 8080 포트를 씁니다. 다른 프로그램이 이 포트를 쓰
|
||||
|
||||
`run_m0_desktop.bat`을 더블클릭하면 PC 제어 도구 단계(`desktop`)만 돕니다. agent-desktop(약 2MB)을 작업 폴더에 받아 쓰고, 1~2분이면 끝납니다. 계산기와 테스트용 브라우저 창이 잠깐 떴다가 닫히니 그동안 손대지 않으시면 됩니다. 입력칸이 값 넣기를 지원하지 않으면 키 입력으로 넣는데, 이때는 그 창이 잠깐 앞으로 나옵니다.
|
||||
|
||||
`run_m0_gamemode.bat`을 더블클릭하면 PC 제어 도구 단계(`desktop`)를 다시 재고, 이어서 게임 중 자동 조절 단계(`gamemode`)를 돕니다. 모델은 이미 받아 둔 것을 쓰므로 새로 받지 않고, 10~15분 걸립니다. 그동안 게임이나 무거운 프로그램은 꺼 두시고 PC에 손대지 않으시면 됩니다.
|
||||
`run_m0_gamemode.bat`을 더블클릭하면 게임 중 자동 조절 단계(`gamemode`)만 돕니다. 같은 모델을 배치 7개(평소, 게임 중 후보 5개, 다시 평소)로 차례로 다시 켜서 잽니다. 게임 중 후보는 전문가 층 VRAM 몫(2GB, 1GB, 0GB)과 함께 대화 메모리 형식(q4_0), 맥락(16K, 8K), MTP 보조 층을 줄입니다. 모델은 이미 받아 둔 것을 쓰므로 새로 받지 않고, 10분 안팎 걸립니다. 그동안 게임이나 무거운 프로그램은 꺼 두시고 PC에 손대지 않으시면 됩니다.
|
||||
|
||||
다 끝나고 필요 없으면 작업 폴더(`\JarvisM0`)를 통째로 지우면 됩니다. Python, 모델, Strata(엔진과 설정 포함)는 모두 그 안에 설치하도록 지정해 두었습니다.
|
||||
|
||||
@@ -57,17 +57,28 @@ PORT = 8080
|
||||
# Strata's qwen36 engine cannot give VRAM back while it runs (POST /v1/vram
|
||||
# answers 400), so each placement is a restart with --expert-vram (GiB for the
|
||||
# routed experts; the rest stay in RAM) and a matching prompt chunk. A game
|
||||
# placement also reads pictures on the CPU and answers one request at a time.
|
||||
# placement also reads pictures on the CPU, answers one request at a time and
|
||||
# leaves the game half the CPU (8 engine workers cost nothing on the 9950X3D).
|
||||
# The first game PC run (2026-11-10) showed that the expert budget is not the
|
||||
# floor: at 2 GB the model still held 10.8 GB and a 16 GB card kept only
|
||||
# 4.3 GB free. The rest is 4.4 GiB of weights that never leave the card, the
|
||||
# conversation memory (1.43 GiB per 32K in int8; q4_0 is half), the MTP
|
||||
# drafter (about 1 GB) and buffers, so the smaller placements also shrink those.
|
||||
# The last row starts the normal placement again: what returning after a game costs.
|
||||
GAME_RESERVE_MIB = 8000
|
||||
_GAME = {"parallel": 1, "vision": "cpu"}
|
||||
_W8 = "pool-workers=8"
|
||||
LEVELS = [
|
||||
{"key": "normal", "parallel": 2, "vision": "gpu", "sets": []},
|
||||
{"key": "game_experts_6g", **_GAME, "sets": ["expert-vram=6", "prefill=2048"]},
|
||||
{"key": "game_experts_4g", **_GAME, "sets": ["expert-vram=4", "prefill=2048"]},
|
||||
{"key": "game_experts_2g", **_GAME, "sets": ["expert-vram=2", "prefill=2048"]},
|
||||
# A game also wants CPU cores: the same placement with half the engine's CPU workers.
|
||||
{"key": "game_experts_2g_8_workers", **_GAME, "sets": ["expert-vram=2", "prefill=2048", "pool-workers=8"]},
|
||||
{"key": "game_experts_2g", **_GAME, "sets": ["expert-vram=2", "prefill=2048", _W8]},
|
||||
{"key": "game_experts_1g_kv_q4_16k", **_GAME, "context": 16384, "kv": "q4_0",
|
||||
"sets": ["expert-vram=1", "prefill=2048", _W8]},
|
||||
{"key": "game_experts_1g_kv_q4_16k_no_mtp", **_GAME, "context": 16384, "kv": "q4_0", "mtp": "off",
|
||||
"sets": ["expert-vram=1", "prefill=2048", _W8]},
|
||||
{"key": "game_experts_0g_kv_q4_16k_no_mtp", **_GAME, "context": 16384, "kv": "q4_0", "mtp": "off",
|
||||
"sets": ["expert-vram=0", "prefill=2048", _W8]},
|
||||
{"key": "game_experts_0g_kv_q4_8k_no_mtp", **_GAME, "context": 8192, "kv": "q4_0", "mtp": "off",
|
||||
"sets": ["expert-vram=0", "prefill=2048", _W8]},
|
||||
{"key": "normal_again", "parallel": 2, "vision": "gpu", "sets": []},
|
||||
]
|
||||
INSTALL_URL = "https://github.com/Niko1221/Strata/releases/latest/download/install.ps1"
|
||||
@@ -118,13 +129,17 @@ class Strata:
|
||||
return self._flags
|
||||
|
||||
def launch_args(self, preset: dict, context: int, parallel: int, vision: str, extra_sets: list[str],
|
||||
restart: bool) -> tuple[list[str], list[str]]:
|
||||
restart: bool, kv: str | None = None, mtp: str | None = None) -> tuple[list[str], list[str]]:
|
||||
want = [("--family", preset["family"]), ("--model", preset["model"]), ("--data-dir", str(self.models)),
|
||||
("--context", str(context)), ("--vision", vision), ("--parallel", str(parallel)),
|
||||
("--access", "local"), ("--port", str(PORT)), ("--no-api-key", None), ("--yes", None),
|
||||
("--no-tui", None)]
|
||||
if preset.get("drafting"):
|
||||
want.append(("--drafting", preset["drafting"]))
|
||||
if kv:
|
||||
want.append(("--kv", kv))
|
||||
if mtp:
|
||||
want.append(("--mtp", mtp))
|
||||
if restart:
|
||||
want.append(("--restart", None))
|
||||
for s in extra_sets:
|
||||
@@ -151,8 +166,9 @@ class Strata:
|
||||
return {"exit": p.returncode, "text": scrub(p.stdout[-3000:] + p.stderr[-2000:])}
|
||||
|
||||
def launch(self, preset: dict, context: int, parallel: int, vision: str = "on",
|
||||
extra_sets: list[str] | None = None, restart: bool = False, timeout: float = 4 * 3600) -> dict:
|
||||
args, dropped = self.launch_args(preset, context, parallel, vision, extra_sets or [], restart)
|
||||
extra_sets: list[str] | None = None, restart: bool = False, timeout: float = 4 * 3600,
|
||||
kv: str | None = None, mtp: str | None = None) -> dict:
|
||||
args, dropped = self.launch_args(preset, context, parallel, vision, extra_sets or [], restart, kv, mtp)
|
||||
last = [0.0]
|
||||
|
||||
def progress(line: str) -> bool:
|
||||
@@ -163,6 +179,7 @@ class Strata:
|
||||
last[0] = time.monotonic()
|
||||
return True
|
||||
|
||||
self.mark_engine_logs()
|
||||
t0 = time.perf_counter()
|
||||
rc = run_logged(self.cmd("launch", *args), self.log, timeout=timeout, env=self.env, echo=True,
|
||||
echo_filter=progress)
|
||||
@@ -187,12 +204,23 @@ class Strata:
|
||||
dest = self.log.with_name(f"{self.log.stem}_engine_{src.name.removesuffix('.engine.log')}.log")
|
||||
dest.write_text(scrub(text), encoding="utf-8")
|
||||
|
||||
def mark_engine_logs(self) -> None:
|
||||
"""Remember how long each engine log is, so engine_lines() reads only what the next start writes."""
|
||||
self._log_marks = {p: p.stat().st_size for p in self.home.rglob("*.engine.log")}
|
||||
|
||||
def engine_lines(self, prefix: str = "strata-q36:", limit: int = 20) -> list[str]:
|
||||
"""The newest engine log's placement lines (how much went to VRAM and RAM), scrubbed."""
|
||||
"""The placement lines (how much went to VRAM and RAM) the newest engine log got since the
|
||||
last start, scrubbed. The log is appended across starts; one written again is read whole."""
|
||||
found = sorted(self.home.rglob("*.engine.log"), key=lambda p: p.stat().st_mtime)
|
||||
if not found:
|
||||
return []
|
||||
text = found[-1].read_text(encoding="utf-8", errors="replace")[-400_000:]
|
||||
src = found[-1]
|
||||
start = getattr(self, "_log_marks", {}).get(src, 0)
|
||||
if src.stat().st_size < start:
|
||||
start = 0
|
||||
with open(src, "rb") as f:
|
||||
f.seek(start)
|
||||
text = f.read()[-400_000:].decode("utf-8", errors="replace")
|
||||
return [scrub(x.strip())[:400] for x in text.splitlines() if x.lstrip().startswith(prefix)][:limit]
|
||||
|
||||
def stop(self) -> None:
|
||||
@@ -291,7 +319,8 @@ def measure_levels(r: StageResult, s: Strata, preset: dict, context: int, levels
|
||||
rows: list[dict] = []
|
||||
r["levels"] = rows
|
||||
for lv in levels:
|
||||
row: dict = {"key": lv["key"], "parallel": lv["parallel"], "vision": lv["vision"], "sets": lv["sets"]}
|
||||
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")}
|
||||
rows.append(row)
|
||||
say(f" - 배치 {lv['key']}: 다시 시작해서 재는 중")
|
||||
t0 = time.perf_counter()
|
||||
@@ -299,8 +328,8 @@ def measure_levels(r: StageResult, s: Strata, preset: dict, context: int, levels
|
||||
idle = gpu_memory_mib()
|
||||
row["vram_idle_mib"] = idle[0] if idle else None
|
||||
with GpuSampler(interval=1) as g:
|
||||
row["launch"] = s.launch(preset, context, parallel=lv["parallel"], vision=lv["vision"],
|
||||
extra_sets=lv["sets"], timeout=3600)
|
||||
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)
|
||||
ready = row["launch"].get("ready")
|
||||
row["switch_s"] = round(time.perf_counter() - t0, 1) if ready else None
|
||||
row["engine"] = s.engine_lines()
|
||||
@@ -330,6 +359,11 @@ def measure_levels(r: StageResult, s: Strata, preset: dict, context: int, levels
|
||||
r.save()
|
||||
s.stop()
|
||||
r["game_choice"] = pick_game_level(rows)
|
||||
measured = [x for x in rows if x["key"].startswith("game_") and x.get("vram_free_mib") is not None]
|
||||
if r["game_choice"] is None and measured:
|
||||
most = max(measured, key=lambda x: x["vram_free_mib"])
|
||||
r.note(f"no game placement leaves {GAME_RESERVE_MIB} MiB free; the most free is "
|
||||
f"{most['key']}: {most['vram_free_mib']} MiB")
|
||||
|
||||
|
||||
def pick_game_level(rows: list[dict], reserve_mib: int = GAME_RESERVE_MIB) -> dict | None:
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
@echo off
|
||||
chcp 65001 >nul
|
||||
powershell -NoProfile -ExecutionPolicy Bypass -File "%~dp0run_m0.ps1" -Only desktop,gamemode -Redo %*
|
||||
powershell -NoProfile -ExecutionPolicy Bypass -File "%~dp0run_m0.ps1" -Only gamemode -Redo %*
|
||||
echo.
|
||||
pause
|
||||
|
||||
Reference in New Issue
Block a user