mirror of
https://github.com/Niko1221/Strata.git
synced 2026-12-03 23:08:36 +00:00
launch, docker: --draft-vocab and DRAFT_VOCAB carry setup's draft vocabulary (#5786)
strata launch --draft-vocab cjk|en|cyrillic|fr|latin passes setup's choice of the draft tokens through; the preset and the flag summary keep it, the Mac setup step takes it, and without it nothing is passed (setup's own pick from the computer's languages stays). The Docker image passes DRAFTING and DRAFT_VOCAB to strata launch. Taken from the PR with its author; resolved against the current tree (its base still had DeepSeek's speed modes, which stay out) and completed: the list is setup.py's DRAFT_VOCABS with latin (the PR had four), pinned equal by a test; help and docs/DOCKER.md text as approved. Tests: tests/terminal/test_launch_draft_vocab.py (each name round-trips through the preset to setup's arguments, none passed by default, an unknown name refused, the entrypoint lines and the docs row), and an entrypoint run in tools/test_docker_entrypoint.py; with test_docker_files, test_launch and test_launch_tui 235 passed on p1004.
This commit is contained in:
1 parent
518cec958c
commit
ee70336055
7 files changed
+102
-2
No files matched your search
@@ -15,6 +15,8 @@
|
||||
# PARALLEL requests answered at the same time, 1 to 8 (empty: fit to the card)
|
||||
# VISION off | on | gpu | cpu (pictures; the picture reader file is downloaded with the model)
|
||||
# KV int8 | q4_0 | k8v4 | fp16 (conversation memory format)
|
||||
# DRAFTING auto | mtp | dflash2 | off (which drafter guesses ahead)
|
||||
# DRAFT_VOCAB cjk | en | cyrillic | fr | latin (which tokens the drafter may guess; every one but cjk keeps English and code)
|
||||
# GPU / GPUS card numbers, e.g. 0 or 0,1 (empty or "all": the engine's choice)
|
||||
# GPU_ROLES a role for each card, e.g. 1=main,0=helper (main, helper or off; cards you do not name are off; not together with GPU / GPUS)
|
||||
# TUNE quick | thorough | skip (done once; RETUNE=1 tunes again)
|
||||
@@ -232,6 +234,8 @@ if [ -n "$roles" ]; then
|
||||
set -- "$@" --gpu-roles "$roles"; have=1
|
||||
fi
|
||||
[ -n "${STRATA_SET:-}" ] && { for kv in $STRATA_SET; do set -- "$@" --set "$kv"; done; have=1; }
|
||||
[ -n "${DRAFTING:-}" ] && { set -- "$@" --drafting "$DRAFTING"; have=1; }
|
||||
[ -n "${DRAFT_VOCAB:-}" ] && { set -- "$@" --draft-vocab "$DRAFT_VOCAB"; have=1; }
|
||||
[ -n "$key" ] && { set -- "$@" --api-key-env STRATA_LAUNCH_KEY; }
|
||||
|
||||
# tune once: ask only when this preset has not been tuned yet (a restart must not tune again for 20 minutes)
|
||||
|
||||
@@ -120,6 +120,8 @@ screens; leave out what you do not care about.
|
||||
| `PARALLEL` | requests answered at the same time, 1 to 8 | fitted to the card |
|
||||
| `VISION` | `off`, `on` (the model reads pictures), `gpu`, `cpu`; the picture-reader file (about 0.9 GB) is downloaded with the model | `off` |
|
||||
| `KV` | conversation memory format: `int8`, `q4_0` (half the memory), `k8v4`, `fp16` | `int8` |
|
||||
| `DRAFTING` | which drafter guesses ahead: `auto`, `mtp`, `dflash2` or `off` | `auto` |
|
||||
| `DRAFT_VOCAB` | which tokens the drafter may guess: `cjk` (with Chinese, Japanese and Korean), `en`, `cyrillic`, `fr` or `latin` (each with English and code) | picked from the container's languages, else `cjk` |
|
||||
| `GPU` / `GPUS` | card numbers as the monitor lists them, `0` or `0,1`; empty or `all` = the engine's choice. Changing it later makes the model's run settings again (the files stay) | all that fit |
|
||||
| `GPU_ROLES` | a role for each card, `1=main,0=helper` (`main`, `helper`, `off`; cards you do not name are off; not together with `GPU` / `GPUS`). Passed to `launch --gpu-roles`; see [MULTI_GPU.md](MULTI_GPU.md) | none |
|
||||
| `TUNE` | `quick` (runtime depends on hardware and workload), `thorough`, `skip`; done once and kept in the preset (`RETUNE=1` tunes again) | `skip` |
|
||||
|
||||
@@ -102,6 +102,9 @@ def add_parsers(sp: argparse._SubParsersAction) -> list[argparse.ArgumentParser]
|
||||
help="which drafter guesses words ahead to make answers faster, one at a time: auto (recommended: DFlash2 for Qwen3.8-Flash-Next where the engine has it, "
|
||||
"else the MTP), mtp, dflash2 (downloads its drafter once, 0.3 to 1.2 GB depending on the model; the size is shown before the download) or off. Auto uses the MTP when several requests run at once; --drafting dflash2 runs with the --parallel count you set. "
|
||||
"If DFlash2 cannot run (on a model it is not for, for example) the MTP is used alone and the start says why")
|
||||
g.add_argument("--draft-vocab", type=_choice("a draft vocabulary", S.DRAFT_VOCAB_MODES), metavar="cjk|en|cyrillic|fr|latin",
|
||||
help="which tokens the drafter may guess: cjk (the default: with Chinese, Japanese and Korean), en (English and code), "
|
||||
"cyrillic, fr or latin (each with English and code). Without it Strata picks from this computer's languages")
|
||||
g.add_argument("--split-engine", type=_choice("a split-engine setting", S.SPLIT_MODES), metavar="auto|on|off",
|
||||
help="NVIDIA, two or more cards: the engine that splits every layer across the cards (faster answers). auto (the default) uses it by itself "
|
||||
"where it is supported and starts the normal layer split everywhere else; on asks for it and says in one line why it cannot run; "
|
||||
@@ -251,6 +254,8 @@ def settings_from_args(a: argparse.Namespace, catalog=None) -> tuple[S.LaunchSet
|
||||
s.mtp = a.mtp
|
||||
if a.drafting:
|
||||
s.drafting = a.drafting
|
||||
if a.draft_vocab:
|
||||
s.draft_vocab = a.draft_vocab
|
||||
if getattr(a, "split_engine", None):
|
||||
s.split_engine = a.split_engine
|
||||
if a.gpu and getattr(a, "gpu_roles", None):
|
||||
@@ -812,7 +817,8 @@ def run_launch(a: argparse.Namespace) -> int:
|
||||
notices.append(S.Notice("warn", backend_note, ""))
|
||||
if not machine:
|
||||
_interrupted_move_notice()
|
||||
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 or getattr(a, "split_engine", None))
|
||||
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 or a.draft_vocab or
|
||||
getattr(a, "split_engine", None))
|
||||
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
|
||||
|
||||
@@ -1127,6 +1127,8 @@ class Runner:
|
||||
args += ["--kv", s.kv]
|
||||
if fam in ("qwen", "coder"):
|
||||
args += ["--experimental-speed-projection", "off"]
|
||||
if s.draft_vocab and fam in modelstate.HELPER_FAMILIES:
|
||||
args += ["--draft-vocab", s.draft_vocab]
|
||||
layer_fetch = getattr(self, "_layer_fetch", False) # the start's safety net (fetch_missing_drafter): setup fetches the draft layer
|
||||
resolved = "mtp" if layer_fetch else self.resolved_drafting(fam)
|
||||
mtp_word = s.mtp if resolved != "off" else "off"
|
||||
@@ -1157,7 +1159,7 @@ class Runner:
|
||||
if sys.platform == "darwin":
|
||||
# a Mac's setup (Control mode, strata_control/mac_fit.py) takes fewer options (no --kv, --gpu, speed projection)
|
||||
keep = {"--yes", "--no-start", "--family", "--model", "--context", "--vision", "--data-dir", "--gguf-dir", "--move-data",
|
||||
"--set-default-data-dir", "--feed", "--drafter", "--mtp"} # --drafter / --mtp: setup.py's Mac step fetches the draft layer only where the
|
||||
"--set-default-data-dir", "--feed", "--drafter", "--mtp", "--draft-vocab"} # --drafter / --mtp: setup.py's Mac step fetches the draft layer only where the
|
||||
# start runs the MTP, and not after a Drafting Off (`--mtp off`)
|
||||
flags = ("--yes", "--no-start", "--move-data", "--set-default-data-dir")
|
||||
out, i = [], 0
|
||||
|
||||
@@ -30,6 +30,8 @@ MTP_MODES = ("on", "off")
|
||||
SPLIT_MODES = ("auto", "on", "off")
|
||||
#: strata_control/drafting.py MODES (tests/terminal/test_drafting.py keeps the two the same)
|
||||
DRAFTING_MODES = ("auto", "mtp", "dflash2", "off")
|
||||
#: setup.py DRAFT_VOCABS (tests/terminal/test_launch_draft_vocab.py keeps the two the same)
|
||||
DRAFT_VOCAB_MODES = ("cjk", "en", "cyrillic", "fr", "latin")
|
||||
KV_MODES = ("int8", "q4_0", "k8v4", "fp16")
|
||||
DEFAULT_PORT = 8080
|
||||
|
||||
@@ -94,6 +96,7 @@ class LaunchSettings:
|
||||
vision: str | None = None # None = the default (on when the model can read pictures and the engine has the reader), off | on | gpu | cpu
|
||||
parallel: int | None = None # None = fit to the card
|
||||
drafting: str | None = None # None = Auto (recommended): the table in strata_control/drafting.py; mtp | dflash2 | off choose one. Saved in the launch config
|
||||
draft_vocab: str | None = None # setup's token subset for the MTP/DFlash2 draft head
|
||||
split_engine: str | None = None # None = auto (the all-cards split engine runs by itself where it is supported); on | off. Saved in the preset and the launch config
|
||||
mtp: str | None = None # None = as installed (draft layer on); "off" starts without it (less graphics memory and RAM, slower); "on" overrides an installed "off"
|
||||
tune: str = "skip" # quick | thorough | skip
|
||||
@@ -309,6 +312,8 @@ def flags_text(s: LaunchSettings, *, preset: str | None = None) -> str:
|
||||
parts.append(f"--mtp {s.mtp}")
|
||||
if s.drafting:
|
||||
parts.append(f"--drafting {s.drafting}")
|
||||
if s.draft_vocab:
|
||||
parts.append(f"--draft-vocab {s.draft_vocab}")
|
||||
if s.split_engine:
|
||||
parts.append(f"--split-engine {s.split_engine}")
|
||||
parts.append(f"--tune {s.tune}")
|
||||
|
||||
@@ -0,0 +1,72 @@
|
||||
"""#5786 (LawiK974): strata launch --draft-vocab and the Docker image's DRAFT_VOCAB carry setup's draft vocabulary choice. One list: setup.py's
|
||||
DRAFT_VOCABS (cjk, en, cyrillic, fr, latin); an unknown name is refused before anything starts; a Qwen helper family passes it to setup, the
|
||||
preset keeps it, and without it nothing is passed (setup's own pick from the computer's languages stays)."""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
import argparse
|
||||
import ast
|
||||
import contextlib
|
||||
import io
|
||||
import unittest
|
||||
from pathlib import Path
|
||||
|
||||
from strata_cli.launch import cmd
|
||||
from strata_cli.launch import settings as S
|
||||
from strata_cli.launch.runner import Runner
|
||||
from tests.terminal.launch_support import HW_12, Home, catalog
|
||||
|
||||
ROOT = Path(__file__).resolve().parents[2]
|
||||
|
||||
|
||||
def setup_vocabs() -> list[str]:
|
||||
tree = ast.parse((ROOT / "setup.py").read_text(encoding="utf-8"))
|
||||
for node in tree.body:
|
||||
if isinstance(node, ast.Assign) and any(isinstance(t, ast.Name) and t.id == "DRAFT_VOCABS" for t in node.targets):
|
||||
return [k.value for k in node.value.keys]
|
||||
raise AssertionError("setup.py has no DRAFT_VOCABS")
|
||||
|
||||
|
||||
def parse(*argv):
|
||||
ap = argparse.ArgumentParser()
|
||||
cmd.add_parsers(ap.add_subparsers(dest="command"))
|
||||
return ap.parse_args(["launch", *argv])
|
||||
|
||||
|
||||
class DraftVocab(unittest.TestCase):
|
||||
def test_the_launch_list_is_setups_list(self):
|
||||
self.assertEqual(list(S.DRAFT_VOCAB_MODES), setup_vocabs())
|
||||
|
||||
def test_every_name_reaches_setup_and_the_preset_keeps_it(self):
|
||||
for name in S.DRAFT_VOCAB_MODES:
|
||||
with self.subTest(name=name), Home():
|
||||
s, _ = cmd.settings_from_args(parse("--model", "IQ3_XXS", "--draft-vocab", name), catalog=catalog(HW_12))
|
||||
self.assertEqual(s.draft_vocab, name)
|
||||
again = S.LaunchSettings.from_dict(s.to_dict())
|
||||
self.assertEqual(again.draft_vocab, name)
|
||||
args = Runner(again.copy(family="qwen", context=32768, kv="q4_0", vision="off"), catalog=catalog(HW_12)).setup_args()
|
||||
self.assertEqual(args[args.index("--draft-vocab") + 1], name)
|
||||
self.assertIn(f"--draft-vocab {name}", S.flags_text(again))
|
||||
|
||||
def test_without_it_nothing_is_passed(self):
|
||||
with Home():
|
||||
args = Runner(S.LaunchSettings(family="qwen", model="IQ3_XXS", context=32768, kv="q4_0", vision="off"), catalog=catalog(HW_12)).setup_args()
|
||||
self.assertNotIn("--draft-vocab", args)
|
||||
|
||||
def test_an_unknown_name_is_refused(self):
|
||||
err = io.StringIO()
|
||||
with contextlib.redirect_stderr(err), self.assertRaises(SystemExit):
|
||||
parse("--draft-vocab", "klingon")
|
||||
self.assertIn("klingon", err.getvalue())
|
||||
|
||||
def test_the_docker_entrypoint_passes_both_settings(self):
|
||||
text = (ROOT / "docker" / "entrypoint.sh").read_text(encoding="utf-8")
|
||||
self.assertIn('[ -n "${DRAFT_VOCAB:-}" ] && { set -- "$@" --draft-vocab "$DRAFT_VOCAB"; have=1; }', text)
|
||||
self.assertIn('[ -n "${DRAFTING:-}" ] && { set -- "$@" --drafting "$DRAFTING"; have=1; }', text)
|
||||
docs = (ROOT / "docs" / "DOCKER.md").read_text(encoding="utf-8")
|
||||
for name in S.DRAFT_VOCAB_MODES:
|
||||
self.assertIn(f"`{name}`", docs.split("| `DRAFT_VOCAB` |", 1)[1].split("\n", 1)[0])
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
unittest.main()
|
||||
@@ -97,6 +97,15 @@ class Entrypoint(unittest.TestCase):
|
||||
self.assertIn("launch --stop --preset office", self.log.read_text())
|
||||
self.assertIn("stopped", self.log.read_text())
|
||||
|
||||
def test_drafting_and_draft_vocab_become_flags(self):
|
||||
"""#5786: DRAFTING and DRAFT_VOCAB reach strata launch as --drafting / --draft-vocab."""
|
||||
p = self.start(MODEL="IQ3_XXS", DRAFTING="dflash2", DRAFT_VOCAB="latin")
|
||||
line = self.launch_line(self.wait_for("--show-key"))
|
||||
self.assertIn("--drafting dflash2", line)
|
||||
self.assertIn("--draft-vocab latin", line)
|
||||
code, _out, err = self.stop(p)
|
||||
self.assertEqual(code, 0, err)
|
||||
|
||||
def test_saved_preset_is_reused_and_a_tuned_one_is_not_tuned_again(self):
|
||||
p = self.start(STUB_PRESET="1", STUB_TUNED="tuned 2026-10-17", TUNE="quick", MODEL="Q2_0")
|
||||
line = self.launch_line(self.wait_for("--show-key"))
|
||||
|
||||
Reference in new issue
Block a user