Merge f-024-rel into f-024-tui
This commit is contained in:
commit
f4e7685ccf
44 files changed
+3711
-159
No files matched your search
@@ -148,8 +148,14 @@ class Ctx:
|
||||
tuned_args, tuned_env = list(merged.get("args") or []), dict(merged.get("env") or {})
|
||||
except Exception: # noqa: BLE001
|
||||
pass
|
||||
exe = self.engine_exe()
|
||||
text = P.engine_help_text(exe) if exe else None
|
||||
if (cfg or {}).get("arch") == "deepseek41" or self.settings.family == "deepseek41": # DeepSeek runs strata-dsv41: its settings, not the Qwen engine's
|
||||
own = (cfg or {}).get("exe")
|
||||
exe = own if own and Path(str(own)).is_file() else None
|
||||
text = P.dsv41_help_text(exe)
|
||||
exe = exe or "static"
|
||||
else:
|
||||
exe = self.engine_exe()
|
||||
text = P.engine_help_text(exe) if exe else None
|
||||
if exe and text:
|
||||
self.engine_flags = sorted({p.name for p in P.parse_help(text)})
|
||||
self.engine_note = ""
|
||||
|
||||
@@ -72,6 +72,8 @@ def verdict(on_this_pc: str | None) -> tuple[str, str]:
|
||||
return TIGHT, "not checked (this computer's memory could not be read)"
|
||||
if low.startswith("does not fit"):
|
||||
return NO, "too big (can still try)"
|
||||
if "free disk space" in low: # DeepSeek: fits in memory, not on the disk (still allowed)
|
||||
return TIGHT, "tight: needs more disk space"
|
||||
if "low-ram mode" in low:
|
||||
return FITS, "fits, a bit slower"
|
||||
if "part of its experts" in low or "read from the ssd" in low:
|
||||
|
||||
@@ -84,6 +84,8 @@ def add_parsers(sp: argparse._SubParsersAction) -> list[argparse.ArgumentParser]
|
||||
g.add_argument("--preset", metavar="NAME", help="start a saved preset (other flags change it for this start)")
|
||||
g.add_argument("--model", metavar="NAME", help="the model size, e.g. iq3_xxs, q2_0, ud-q4_k_xl (any case)")
|
||||
g.add_argument("--family", metavar="NAME", help="the model family when a size is offered by several (qwen, swift, coder, ...)")
|
||||
g.add_argument("--dsv41-package", metavar="FILE", help="DeepSeek: the engine package you downloaded from the release page (.tar.gz or .zip); "
|
||||
"it is checked and installed instead of being fetched")
|
||||
g.add_argument("--model-path", metavar="PATH", help="use model files you already have: a folder of shards or one .gguf file")
|
||||
g.add_argument("--data-dir", metavar="DIR", help="where downloaded model files are stored (default: Strata's data folder)")
|
||||
g.add_argument("--move-data", action="store_true",
|
||||
@@ -199,6 +201,8 @@ def settings_from_args(a: argparse.Namespace, catalog=None) -> tuple[S.LaunchSet
|
||||
s = store.load(a.preset) if a.preset else S.LaunchSettings()
|
||||
if a.preset:
|
||||
s.name = s.name or a.preset
|
||||
if getattr(a, "dsv41_package", None):
|
||||
s.dsv41_package = str(Path(a.dsv41_package).expanduser())
|
||||
if a.model_path:
|
||||
s.model_path = str(Path(a.model_path).expanduser())
|
||||
if not a.model:
|
||||
@@ -531,6 +535,22 @@ def open_page(url: str) -> bool:
|
||||
return False
|
||||
|
||||
|
||||
def _screens_missing() -> str | None:
|
||||
"""The Python package the screens need that this install lacks ("rich" / "textual"), None when both are there. A source install made before
|
||||
setup installed them has neither: `strata launch` then goes on in plain lines instead of stopping with a traceback."""
|
||||
import importlib.util
|
||||
return next((m for m in ("rich", "textual") if importlib.util.find_spec(m) is None), None)
|
||||
|
||||
|
||||
def final_hint_lines(s, preset_saved: bool) -> list[str]:
|
||||
"""The last lines of a flag launch: how to connect an app and how to stop. `--preset "<name>"` is suggested only when a preset by that name exists
|
||||
(--preset NAME, or --save-preset NAME); otherwise the plain command, and how to keep the settings."""
|
||||
if preset_saved:
|
||||
return [f" Connect an app: strata connect opencode Stop: strata launch --stop --preset \"{s.name}\""]
|
||||
return [" Connect an app: strata connect opencode Stop: strata launch --stop",
|
||||
" To keep these settings for next time, add --save-preset NAME."]
|
||||
|
||||
|
||||
def _tui(run, *args, **kw) -> int:
|
||||
"""Open the screens. An error of the screens themselves ends with a plain sentence and a non-zero exit code, never a traceback and exit 0
|
||||
(tester report T02)."""
|
||||
@@ -668,14 +688,21 @@ def run_launch(a: argparse.Namespace) -> int:
|
||||
have_choices = bool(a.preset or a.model or a.model_path or a.context or a.vision or a.parallel or a.access or a.tune or a.drafting)
|
||||
interactive = sys.stdin.isatty() and sys.stdout.isatty() and not a.no_tui and not machine and not a.plan
|
||||
plain_questions = False
|
||||
no_screens_package = None
|
||||
if interactive and _screens_missing():
|
||||
no_screens_package = _screens_missing()
|
||||
interactive = False
|
||||
_say(f"The screens need a Python package this install does not have yet ({no_screens_package}), so Strata goes on in plain lines. "
|
||||
"Run setup again (START-HERE / ./setup.sh) to get the screens.")
|
||||
if not have_choices and not interactive and not a.plan:
|
||||
if machine or a.no_tui or catalog is None or not _can_ask(): # --no-tui never asks (round 8, M)
|
||||
return fail("`strata launch` with no choices opens screens, and this is not a terminal (or --no-tui was given). Name what to start: --preset NAME, or --model NAME "
|
||||
"(strata launch --help has examples; --plan shows what would happen without changing anything).", 2)
|
||||
# Git Bash, mintty and some editor panels cannot show the screens although a person is typing: go on in plain lines, and ask first
|
||||
plain_questions = True
|
||||
_say("This window cannot show Strata's screens (Git Bash and similar windows do not pass the keyboard through). "
|
||||
"For the screens, open Windows Terminal, PowerShell or cmd, or run `winpty strata launch`. Going on with plain questions.")
|
||||
if no_screens_package is None:
|
||||
_say("This window cannot show Strata's screens (Git Bash and similar windows do not pass the keyboard through). "
|
||||
"For the screens, open Windows Terminal, PowerShell or cmd, or run `winpty strata launch`. Going on with plain questions.")
|
||||
if interactive and not have_choices:
|
||||
if catalog is None:
|
||||
return fail("This Terminal does not carry the model list, so the screens cannot open. Install it again with the one-line installer.", 5)
|
||||
@@ -786,7 +813,8 @@ def run_launch(a: argparse.Namespace) -> int:
|
||||
_say(f" {'Anthropic apps':<14} {result.urls[0]} (Claude Code: ANTHROPIC_BASE_URL, no /v1 at the end)")
|
||||
if result.key:
|
||||
from strata_cli.launch import access
|
||||
_say(f" {'API key':<14} {access.mask_key(result.key)} (show it: strata launch --show-key --preset \"{s.name}\")")
|
||||
_say(f" {'API key':<14} {access.mask_key(result.key)} (show it: strata launch --show-key"
|
||||
+ (f" --preset \"{s.name}\")" if (a.preset or a.save_preset) else ")"))
|
||||
for n in result.notices:
|
||||
_say(f"[!] {n}")
|
||||
local = next((u for u in result.urls if "127.0.0.1" in u), result.urls[0] if result.urls else "")
|
||||
@@ -798,7 +826,8 @@ def run_launch(a: argparse.Namespace) -> int:
|
||||
_say(f" Watch it: STRATA_API_KEY=$(strata launch --show-key) strata monitor --url {local} --credential-env STRATA_API_KEY")
|
||||
else:
|
||||
_say(f" Watch it: strata monitor --url {local}")
|
||||
_say(f" Connect an app: strata connect opencode Stop: strata launch --stop --preset \"{s.name}\"")
|
||||
for line in final_hint_lines(s, bool(a.preset or a.save_preset)):
|
||||
_say(line)
|
||||
return 0
|
||||
except store.PresetError as e:
|
||||
return fail(str(e), 2)
|
||||
|
||||
@@ -212,6 +212,45 @@ def flag_list(engine: str | Path | None) -> list[str] | None:
|
||||
return None
|
||||
|
||||
|
||||
#: strata-dsv41's settings in plain words (its own --help is one bracketed usage line, which the Qwen engine's list parser cannot read).
|
||||
DSV41_FLAGS = {
|
||||
"--pack": ("DIR", "The folder with the model's prepared data."),
|
||||
"--max-context": ("N", "How much text the model remembers at once."),
|
||||
"--eos": ("ID", "The token that ends an answer (1 for DeepSeek)."),
|
||||
"--dspark": ("on|off|none|auto", "The DSpark drafter that guesses ahead to speed up answers (auto loads it only where it helps)."),
|
||||
"--dspark-conf": ("F", "How sure a DSpark guess must be to be used (0 to 1)."),
|
||||
"--dspark-block": ("N", "The most words DSpark guesses in one round."),
|
||||
"--expert-profile": ("FILE|none", "A table of which experts are used most, to decide what is kept in memory first."),
|
||||
"--ssd-cache": ("GB", "How much RAM keeps the most used experts so they are not read from the SSD again (sizes itself when absent)."),
|
||||
"--ssd-policy": ("lru|lfu|lfulru", "Which experts the RAM store drops first."),
|
||||
"--prefill-chunk": ("N", "How many prompt words are read at once (the fast prompt path)."),
|
||||
"--threads": ("on|off", "Read long prompts layer by layer on all CPU threads."),
|
||||
"--cpu-threads": ("N", "How many CPU threads compute the experts the graphics card does not hold."),
|
||||
"--tp": ("N", "Share each layer between this many graphics cards."),
|
||||
"--gpus": ("LIST", "Which graphics cards to use together."),
|
||||
"--reserve-mib": ("N", "Graphics memory (in MiB) kept free for other programs."),
|
||||
"--vram-experts": ("F", "How many experts to keep in graphics memory."),
|
||||
"--mmap-experts": ("on|off|auto", "Read the experts in place from the model's files."),
|
||||
"--no-expert-cache": ("", "Do not keep the most used experts in graphics memory."),
|
||||
"--vision": ("on|off", "Let the model read pictures."),
|
||||
"--verbose": ("", "Print more about what the engine does."),
|
||||
}
|
||||
|
||||
|
||||
def dsv41_help_text(engine: str | Path | None) -> str:
|
||||
"""A list of strata-dsv41's settings the Advanced screen can read: ours in plain words, plus any flag its own --help names that we do not
|
||||
describe. Works before the engine is installed too (the plain words are static)."""
|
||||
lines = [f" {flag} {meta} {desc}" if meta else f" {flag} {desc}" for flag, (meta, desc) in DSV41_FLAGS.items()]
|
||||
if engine:
|
||||
import subprocess
|
||||
try:
|
||||
proc = subprocess.run([str(engine), "--help"], capture_output=True, text=True, timeout=20)
|
||||
seen = set(re.findall(r"--[a-z][a-z0-9-]*", (proc.stdout or "") + " " + (proc.stderr or "")))
|
||||
lines += [f" {f} An engine setting (the engine's help has no sentence for it)." for f in sorted(seen) if f not in DSV41_FLAGS]
|
||||
except Exception: # noqa: BLE001 - the static list stands
|
||||
pass
|
||||
return "\n".join(lines) + "\n"
|
||||
|
||||
def engine_help_text(engine: str | Path | None) -> str | None:
|
||||
if not engine:
|
||||
return None
|
||||
|
||||
+65
-11
@@ -739,6 +739,8 @@ class Runner:
|
||||
if s.model_path:
|
||||
p = Path(s.model_path)
|
||||
args += ["--gguf-dir", str(p if p.is_dir() else p.parent)]
|
||||
if s.dsv41_package and s.family == "deepseek41":
|
||||
args += ["--dsv41-package", s.dsv41_package]
|
||||
if s.gpu_roles:
|
||||
args += ["--gpu-roles", ",".join(f"{k}={v}" for k, v in sorted(s.gpu_roles.items(), key=lambda kv: int(kv[0])))]
|
||||
elif s.gpus:
|
||||
@@ -1263,7 +1265,8 @@ class Runner:
|
||||
mode = "thorough" if s.tune == "thorough" else "quick"
|
||||
argv = [sys.executable, str(Path(__file__).resolve().parents[2] / "tools" / "dsv41" / "tune.py"), "--config", str(cfg), "--mode", mode,
|
||||
"--output", "json"]
|
||||
self.emit("tune", "Tuning DeepSeek for the best speed: a few short test runs (1-3 minutes each). Close other heavy programs.", 0)
|
||||
self.emit("tune", "Tuning DeepSeek: it times a short question with your standard settings, then with the DSpark drafter on (and, if that helps, a shorter "
|
||||
"draft block) and the CPU threads set to your physical cores; each run loads the model once. It keeps only a clear gain. Close other heavy programs.", 0)
|
||||
try:
|
||||
p = self._spawn(argv)
|
||||
except Exception as e: # noqa: BLE001 - a tune never stops a launch
|
||||
@@ -1828,21 +1831,54 @@ class Runner:
|
||||
except Exception: # noqa: BLE001
|
||||
return ""
|
||||
|
||||
def dsv41_engine(self) -> bool | None:
|
||||
"""Whether the installed engine carries strata-dsv41 (True / False); None when no engine is installed yet or it cannot be told."""
|
||||
def dsv41_engine_found(self) -> tuple[Path | None, bool | None]:
|
||||
"""(strata-dsv41 already installed, or None; whether the engine can be told at all). Looks where setup puts DeepSeek's own engine package
|
||||
(engine-dsv41/ beside the engine, in Strata's own folder, and in the data folder), and at STRATA_DSV41_EXE (a build of your own)."""
|
||||
from strata_control import dsv41_engine
|
||||
own = (os.environ.get("STRATA_DSV41_EXE") or "").strip()
|
||||
if own:
|
||||
return Path(own).is_file()
|
||||
return (Path(own) if Path(own).is_file() else None), True
|
||||
folders: list[Path] = []
|
||||
try:
|
||||
from strata_control import engine_component as ec
|
||||
rep = ec.status()
|
||||
exe = (rep.get("engine") or {}).get("exe") if rep.get("usable") else None
|
||||
if not exe:
|
||||
return None
|
||||
folder = Path(str(exe)).parent
|
||||
return any((d / n).is_file() for d in (folder, folder.parent / "engine-dsv41") for n in ("strata-dsv41", "strata-dsv41.exe"))
|
||||
if exe:
|
||||
folder = Path(str(exe)).parent
|
||||
folders += [folder.parent / dsv41_engine.DIR]
|
||||
try:
|
||||
folders.append(self.catalog.strata.setup_module().dsv41_engine_dir(folder))
|
||||
except Exception: # noqa: BLE001
|
||||
pass
|
||||
known = True
|
||||
else:
|
||||
known = None
|
||||
except Exception: # noqa: BLE001
|
||||
return None
|
||||
known = None
|
||||
try: # where the setup this Terminal runs puts it (its own engine folder, or Strata's folder)
|
||||
mod = self.catalog.strata.setup_module()
|
||||
folders += [Path(self.catalog.root) / dsv41_engine.DIR, # setup runs here in the app's installer mode: its home() is this folder
|
||||
mod.dsv41_engine_dir(Path(mod.ROOT) / "engine"), Path(mod.home()) / dsv41_engine.DIR]
|
||||
except Exception: # noqa: BLE001
|
||||
pass
|
||||
try:
|
||||
folders.append((Path(self.s.data_dir) if self.s.data_dir else self.catalog.data_dir()) / dsv41_engine.DIR)
|
||||
except Exception: # noqa: BLE001
|
||||
pass
|
||||
for f in folders:
|
||||
found = dsv41_engine.find(f)
|
||||
if found is not None:
|
||||
return found, True
|
||||
for f in folders[:1]: # the engine's own folder: an all-in-one package carries it
|
||||
for n in ("strata-dsv41", "strata-dsv41.exe"):
|
||||
if (f.parent / n).is_file():
|
||||
return f.parent / n, True
|
||||
return None, known
|
||||
|
||||
def dsv41_engine(self) -> bool | None:
|
||||
"""Whether the installed engine carries strata-dsv41 (True / False); None when no engine is installed yet or it cannot be told."""
|
||||
found, known = self.dsv41_engine_found()
|
||||
return True if found is not None else (False if known else None)
|
||||
|
||||
def placement(self) -> dict:
|
||||
"""Where DeepSeek-V4.1-Flash would go on this computer's cards (strata_control/dsv41_fit.py): the cards this launch names, else every
|
||||
@@ -1856,7 +1892,11 @@ class Runner:
|
||||
free = None
|
||||
p = self.catalog.strata.dsv41_plan(hw, free, s.gpus, model=s.model)
|
||||
warnings = list(p["warnings"])
|
||||
engine = self.dsv41_engine()
|
||||
found, known = self.dsv41_engine_found()
|
||||
engine = True if found is not None else (False if known else None)
|
||||
if found is not None:
|
||||
ver = next((part for part in (found.parent.name.split("-")[0], ) if part[:1].isdigit()), "")
|
||||
p["lines"].append("DeepSeek engine: installed" + (f", {ver}" if ver else "") + ".")
|
||||
if engine is False:
|
||||
warnings.append("DeepSeek runs on its own engine package (about 70 MB, separate from the Strata engine): setup downloads it first. "
|
||||
"If it cannot be fetched, setup stops with a message before the model is downloaded.")
|
||||
@@ -1927,6 +1967,11 @@ def _read_json(path: Path) -> dict | None:
|
||||
#: lines of an engine log that say why it stopped (the last one wins), and a plain next step for the causes we know. Recommend, never force.
|
||||
CAUSE_LINE = re.compile(r"error|exception|failed|cannot|can't|could not|no device|not found|out of memory|unsupported|abort|invalid|missing|"
|
||||
r"no kernel|illegal|denied|refus", re.I)
|
||||
# The GPU runtime (ROCm) failed while the card was being set up, often right after another engine exited: the runtime's own text
|
||||
# ("terminate called after throwing an instance of 'rocr::AMD::hsa_exception'") stays in the log, not in the sentence shown.
|
||||
HSA_START = re.compile(r"hsa_exception|HSA_STATUS_ERROR", re.I)
|
||||
HSA_START_NEXT = ("The graphics card was not ready yet; wait a few seconds and run it again. If it keeps happening, restart the PC "
|
||||
"and report the log.")
|
||||
KNOWN_CAUSES = (
|
||||
(re.compile(r"no device of requested type|device not found|no (gpu|sycl|level.zero) device|permission denied.*(dri|render)", re.I),
|
||||
"The engine could not open the graphics card. On Linux the account must be allowed to use it: add it to the render group "
|
||||
@@ -2005,10 +2050,19 @@ def explain_engine_exit(result: dict, config: Path | None, marks: dict | None =
|
||||
stage = "The engine stopped while it was loading the model" + (f" (exit code {code})" if code not in (None, 0) else "")
|
||||
else:
|
||||
stage = f"The server did not become ready ({state}: {why or 'see the engine log'})"
|
||||
hsa = HSA_START.search(" ".join(lines + [str(why or "")])) # the runtime's own text is kept out of the sentence (it is in the log)
|
||||
if hsa:
|
||||
# a real cause in the same log (out of memory, no permission on the card ...) wins: its line is the cause shown
|
||||
real = next((x for x in reversed(lines) if any(p.search(x) for p, _ in KNOWN_CAUSES)), None)
|
||||
if real:
|
||||
hsa = None
|
||||
cause = re.sub(r"^(\[strata\]\s*)?(\d{4}-\d\d-\d\d[ T][\d:.]+\s*)?", "", real.strip())[:240]
|
||||
else:
|
||||
cause = ""
|
||||
text = stage + (f": {cause}" if cause else ".")
|
||||
if not text.endswith((".", "!")):
|
||||
text += "."
|
||||
step = next((words for pattern, words in KNOWN_CAUSES if pattern.search(" ".join([cause, str(why or "")]))), "Run it again; if it repeats, report the log.")
|
||||
step = HSA_START_NEXT if hsa else next((words for pattern, words in KNOWN_CAUSES if pattern.search(" ".join([cause, str(why or "")]))), "Run it again; if it repeats, report the log.")
|
||||
return text, step + (f" The engine's log: {log}" if log else " The engine's log has the reason (strata logs, or the log named in the run config).")
|
||||
|
||||
|
||||
|
||||
@@ -1041,9 +1041,15 @@ class TuningScreen(Base):
|
||||
def on_mount(self) -> None:
|
||||
s = self.ctx.settings
|
||||
first = self.ctx.fresh_setup and not s.is_tuned
|
||||
items = [Item(["Quick", "about 20 minutes", "checks the most likely gains" + ("; suggested the first time" if first else "")], key="quick"),
|
||||
Item(["Thorough", "up to 2 hours", "tries more settings, measures each one several times"], key="thorough"),
|
||||
Item(["Skip", "", "use the default settings (already good on most computers)"], key="skip")]
|
||||
if s.family == "deepseek41": # DeepSeek's own short tune (tools/dsv41/tune.py): its real length and what it tries
|
||||
items = [Item(["Quick", "about 5-10 minutes", "tries the DSpark drafter on or off, a shorter draft block and the CPU threads; keeps only clear gains"
|
||||
+ ("; suggested the first time" if first else "")], key="quick"),
|
||||
Item(["Thorough", "about 10-15 minutes", "also tries every CPU thread"], key="thorough"),
|
||||
Item(["Skip", "", "use the default settings (already good on most computers)"], key="skip")]
|
||||
else:
|
||||
items = [Item(["Quick", "about 20 minutes", "checks the most likely gains" + ("; suggested the first time" if first else "")], key="quick"),
|
||||
Item(["Thorough", "up to 2 hours", "tries more settings, measures each one several times"], key="thorough"),
|
||||
Item(["Skip", "", "use the default settings (already good on most computers)"], key="skip")]
|
||||
if not self.ctx.tune_chosen and s.tune == "skip" and not s.is_tuned and self.ctx.fresh_setup:
|
||||
s.tune = "quick"
|
||||
self.query_one(Menu).set_items(items, {"quick": 0, "thorough": 1, "skip": 2}.get(s.tune, 0))
|
||||
|
||||
@@ -82,6 +82,7 @@ class LaunchSettings:
|
||||
family: str | None = None # catalog family id (qwen, swift, coder, unsloth, gyro, nvfp4...)
|
||||
model: str | None = None # catalog size (IQ3_XXS ...)
|
||||
model_path: str | None = None # "Use model files I already have": a .gguf file or a folder
|
||||
dsv41_package: str | None = None # DeepSeek: the engine package the person downloaded by hand (checked, then installed)
|
||||
data_dir: str | None = None # where model files are stored (None: the Strata default)
|
||||
gpus: list[int] | None = None # None = the engine's choice (all usable cards)
|
||||
gpu_roles: dict[str, str] | None = None # {"1": "main", "0": "helper", "2": "off"}: a role for every card; None = the recommendation
|
||||
|
||||
Reference in new issue
Block a user