mirror of
https://github.com/Niko1221/Strata.git
synced 2026-12-05 15:58:53 +00:00
drafting plan: say what parallel slots draft, as the server does
The Terminal plan line (strata launch --plan) and `strata drafting plan` now show "Drafting: none in parallel slots (one token per request and step); a single request still drafts" for request slots that draft nothing, the same sentence the server prints. decide() takes a slots_none flag; the two plan builders pass it from the config's arguments (user_args merged) and the request count. Where the request count is not known (no number of requests given), the plan keeps its old line.
This commit is contained in:
1 parent
e17d7a8282
commit
f4accc5f41
4 files changed
+62
-7
No files matched your search
@@ -130,7 +130,8 @@ def _inputs(a) -> dict:
|
||||
slot_drafts = drafting.slot_drafts_by_default(mode, backend=backend, archs=archs, vram_mib=sig.get("vram_mib"), args=sig.get("args"), slots=parallel) # the drafter is fetched before the start
|
||||
return {"mode": mode, "klass": drafting.card_class(archs), "model_name": model_name, "family": a.family, "data_dir": data,
|
||||
"backend": backend, "archs": archs, "mtp_here": drafting.mtp_ready(args) if cfg else None,
|
||||
"blocked": drafting.blocked_by(args, slots=parallel, named=drafting.normalize(mode) == "dflash2", backend=backend, slot_drafts=slot_drafts)}
|
||||
"blocked": drafting.blocked_by(args, slots=parallel, named=drafting.normalize(mode) == "dflash2", backend=backend, slot_drafts=slot_drafts),
|
||||
"slots_none": drafting.slots_draft_nothing(drafting.merged_args(cfg), parallel)} # (False when the request count is not in the config: today's line)
|
||||
|
||||
|
||||
def _signals(a, want: dict) -> dict:
|
||||
|
||||
@@ -1532,7 +1532,8 @@ class Runner:
|
||||
return {"mode": mode, "klass": drafting.card_class(archs), "model_name": name, "family": self.s.family,
|
||||
"data_dir": drafting.data_dir_of(args) or (Path(self.s.data_dir) if self.s.data_dir else None),
|
||||
"backend": backend, "archs": archs, "mtp_here": drafting.mtp_ready(args) if cfg else None,
|
||||
"blocked": drafting.blocked_by(args, split=split, slots=int(self.s.parallel or 0), named=drafting.normalize(mode) == "dflash2", backend=backend, slot_drafts=slot_drafts)}
|
||||
"blocked": drafting.blocked_by(args, split=split, slots=int(self.s.parallel or 0), named=drafting.normalize(mode) == "dflash2", backend=backend, slot_drafts=slot_drafts),
|
||||
"slots_none": drafting.slots_draft_nothing(drafting.merged_args(cfg), int(self.s.parallel or 0))}
|
||||
|
||||
def drafting_signals(self, cfg: dict, want: dict) -> dict:
|
||||
"""The two signals drafting.tuned_applies reads besides the backend and the card: the arguments (--expert-cache and the others the confidence reads, with the person's own
|
||||
|
||||
@@ -854,6 +854,15 @@ def line(drafter: str, reason: str = "") -> str:
|
||||
return f"Drafting: {word} ({reason})" if reason else f"Drafting: {word}"
|
||||
|
||||
|
||||
def merged_args(cfg: dict[str, Any]) -> list[str]:
|
||||
"""The config's engine arguments with the person's own ``user_args`` over them, as the server merges them at a start (what slots_draft_nothing reads)."""
|
||||
args = [str(a) for a in cfg.get("args") or []]
|
||||
if cfg.get("user_args"):
|
||||
from strata_control import user_args
|
||||
args = user_args.merge(args, cfg["user_args"])
|
||||
return args
|
||||
|
||||
|
||||
def slots_draft_nothing(args: list[Any], slots: int | float | None = 0) -> bool:
|
||||
"""Do this start's request slots draft nothing? Yes for 2 or more requests at once with no ``--batch-mtp`` (and no ``STRATA_BATCH_MTP``, no ``--pipeline-windows``) in the arguments:
|
||||
the engine runs the slots with one token per request and step, and only a single request drafts. (Called for a start that runs the MTP layer: the slots' own DFlash2 drafts are
|
||||
@@ -1380,8 +1389,9 @@ def choice_of(mode: Any, *, model_name: str | None = None, family: str | None =
|
||||
|
||||
def decide(mode: Any, *, klass: str = "other", model_name: str | None = None, family: str | None = None, data_dir: str | Path | None = None,
|
||||
backend: str | None = None, archs: Any = None, mtp_here: bool | None = None, blocked: bool = False, vocab_here: bool = True,
|
||||
args: list[Any] | None = None, vram_mib: float | None = None) -> Decision:
|
||||
"""The drafter a start uses. Never raises. One drafter, never two. A choice that cannot be applied becomes the other drafter when that one is on this computer,
|
||||
args: list[Any] | None = None, vram_mib: float | None = None, slots_none: bool = False) -> Decision:
|
||||
"""The drafter a start uses. Never raises. ``slots_none`` (slots_draft_nothing of the start's arguments and request count; False when the caller cannot know it): the reason for a
|
||||
DFlash2 that is not available here is NONE_IN_SLOTS instead of NOT_HERE, so the plan says what the server says. One drafter, never two. A choice that cannot be applied becomes the other drafter when that one is on this computer,
|
||||
else none, with a note in plain words. ``mtp_here`` says whether the MTP layer is on disk (None: not known, taken as there), ``blocked`` that this start is a layer
|
||||
split or has several requests at once (see blocked_by), ``vocab_here`` that the draft vocabulary DFlash2 needs is there. ``klass`` is not used any more (Auto
|
||||
does not depend on the kind of card) and stays only so the callers keep working."""
|
||||
@@ -1395,6 +1405,8 @@ def decide(mode: Any, *, klass: str = "other", model_name: str | None = None, fa
|
||||
|
||||
if want == "dflash2":
|
||||
reason = NOT_HERE if (blocked or not vocab_here) else NOT_DOWNLOADED if not drafter_ready(data_dir, model_name, backend) else ""
|
||||
if reason == NOT_HERE and slots_none:
|
||||
reason = NONE_IN_SLOTS
|
||||
if not reason:
|
||||
return Decision(asked, "dflash2", flags=engine_flags(pack_path(data_dir)))
|
||||
return Decision(asked, "mtp", reason) if have_mtp else Decision(asked, "off", NONE_HERE)
|
||||
@@ -1556,9 +1568,8 @@ def apply(cfg: dict[str, Any], *, klass: str = "other", data_dir: str | Path | N
|
||||
drafter_here=vocab is not None and form != FORM_NONE and drafter_ready(data_dir, name, backend))
|
||||
decision = decide(mode, model_name=name, family=family, data_dir=data_dir, backend=backend, archs=archs,
|
||||
mtp_here=mtp_here, blocked=blocked_by(strip_draft_flags(args), split=split, slots=slots, named=normalize(mode) == "dflash2", backend=backend, slot_drafts=slot_drafts) or form == FORM_NONE,
|
||||
vocab_here=vocab is not None, args=strip_mtp_flags(strip_draft_flags(args)), vram_mib=vram_mib)
|
||||
if decision.drafter == "mtp" and decision.note == NOT_HERE and slots_draft_nothing(args, slots):
|
||||
decision.note = NONE_IN_SLOTS # request slots with no --batch-mtp draft nothing: say that, not "DFlash2 isn't available in this mode" (MTP slot drafts keep that line)
|
||||
vocab_here=vocab is not None, args=strip_mtp_flags(strip_draft_flags(args)), vram_mib=vram_mib,
|
||||
slots_none=slots_draft_nothing(args, slots)) # request slots with no --batch-mtp draft nothing: say that, not "DFlash2 isn't available in this mode" (MTP slot drafts keep that line)
|
||||
mine = cfg.get("user_args") or []
|
||||
pack = None
|
||||
if decision.drafter == "dflash2":
|
||||
|
||||
@@ -249,6 +249,48 @@ class TheStart(unittest.TestCase):
|
||||
self.assertEqual((d.drafter, d.note), ("mtp", drafting.NOT_HERE))
|
||||
self.assertIn("--batch-mtp", c["args"])
|
||||
|
||||
def plan_by_command(self, parallel, args=None, **env) -> str:
|
||||
"""The plan line `strata drafting plan` shows for this config (strata_cli/drafting_cmd.py: _inputs, then decide)."""
|
||||
from strata_cli import drafting_cmd
|
||||
cfg = {**self.cfg(), **({} if parallel is None else {"parallel": parallel}), "args": list(args if args is not None else self.args)}
|
||||
path = self.data / "plan.json"
|
||||
path.write_text(__import__("json").dumps(cfg), encoding="utf-8")
|
||||
a = SimpleNamespace(config=str(path), data_dir=str(self.data), mode=None, family="qwen", model=None, no_split=True, engines_unloading=False, drafting_command="plan")
|
||||
with mock.patch.object(drafting, "card_vram_mib", return_value=PRO5000), mock.patch.object(drafting_cmd, "_hardware", return_value=("cuda", ["sm_120"])), \
|
||||
mock.patch.object(drafting_cmd, "_split_expected", return_value=False), mock.patch.dict(os.environ, env):
|
||||
want = drafting_cmd._inputs(a)
|
||||
sig = drafting_cmd._signals(a, want)
|
||||
return drafting.summary_line(drafting.decide(**want, **sig))
|
||||
|
||||
def plan_by_launch(self, parallel, args=None, **env) -> str:
|
||||
"""The plan line the Terminal's `strata launch --plan` shows (runner.drafting_plan_line) for an installed config like this one."""
|
||||
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
|
||||
cfg = {**self.cfg(), "args": list(args if args is not None else self.args)}
|
||||
with Home():
|
||||
runner = Runner(S.LaunchSettings(family="qwen", model="IQ3_S", context=32768, vision="off", parallel=parallel), catalog=catalog(HW_12))
|
||||
runner._split_expected = False
|
||||
with mock.patch.object(Runner, "installed_state", return_value=(None, cfg)), mock.patch.object(drafting, "detect_hardware", return_value=("cuda", ["sm_120"])), \
|
||||
mock.patch.object(drafting, "card_vram_mib", return_value=PRO5000), mock.patch.object(drafting, "data_dir_of", return_value=self.data), mock.patch.dict(os.environ, env):
|
||||
return runner.drafting_plan_line()
|
||||
|
||||
def test_the_plan_line_says_what_the_server_says(self):
|
||||
self.pack()
|
||||
none = "Drafting: none in parallel slots (one token per request and step); a single request still drafts"
|
||||
mtp_slots = "Drafting: MTP (DFlash2 isn't available in this mode)"
|
||||
for how in (self.plan_by_command, self.plan_by_launch):
|
||||
name = how.__name__
|
||||
self.assertEqual(how(2), "Drafting: DFlash2", (name, "2 requests on the measured class: DFlash2 slot drafts"))
|
||||
self.assertEqual(how(3), none, (name, "slots with no drafts"))
|
||||
self.assertEqual(how(2, STRATA_BATCH_DF2="0"), none, (name, "the way back from the slot drafts"))
|
||||
self.assertEqual(how(3, args=[*self.args, "--batch-mtp"]), mtp_slots, (name, "MTP slot drafts keep their line"))
|
||||
self.assertEqual(how(3, STRATA_BATCH_MTP="1"), mtp_slots, (name, "MTP slot drafts through the environment"))
|
||||
self.assertEqual(how(1), "Drafting: DFlash2", (name, "one request at a time"))
|
||||
self.assertEqual(how(None), "Drafting: DFlash2", (name, "the number of requests is not known: today's line"))
|
||||
# the plan and the server print the same words in the same case
|
||||
self.assertEqual("[strata] " + self.plan_by_command(3), self.lines(self.cfg(parallel=3))[0])
|
||||
|
||||
def test_the_plan_agrees_with_the_start(self):
|
||||
from strata_cli import drafting_cmd
|
||||
self.pack()
|
||||
|
||||
Reference in new issue
Block a user