--no-browser (on a start or at setup) saves "open_browser": false in the model's run config; start() and run-<model>.bat/.sh then leave --open out, and the server ignores --open when the config says so (a start script written earlier still has it). --browser undoes it. Without the flag the config, the command and the script are as before.
This commit is contained in:
1 parent
e294e0109b
commit
9b6515b37c
6 files changed
+92
-14
No files matched your search
@@ -191,6 +191,8 @@ START-HERE.bat --port 8081 another port
|
||||
START-HERE.bat --gpu 1 another GPU (setup picks the one with the most VRAM)
|
||||
START-HERE.bat --gpus 0,2 several GPUs sharing the model
|
||||
START-HERE.bat --vram-reserve-mib 2048 leave 2 GB of VRAM free for other programs (remembered)
|
||||
START-HERE.bat --no-browser do not open the chat page when the model is ready (remembered;
|
||||
--browser undoes it)
|
||||
START-HERE.bat --setup --backend hip the AMD engine on a PC that also has an NVIDIA card
|
||||
START-HERE.bat --setup --host 0.0.0.0 --api-key <secret> reachable from other devices, with a key
|
||||
START-HERE.bat --calibrate tune the engine for this PC (about 5-10 minutes), then start
|
||||
|
||||
+2
-2
@@ -3027,8 +3027,8 @@ def main() -> int:
|
||||
"in an admin PowerShell:\n New-NetFirewallRule -DisplayName \"Strata " + str(a.port) + "\" "
|
||||
"-Direction Inbound -Protocol TCP -LocalPort " + str(a.port) + " -Action Allow -Profile Private\n"
|
||||
" (and set this network to Private in Windows' network settings)", flush=True)
|
||||
if a.open:
|
||||
import webbrowser
|
||||
if a.open and cfg.get("open_browser") is not False: # #609: the config's "open_browser": false wins (an older
|
||||
import webbrowser # run-<model>.bat still passes --open)
|
||||
webbrowser.open(f"http://{'127.0.0.1' if a.host in ('0.0.0.0', '') else a.host}:{a.port}/")
|
||||
# #96: docker stop sends SIGTERM, which Python ignores by default, so the container's PID 1 would be killed after
|
||||
# the grace period with the engine still running. SIGTERM takes Ctrl+C's path below (QUIT to the engine).
|
||||
|
||||
@@ -2682,6 +2682,8 @@ def settings_summary(cfg: dict, port=None) -> str:
|
||||
srv = [f"{cfg.get('host', '127.0.0.1')}:{port or cfg.get('port', 8080)}"]
|
||||
if cfg.get("api_key"):
|
||||
srv.append("api key set")
|
||||
if cfg.get("open_browser") is False: # #609
|
||||
srv.append("no browser")
|
||||
for k in ("gpu", "layer_split", "draft_vocab", "fit_max_tokens", "reasoning_budget_tokens", "anthropic_thinking"):
|
||||
if cfg.get(k) is not None:
|
||||
v = cfg[k]
|
||||
@@ -2710,8 +2712,9 @@ def start(cfg_path: Path, port: int | None, gpu: int | list | None = None, open_
|
||||
if keep and any(cfg.get(k) != v for k, v in keep.items()): # #179: a --host/--api-key on a start was ignored
|
||||
cfg.update(keep)
|
||||
write_config(cfg_path, cfg)
|
||||
ok("saved for this model: " + ", ".join("api key" if k == "api_key" else f"{k.replace('_', ' ')} {v}"
|
||||
for k, v in keep.items()))
|
||||
ok("saved for this model: " + ", ".join(
|
||||
"api key" if k == "api_key" else ("the browser opens" if v else "no browser") if k == "open_browser"
|
||||
else f"{k.replace('_', ' ')} {v}" for k, v in keep.items()))
|
||||
cfg_path.touch() # the most recently used model
|
||||
if "--mtp" in cfg["args"][:-1]:
|
||||
refresh_draft_vocab(Path(cfg["args"][cfg["args"].index("--mtp") + 1]), cfg.get("draft_vocab", "cjk"))
|
||||
@@ -2779,7 +2782,8 @@ def start(cfg_path: Path, port: int | None, gpu: int | list | None = None, open_
|
||||
if g is not None:
|
||||
cfg = ensure_engine_for([g], cfg_path, cfg, yes)
|
||||
ok("GPU: " + gpu_name(g))
|
||||
if open_browser:
|
||||
browser = open_browser and cfg.get("open_browser") is not False # #609: "open_browser": false, --no-browser
|
||||
if browser:
|
||||
cmd.append("--open")
|
||||
gb = 0.0
|
||||
if "--native" in cfg["args"]:
|
||||
@@ -2799,7 +2803,8 @@ def start(cfg_path: Path, port: int | None, gpu: int | list | None = None, open_
|
||||
say(f" Starting {cfg.get('model_name', 'the model')}: it loads {size} into RAM and locks part of it for the "
|
||||
"GPU.")
|
||||
say(" While it does, YOUR PC CAN BE SLOW OR STOP RESPONDING FOR 1-3 MINUTES (longer the first time after a")
|
||||
say(" restart). That is normal: please wait and don't close this window - the browser opens when it is ready.")
|
||||
say(" restart). That is normal: please wait and don't close this window - " + (
|
||||
"the browser opens when it is ready." if browser else "the server says when it is ready."))
|
||||
say(" Later, closing this window stops the model.")
|
||||
say(" " + "-" * 100)
|
||||
for n, line in enumerate(textwrap.wrap(f"Settings ({cfg_path.name}): {settings_summary(cfg, port)}", 100,
|
||||
@@ -2944,9 +2949,10 @@ def ensure_engine_for(cards, cfg_path: Path, cfg: dict, yes: bool) -> dict:
|
||||
return cfg
|
||||
|
||||
|
||||
def write_run_script(model, cfg_path, port):
|
||||
def write_run_script(model, cfg_path, port, open_browser=True):
|
||||
"""run-<model>.bat / .sh: the server with this config; `open_browser` False (#609: --no-browser) leaves --open out."""
|
||||
serve = [sys.executable, str(ROOT / "serve" / "server.py"), "--engine", "strata", "--config", str(cfg_path),
|
||||
"--port", str(port), "--open"]
|
||||
"--port", str(port)] + (["--open"] if open_browser else [])
|
||||
if WIN:
|
||||
script = ROOT / f"run-{model.lower()}.bat"
|
||||
script.write_text("@echo off\r\ntitle Strata " + model + "\r\ncd /d \"" + str(ROOT) + "\"\r\n" +
|
||||
@@ -3028,6 +3034,11 @@ def main() -> int:
|
||||
ap.add_argument("--host", help="where the server listens: 127.0.0.1 = this PC only (default), 0.0.0.0 = also other "
|
||||
"devices on your network (issue #26; set --api-key too)")
|
||||
ap.add_argument("--api-key", help="require this key from clients (recommended with --host 0.0.0.0)")
|
||||
ap.add_argument("--no-browser", dest="browser", action="store_false", default=None,
|
||||
help="do not open the chat page in the browser when the model is ready (for a harness or an app "
|
||||
"that uses the API; remembered for this model, also in run-<model>.bat/.sh)")
|
||||
ap.add_argument("--browser", dest="browser", action="store_true",
|
||||
help="open the chat page again when the model is ready (the default; undoes --no-browser)")
|
||||
ap.add_argument("--data-dir", help="where the model files go (~70-120 GB): default Strata-data next to this folder, "
|
||||
"remembered for every Strata folder on this PC")
|
||||
ap.add_argument("--models-dir", help="where the GGUF files go (default: <data folder>/models)")
|
||||
@@ -3134,14 +3145,14 @@ def main() -> int:
|
||||
+ ("keeps" if a.no_start else "starts with") + " the default settings")
|
||||
return 0 if a.no_start else start(pick_cfg, a.port, run_gpu, yes=a.yes, layer_split=a.layer_split,
|
||||
keep={"host": a.host, "api_key": a.api_key, "draft_vocab": a.draft_vocab,
|
||||
"vram_reserve_mib": a.vram_reserve_mib})
|
||||
"vram_reserve_mib": a.vram_reserve_mib, "open_browser": a.browser})
|
||||
if have and not (a.setup or a.model or a.family or a.check or a.no_start):
|
||||
if not a.build:
|
||||
update_installed_engine(a.prebuilt)
|
||||
if len(have) == 1:
|
||||
return start(have[0], a.port, run_gpu, yes=a.yes, layer_split=a.layer_split,
|
||||
keep={"host": a.host, "api_key": a.api_key, "draft_vocab": a.draft_vocab,
|
||||
"vram_reserve_mib": a.vram_reserve_mib})
|
||||
"vram_reserve_mib": a.vram_reserve_mib, "open_browser": a.browser})
|
||||
say()
|
||||
for i, c in enumerate(have, 1):
|
||||
say(f" {i}) {json.loads(c.read_text(encoding='utf-8-sig')).get('model_name', c.stem)}")
|
||||
@@ -3150,7 +3161,7 @@ def main() -> int:
|
||||
if pick <= len(have):
|
||||
return start(have[pick - 1], a.port, run_gpu, yes=a.yes, layer_split=a.layer_split,
|
||||
keep={"host": a.host, "api_key": a.api_key, "draft_vocab": a.draft_vocab,
|
||||
"vram_reserve_mib": a.vram_reserve_mib})
|
||||
"vram_reserve_mib": a.vram_reserve_mib, "open_browser": a.browser})
|
||||
|
||||
# ---- 1. the PC
|
||||
step(1, "checking your PC")
|
||||
@@ -3734,6 +3745,8 @@ def main() -> int:
|
||||
cfg["api_key"] = a.api_key
|
||||
if draft_vocab:
|
||||
cfg["draft_vocab"] = draft_vocab
|
||||
if a.browser is not None: # #609: only when given (else an earlier choice is carried over)
|
||||
cfg["open_browser"] = a.browser
|
||||
if vision != "none":
|
||||
cfg["vision"] = {"exe": str(eng / VEXE), "mmproj": str(mmproj), "model": str(shards[0]),
|
||||
"gpu": vision == "gpu", "max_tokens": VISION[vision]["max_tokens"]}
|
||||
@@ -3747,7 +3760,7 @@ def main() -> int:
|
||||
cfg["args"] = CAL.apply(cfg["args"], cal.get("settings") or {})
|
||||
ok("the settings tuned for this PC earlier are used" + (f" ({cal['date']})" if cal.get("date") else ""))
|
||||
write_setup_config(cfg_path, cfg, adopted if adopted is not None and adopted.name == cfg_path.name else None)
|
||||
script = write_run_script(tag, cfg_path, port)
|
||||
script = write_run_script(tag, cfg_path, port, cfg.get("open_browser") is not False)
|
||||
# offered only when someone answers: --yes installs and adopted earlier installs are not held up by it
|
||||
if cal is None and not hip and not a.no_start and not a.yes and ask(
|
||||
"Tune Strata for this PC now? It measures a few engine settings (about 5-10 minutes; the PC is busy "
|
||||
|
||||
@@ -11,6 +11,7 @@ import json
|
||||
import sys
|
||||
import tempfile
|
||||
import unittest
|
||||
import unittest.mock
|
||||
from pathlib import Path
|
||||
|
||||
ROOT = Path(__file__).resolve().parents[1]
|
||||
@@ -131,5 +132,67 @@ class CarryOver(unittest.TestCase):
|
||||
self.assertFalse((Path(d) / "strata-x.json.bak").exists()) # nothing here was replaced
|
||||
|
||||
|
||||
class NoBrowser(unittest.TestCase):
|
||||
"""#609 (#631): --no-browser keeps the chat page from opening: "open_browser": false in the run config, no --open
|
||||
on the start's server command or in run-<model>.bat/.sh. Without the flag nothing changes."""
|
||||
|
||||
def setUp(self):
|
||||
self.ram, self.found = PROFILES["64GB-1x32GB"]
|
||||
|
||||
def run_setup(self, *extra, configs=()):
|
||||
return install(self.ram, self.found, ["--family", "qwen", "--model", "Q2_0", "--no-start", *extra],
|
||||
configs=configs)
|
||||
|
||||
def test_at_setup(self):
|
||||
code, out, cfg, _ = self.run_setup("--no-browser")
|
||||
self.assertEqual(code, 0, out)
|
||||
self.assertIs(cfg["open_browser"], False)
|
||||
code, out, cfg, _ = self.run_setup()
|
||||
self.assertNotIn("open_browser", cfg) # not given: the config as before
|
||||
# setup run again without the flag keeps the choice (#629); --browser undoes it
|
||||
code, out, cfg, _ = self.run_setup(configs=[("strata-q2_0.json", {"open_browser": False})])
|
||||
self.assertIs(cfg["open_browser"], False)
|
||||
code, out, cfg, _ = self.run_setup("--browser", configs=[("strata-q2_0.json", {"open_browser": False})])
|
||||
self.assertIs(cfg["open_browser"], True)
|
||||
|
||||
def test_run_script(self):
|
||||
with tempfile.TemporaryDirectory() as d, unittest.mock.patch.object(setup, "ROOT", Path(d)):
|
||||
text = lambda p: p.read_text(encoding="utf-8") # noqa: E731
|
||||
self.assertIn('"--open"', text(setup.write_run_script("Q2_0", Path(d) / "strata-q2_0.json", 8080)))
|
||||
script = setup.write_run_script("Q2_0", Path(d) / "strata-q2_0.json", 8080, False)
|
||||
self.assertNotIn("--open", text(script))
|
||||
self.assertIn('"--port" "8080"', text(script))
|
||||
|
||||
def start_cmd(self, cfg, keep=None):
|
||||
with tempfile.TemporaryDirectory() as d:
|
||||
exe = Path(d) / "strata.exe"
|
||||
exe.write_bytes(b"")
|
||||
p = Path(d) / "strata-q2_0.json"
|
||||
p.write_text(json.dumps({"exe": str(exe), "args": ["--kv", "int8"], "gpu": 0, "gpus_asked": True, **cfg}))
|
||||
call = unittest.mock.Mock(return_value=0)
|
||||
with unittest.mock.patch.object(setup, "gpus", lambda: self.found), \
|
||||
unittest.mock.patch.object(setup, "is_wsl", lambda: False), \
|
||||
unittest.mock.patch.object(setup, "ensure_engine_for", lambda cards, path, c, yes: c), \
|
||||
unittest.mock.patch.object(setup.subprocess, "call", call):
|
||||
_, out = quiet(setup.start, p, None, None, True, True, None, keep)
|
||||
return call.call_args[0][0], out, json.loads(p.read_text())
|
||||
|
||||
def test_on_a_start(self):
|
||||
cmd, out, _ = self.start_cmd({})
|
||||
self.assertIn("--open", cmd) # the default, as before
|
||||
self.assertIn("the browser opens when it is ready", out)
|
||||
cmd, out, _ = self.start_cmd({"open_browser": False})
|
||||
self.assertNotIn("--open", cmd)
|
||||
self.assertNotIn("the browser opens", out)
|
||||
self.assertIn("no browser", out) # the Settings line says so
|
||||
cmd, out, saved = self.start_cmd({}, {"open_browser": False}) # START-HERE --no-browser: kept from now on
|
||||
self.assertNotIn("--open", cmd)
|
||||
self.assertIs(saved["open_browser"], False)
|
||||
self.assertIn("saved for this model: no browser", out)
|
||||
cmd, out, saved = self.start_cmd({"open_browser": False}, {"open_browser": True})
|
||||
self.assertIn("--open", cmd)
|
||||
self.assertIs(saved["open_browser"], True)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
unittest.main()
|
||||
@@ -113,7 +113,7 @@ def install(ram, found, argv, answers=None, extra=(), avx512=False, configs=()):
|
||||
mock.patch.object(setup, "run", lambda *a, **k: None),
|
||||
mock.patch.object(setup, "mtp_corrupt", lambda *a, **k: False),
|
||||
mock.patch.object(setup, "refresh_draft_vocab", lambda *a, **k: None),
|
||||
mock.patch.object(setup, "write_run_script", lambda tag, cfg, port: t / f"run-{tag}.bat"),
|
||||
mock.patch.object(setup, "write_run_script", lambda tag, cfg, port, *_: t / f"run-{tag}.bat"),
|
||||
mock.patch.object(setup, "saved_calibration", lambda cfg: None),
|
||||
mock.patch.object(setup, "calibrate_config", mock.Mock(side_effect=AssertionError("calibrated"))),
|
||||
mock.patch.dict(sys.modules, {"gguf_reader": types.SimpleNamespace(GGUFFile=FakeGGUF)}),
|
||||
|
||||
@@ -174,7 +174,7 @@ class Main(unittest.TestCase):
|
||||
mock.patch.object(setup, "verify_sha256", lambda s, size, sha: self.verified.append((s.name, size, sha))),
|
||||
mock.patch.object(setup, "run", fake_run),
|
||||
mock.patch.object(setup, "refresh_draft_vocab", lambda *a, **k: None),
|
||||
mock.patch.object(setup, "write_run_script", lambda tag, cfg, port: self.t / f"start-{tag}.bat"),
|
||||
mock.patch.object(setup, "write_run_script", lambda tag, cfg, port, *_: self.t / f"start-{tag}.bat"),
|
||||
mock.patch.object(setup, "saved_calibration", lambda cfg: None),
|
||||
mock.patch.object(setup, "start", mock.Mock(side_effect=AssertionError("started"))),
|
||||
mock.patch.dict(sys.modules, {"gguf_reader": types.SimpleNamespace(GGUFFile=FakeGGUF)}),
|
||||
|
||||
Reference in new issue
Block a user