bench: the server the bench starts runs without --expert-profile-save, so it never saves a profile learned from its short prompts over the user's (#2088)
This commit is contained in:
1 parent
4468e0e62c
commit
017a672ae1
2 files changed
+58
No files matched your search
@@ -656,7 +656,35 @@ def is_strata(base: str, key: str) -> bool:
|
||||
return bool(h and h.get("service") == "strata")
|
||||
|
||||
|
||||
def without_profile_save(cfg: dict) -> tuple[dict, bool]:
|
||||
"""#2088: the config without `--expert-profile-save FILE` (and its value) - the engine writes that profile when the
|
||||
server quits, and a benchmark's short prompts must not replace the user's calibrated one. -> (config, removed)."""
|
||||
args = list(cfg.get("args") or [])
|
||||
out, i, removed = [], 0, False
|
||||
while i < len(args):
|
||||
if args[i] == "--expert-profile-save":
|
||||
i, removed = i + 2, True
|
||||
elif isinstance(args[i], str) and args[i].startswith("--expert-profile-save="):
|
||||
i, removed = i + 1, True
|
||||
else:
|
||||
out.append(args[i])
|
||||
i += 1
|
||||
return ({**cfg, "args": out} if removed else cfg), removed
|
||||
|
||||
|
||||
def start_server(cfg_path: Path, port: int, gpu: str | None, log_path: Path):
|
||||
try:
|
||||
cfg = json.loads(cfg_path.read_text(encoding="utf-8-sig"))
|
||||
except (OSError, ValueError):
|
||||
cfg = None
|
||||
if isinstance(cfg, dict):
|
||||
safe, removed = without_profile_save(cfg)
|
||||
if removed: # a copy beside the log: the user's config file is not touched
|
||||
print("Note: the bench starts this model without --expert-profile-save, so its short prompts do not "
|
||||
"overwrite your saved expert profile.", file=sys.stderr)
|
||||
tmp = log_path.with_suffix(".config.json")
|
||||
tmp.write_text(json.dumps(safe), encoding="utf-8")
|
||||
cfg_path = tmp
|
||||
cmd = [sys.executable, str(ROOT / "serve" / "server.py"), "--engine", "strata", "--config", str(cfg_path), "--port", str(port)]
|
||||
if gpu:
|
||||
cmd += ["--gpu", gpu]
|
||||
|
||||
@@ -2,6 +2,8 @@
|
||||
writing and the comparison. Light: no GPU, no Strata server, a few seconds."""
|
||||
from __future__ import annotations
|
||||
|
||||
import contextlib
|
||||
import io
|
||||
import json
|
||||
import os
|
||||
import sys
|
||||
@@ -296,6 +298,34 @@ class ReportTests(unittest.TestCase):
|
||||
m = B.collect_machine(srv.base, "", {"backend": "sycl"})
|
||||
self.assertEqual((m["gpu"], m["cuda"]), (["Intel Arc Pro B70"], None))
|
||||
|
||||
def test_a_bench_server_never_saves_over_the_users_profile(self):
|
||||
"""#2088: --expert-profile-save writes the profile at quit; the bench's own server runs without it."""
|
||||
cfg = {"args": ["--expert-profile", "p.bin", "--expert-profile-save", "p.bin", "--spec", "4"]}
|
||||
safe, removed = B.without_profile_save(cfg)
|
||||
self.assertTrue(removed)
|
||||
self.assertEqual(safe["args"], ["--expert-profile", "p.bin", "--spec", "4"])
|
||||
self.assertEqual(cfg["args"][3], "p.bin") # the input is not changed
|
||||
safe, removed = B.without_profile_save({"args": ["--expert-profile-save=p.bin", "--spec", "4"]})
|
||||
self.assertEqual((safe["args"], removed), (["--spec", "4"], True))
|
||||
same = {"args": ["--spec", "4"]}
|
||||
self.assertEqual(B.without_profile_save(same), (same, False))
|
||||
with tempfile.TemporaryDirectory(ignore_cleanup_errors=True) as d:
|
||||
c = Path(d) / "strata-x.json"
|
||||
c.write_text(json.dumps(cfg))
|
||||
with mock.patch.object(B.subprocess, "Popen") as popen, contextlib.redirect_stderr(io.StringIO()):
|
||||
B.start_server(c, 8080, None, Path(d) / "run.log")
|
||||
used = Path(popen.call_args[0][0][popen.call_args[0][0].index("--config") + 1])
|
||||
self.assertNotIn("--expert-profile-save", json.loads(used.read_text())["args"])
|
||||
self.assertIn("--expert-profile-save", json.loads(c.read_text())["args"]) # the user's file is as it was
|
||||
|
||||
def test_an_attached_server_is_not_stopped(self):
|
||||
"""#2088: with --url the bench only reads; the server it did not start keeps running."""
|
||||
srv = FakeStrata()
|
||||
self.addCleanup(srv.stop)
|
||||
with tempfile.TemporaryDirectory() as d, mock.patch.object(B, "stop_server") as stop:
|
||||
self.assertEqual(self.run_main(srv, d), 0)
|
||||
stop.assert_not_called()
|
||||
|
||||
def test_names(self):
|
||||
m = {"gpu": ["NVIDIA GeForce RTX 3060"], "model": "Qwen3.8 Flash-Next", "quant": "IQ3_XXS"}
|
||||
self.assertEqual(B.results_dir_name(m, "2026-10-10"), "2026-10-10-community-rtx-3060-qwen3-8-flash-next-iq3-xxs")
|
||||
|
||||
Reference in new issue
Block a user