From b2360bb3d30bfb5cd3a1fcba99d45d65b9a9bc44 Mon Sep 17 00:00:00 2001 From: Niko1221 Date: Wed, 2 Dec 2026 21:39:47 +0100 Subject: [PATCH] ling32 launcher: --mtp auto (the default; the engine decides at start, --mtp-auto FILE), the status line from measured keys, and the prompt chunk by card size MTP auto (L32-CUDA fe96b81b73: --mtp-auto FILE --spec mtp --spec-adaptive; `mtp_auto=1` in --info --kv; serve INFO has h2d_gbps and spec=off|mtp): - ling32_family: MTP_MODES auto/on/off, DEFAULT_MTP_MODE, MTP_AUTO_MIN_LINK_GBPS (32), the run-config keys ling32_mtp_mode ("auto" also when absent, or "on") and ling32_plan_tier. - serve/ling32_kind: mode on = --mtp FILE; auto = --mtp-auto FILE when the engine says mtp_auto=1; an engine that cannot decide gets the sidecar only in tier A, on a Mac, or when the config was written before the word (forced then); stats_view adds h2d_gbps, mtp.mode and mtp.line ("MTP: on (auto: link 46 GB/s)", "MTP: off (auto: 24 GB/s link: no gain)", built from spec and the measured link only). - ling32_fit: mtp_mode(), mtp_status_line(), MTP_AUTO_NOTE; plan(mtp="auto") counts the sidecar in tier A and in one memory pool and not in tier B or C (a tier B plan carries one note). - setup.py / launcher: --mtp auto|on|off (nothing = auto; a card of 12 GB or less still off by default), the config gets the mode and the plan's tier; settings register and docs; the mock engine says mtp_auto=1 / h2d_gbps when asked. - Tests for the flags (auto, on, an old engine, a hand-written --mtp-auto), the planner, the status line, the launcher and setup. Prompt chunk (L32-CUDA, RTX 5090 tier B: --chunk 256 made a 4062-token prefill 33 % and a 32K one 115 % slower than the engine's default): chunk_for is 256 under 16 GB, 1024 from 16 to 30 GB (to be measured on a 24 GB card), the engine's own 2048 from 30 to 48 GB, 1024 above (the static layout). --- docs/SETTINGS.md | 9 ++- terminal/data/settings-register.json | 45 ++++++++++-- terminal/serve/ling32_kind.py | 54 ++++++++++++-- terminal/serve/server.py | 4 +- terminal/serve/test_ling32_mtp.py | 72 ++++++++++++++++++- terminal/setup.py | 18 +++-- terminal/strata_cli/launch/cmd.py | 4 +- terminal/strata_cli/launch/runner.py | 9 ++- terminal/strata_cli/launch/settings.py | 8 ++- terminal/strata_control/ling32_family.py | 6 +- terminal/strata_control/ling32_fit.py | 51 ++++++++++++- terminal/tests/terminal/test_ling32_fit.py | 44 ++++++++++++ terminal/tests/terminal/test_ling32_launch.py | 16 +++++ terminal/tools/ling32_mock_engine.py | 7 +- terminal/tools/test_setup_ling32.py | 10 ++- tools/test_settings_register.py | 2 +- 16 files changed, 319 insertions(+), 40 deletions(-) diff --git a/docs/SETTINGS.md b/docs/SETTINGS.md index 1c83d68fc2..a73cad7768 100644 --- a/docs/SETTINGS.md +++ b/docs/SETTINGS.md @@ -636,7 +636,7 @@ version made it the default. | `STRATA_WDDM_SHARED_RESERVE_MIB` | number | NVIDIA and AMD | v0.2.17 | - | | `STRATA_XN_F16` | on / off | NVIDIA and AMD | v0.2.16 | [DETAILS.md](DETAILS.md) | -## Ling-3.2-Air options (23) +## Ling-3.2-Air options (26) These are command-line options and variables of `strata launch` and setup, not engine variables. Nothing here is on unless you ask, except the thinking default (off) and the memory tier (chosen for your computer when you say `auto`). @@ -660,10 +660,13 @@ except the thinking default (off) and the memory tier (chosen for your computer | `--vision FILE` | the Vision shard the engine reads pictures with; setup writes it, serve takes it out when the engine does not say images=1 | engine-flag | default | | `--vision-device auto/cpu/gpu` | where the picture encoder runs (auto: the card from 24 GiB of device memory, the processor below); written only when --vision gpu/cpu is given | engine-flag | opt-in | | `--probe-cap` | asked once by setup on a Windows integrated GPU (Strix Halo): the engine allocates 1 GiB pieces until the driver refuses and frees them (a few seconds); the answer, gpu_alloc_cap_gib, is the cap the plan follows (card budget = min(free, cap - 4 GiB), RAM tier = available RAM - 9.5 GiB) | engine-flag | default | -| `--mtp on/off` | the MTP sidecar (Ling-3.2-Air-MTP.strata, in the default download set, MIT): the model's own multi-token-prediction layer drafts several tokens per step and the model checks them in one pass, so the answers are the same. On by default in every tier when the sidecar is there, EXCEPT on a discrete card of 12 GB or less, where the file takes room the expert pool needs: off by default there, not downloaded, not counted by the planner (a machine with one shared memory pool, such as a Strix, a Spark or a Mac, keeps it on). `--mtp on` forces it, `--mtp off` always turns it off | launcher-flag | default | -| `ling32_mtp (run config key)` | the sidecar's path in the run config; serve makes `--mtp FILE --spec mtp --spec-adaptive` from it at the start. Not kept in the arguments, because Control reads `--mtp ` as Flash-Next's draft layer | launcher-flag | default | +| `--mtp auto/on/off` | the MTP sidecar (Ling-3.2-Air-MTP.strata, in the default download set, MIT): the model's own multi-token-prediction layer drafts several tokens per step and the model checks them in one pass, so the answers are the same. auto (the default): the ENGINE decides at start whether the sidecar pays here (`--mtp-auto`): loaded when the whole model is on the card or in one memory pool, never in tier C, and in tier B only over a host-to-device link of 32 GB/s or more (it measures the link); the status line says which it chose. EXCEPT on a discrete card of 12 GB or less, where the file takes room the expert pool needs: off by default there, not downloaded, not counted by the planner. `--mtp on` forces it, `--mtp off` always turns it off | launcher-flag | default | +| `ling32_mtp (run config key)` | the sidecar's path in the run config; serve makes `--mtp FILE` (forced) or `--mtp-auto FILE` (the engine decides) plus `--spec mtp --spec-adaptive` from it at the start. Not kept in the arguments, because Control reads `--mtp ` as Flash-Next's draft layer | launcher-flag | default | +| `ling32_mtp_mode (run config key)` | the word next to the sidecar's path: `auto` (the engine decides at start) or `on` (forced); no path = off | launcher-flag | default | +| `ling32_plan_tier (run config key)` | the tier the launcher's plan gave: what `auto` does with an engine that cannot decide by itself (no mtp_auto=1 in its --info --kv line): the sidecar only in tier A or on one memory pool | launcher-flag | opt-in | | `ling32_spec_block (run config key)` | a ceiling for the adaptive K (the engine's default, the one measured, is 4) | launcher-flag | opt-in | | `--mtp FILE --spec mtp --spec-adaptive [--spec-block K]` | the engine's flags for the sidecar, written by serve at the start only when the file is there and the engine says mtp=1 in `--info FILE --kv`; INFO then says spec=mtp, STAT carries spec_accept, tok_per_verify and spec_k | engine-flag | default | +| `--mtp-auto FILE --spec mtp --spec-adaptive` | the engine decides about the sidecar after its memory plan: tier A or one memory pool loads it, tier C never, tier B only over a measured host-to-device link of 32 GB/s or more (`tier store: host-to-device link moved N GB/s`); written by serve only when the engine says mtp_auto=1 in `--info FILE --kv`; the serve INFO line then carries h2d_gbps and spec=off/mtp | engine-flag | default | | `--graph (AMD fast path)` | the AMD (HIP, Windows and Linux) engine gets only --graph besides --ctx and --chunk: the NVIDIA-tuned --tc / --tc-moe / --mla-kernel are not repeated, the engine's own choice for AMD is the measured one | engine-flag | default | | `--mtp FILE --spec mtp (Mac)` | the Metal engine takes the MTP sidecar like the CUDA and HIP ones since its command line was aligned (L32-METAL f9fbc1d186): --mtp FILE --spec mtp --spec-adaptive, only when its --info FILE --kv says mtp=1; a Mac keeps the whole model in memory: no tiers, no pictures | engine-flag | default | diff --git a/terminal/data/settings-register.json b/terminal/data/settings-register.json index a8293878e9..e07bfdf9b4 100644 --- a/terminal/data/settings-register.json +++ b/terminal/data/settings-register.json @@ -66714,12 +66714,12 @@ } }, { - "name": "--mtp on/off", + "name": "--mtp auto/on/off", "kind": "launcher-flag", "family": "ling-3.2-air", "status": "default", - "default": "on, except off on a discrete card of 12 GB or less", - "note": "the MTP sidecar (Ling-3.2-Air-MTP.strata, in the default download set, MIT): the model's own multi-token-prediction layer drafts several tokens per step and the model checks them in one pass, so the answers are the same. On by default in every tier when the sidecar is there, EXCEPT on a discrete card of 12 GB or less, where the file takes room the expert pool needs: off by default there, not downloaded, not counted by the planner (a machine with one shared memory pool, such as a Strix, a Spark or a Mac, keeps it on). `--mtp on` forces it, `--mtp off` always turns it off", + "default": "auto, except off on a discrete card of 12 GB or less", + "note": "the MTP sidecar (Ling-3.2-Air-MTP.strata, in the default download set, MIT): the model's own multi-token-prediction layer drafts several tokens per step and the model checks them in one pass, so the answers are the same. auto (the default): the ENGINE decides at start whether the sidecar pays here (`--mtp-auto`): loaded when the whole model is on the card or in one memory pool, never in tier C, and in tier B only over a host-to-device link of 32 GB/s or more (it measures the link); the status line says which it chose. EXCEPT on a discrete card of 12 GB or less, where the file takes room the expert pool needs: off by default there, not downloaded, not counted by the planner. `--mtp on` forces it, `--mtp off` always turns it off", "where": { "terminal/strata_cli/launch/cmd.py": "its MTP sidecar", "terminal/strata_control/ling32_family.py": "DEFAULT_MTP = True" @@ -66730,13 +66730,37 @@ "kind": "launcher-flag", "family": "ling-3.2-air", "status": "default", - "default": "the sidecar's path when MTP is on", - "note": "the sidecar's path in the run config; serve makes `--mtp FILE --spec mtp --spec-adaptive` from it at the start. Not kept in the arguments, because Control reads `--mtp ` as Flash-Next's draft layer", + "default": "the sidecar's path when MTP is auto or on", + "note": "the sidecar's path in the run config; serve makes `--mtp FILE` (forced) or `--mtp-auto FILE` (the engine decides) plus `--spec mtp --spec-adaptive` from it at the start. Not kept in the arguments, because Control reads `--mtp ` as Flash-Next's draft layer", "where": { "terminal/strata_control/ling32_family.py": "MTP_CONFIG_KEY = \"ling32_mtp\"", "terminal/serve/ling32_kind.py": "def _mtp_args" } }, + { + "name": "ling32_mtp_mode (run config key)", + "kind": "launcher-flag", + "family": "ling-3.2-air", + "status": "default", + "default": "auto (also when the key is absent)", + "note": "the word next to the sidecar's path: `auto` (the engine decides at start) or `on` (forced); no path = off", + "where": { + "terminal/strata_control/ling32_family.py": "MTP_MODE_KEY = \"ling32_mtp_mode\"", + "terminal/serve/ling32_kind.py": "ling32_mtp_mode" + } + }, + { + "name": "ling32_plan_tier (run config key)", + "kind": "launcher-flag", + "family": "ling-3.2-air", + "status": "opt-in", + "default": "the plan's tier (A, B or C)", + "note": "the tier the launcher's plan gave: what `auto` does with an engine that cannot decide by itself (no mtp_auto=1 in its --info --kv line): the sidecar only in tier A or on one memory pool", + "where": { + "terminal/strata_control/ling32_family.py": "PLAN_TIER_KEY = \"ling32_plan_tier\"", + "terminal/serve/ling32_kind.py": "ling32_plan_tier" + } + }, { "name": "ling32_spec_block (run config key)", "kind": "launcher-flag", @@ -66760,6 +66784,17 @@ "terminal/strata_control/ling32_family.py": "\"cuda\": [\"--spec\", \"mtp\", \"--spec-adaptive\"]" } }, + { + "name": "--mtp-auto FILE --spec mtp --spec-adaptive", + "kind": "engine-flag", + "family": "ling-3.2-air", + "status": "default", + "default": "on (the launcher's default mode is auto)", + "note": "the engine decides about the sidecar after its memory plan: tier A or one memory pool loads it, tier C never, tier B only over a measured host-to-device link of 32 GB/s or more (`tier store: host-to-device link moved N GB/s`); written by serve only when the engine says mtp_auto=1 in `--info FILE --kv`; the serve INFO line then carries h2d_gbps and spec=off|mtp", + "where": { + "terminal/serve/ling32_kind.py": "--mtp-auto" + } + }, { "name": "--graph (AMD fast path)", "kind": "engine-flag", diff --git a/terminal/serve/ling32_kind.py b/terminal/serve/ling32_kind.py index 092c175955..905d2f8269 100644 --- a/terminal/serve/ling32_kind.py +++ b/terminal/serve/ling32_kind.py @@ -168,13 +168,24 @@ def has_mtp(info: dict | None) -> bool: return str((info or {}).get("mtp")) == "1" +def has_mtp_auto(info: dict | None) -> bool: + """Does the engine decide about the sidecar itself: `mtp_auto=1` in its `--info FILE --kv` line (`--mtp-auto FILE`).""" + return str((info or {}).get("mtp_auto")) == "1" + + +NO_MTP_AUTO_NOTE = ("Ling-3.2-Air: this engine cannot decide about the MTP sidecar by itself (no `mtp_auto` in its --info --kv line) and the plan is not tier A, where it surely pays, so it starts " + "without it; `--mtp on` forces it") + + def _mtp_args(args: list, exe, cfg, announce: bool) -> list: """The run config's `ling32_mtp` (the sidecar's path, written by setup / the launcher's `--mtp on`) becomes `--mtp FILE --spec mtp --spec-adaptive` (and `--spec-block K` when the config names a ceiling): only when the file is there and the engine says it takes it; a `--spec` the person wrote by hand is theirs and stays (no second one). The flags are not kept in the config's arguments: Control reads `--mtp ` as Flash-Next's draft layer.""" path = (cfg or {}).get("ling32_mtp") - if not path or "--mtp" in args: + if not path or "--mtp" in args or "--mtp-auto" in args: return args + mode = str((cfg or {}).get("ling32_mtp_mode") or "auto").lower() # "on" forces the sidecar (--mtp FILE); "auto" (also when the key is absent) lets the engine decide (--mtp-auto FILE) + mode = mode if mode in ("auto", "on") else "auto" if not Path(str(path)).is_file(): if announce: print("[strata] " + NO_MTP_FILE_NOTE.format(path=path), flush=True) @@ -190,7 +201,18 @@ def _mtp_args(args: list, exe, cfg, announce: bool) -> list: if announce: print(f"[strata] {NO_MTP_NOTE}", flush=True) return args - out = [*args, "--mtp", str(path), *ling32_family.MTP_ENGINE_FLAGS[backend]] + flag = "--mtp" + if mode == "auto": + if has_mtp_auto(info): + flag = "--mtp-auto" # the engine decides after its memory plan (and measures the link in tier B) + else: # an engine that cannot decide by itself: the sidecar only where it surely pays (tier A, one memory pool: a Mac), else none + legacy = "ling32_mtp_mode" not in (cfg or {}) # a config written before the auto word: the sidecar was forced then, and an engine that cannot decide keeps doing that + sure = legacy or str((cfg or {}).get("ling32_plan_tier") or "") == "A" or backend == "metal" + if not sure: + if announce: + print(f"[strata] {NO_MTP_AUTO_NOTE}", flush=True) + return args + out = [*args, flag, str(path), *ling32_family.MTP_ENGINE_FLAGS[backend]] block = (cfg or {}).get("ling32_spec_block") if isinstance(block, int) and not isinstance(block, bool) and 1 <= block <= 8: out += ["--spec-block", str(block)] @@ -289,9 +311,29 @@ def end_ids(tokenizer) -> set[int]: return ids -def stats_view(info: dict | None, last: dict | None, stat: dict | None, totals: dict | None = None) -> dict: - """The tier facts for `/metrics` and `/v1/status`: what the engine said at its start (INFO) and what its last request measured (DONE, STAT). Empty-safe.""" +def _mtp_line(spec, h2d, asked) -> str | None: + """`mtp.line` of the status: None when no sidecar was asked for (nothing to say); else strata_control/ling32_fit.mtp_status_line.""" + if asked is None: + return None + from strata_control import ling32_fit + return ling32_fit.mtp_status_line(spec, h2d, asked) + + +def mtp_mode_of(args) -> str | None: + """How the sidecar was asked for in an engine's arguments: "auto" (`--mtp-auto FILE`), "on" (`--mtp FILE`, forced) or None (no sidecar asked for).""" + args = [str(a) for a in (args or [])] + return "auto" if "--mtp-auto" in args else "on" if "--mtp" in args else None + + +def stats_view(info: dict | None, last: dict | None, stat: dict | None, totals: dict | None = None, args=None) -> dict: + """The tier facts for `/metrics` and `/v1/status`: what the engine said at its start (INFO) and what its last request measured (DONE, STAT). Empty-safe. `args`: the engine's arguments + (they say whether the sidecar was asked for by `--mtp-auto` or forced by `--mtp`: `mtp.line` is the plain status line, built from `spec=` and the measured `h2d_gbps=` only).""" info, last, stat, totals = info or {}, last or {}, stat or {}, totals or {} + try: + h2d = float(info.get("h2d_gbps")) if info.get("h2d_gbps") is not None else None + except (TypeError, ValueError): + h2d = None + asked = mtp_mode_of(args) offered, accepted = totals.get("drafts_offered") or 0, totals.get("drafts_accepted") or 0 hits, lookups = last.get("hits"), last.get("lookups") return { @@ -301,8 +343,10 @@ def stats_view(info: dict | None, last: dict | None, stat: dict | None, totals: "prefetch": None if info.get("prefetch") is None else bool(int(info.get("prefetch"))), "turbo_ssd": None if info.get("turbo_ssd") is None else bool(int(info.get("turbo_ssd"))), "spec": info.get("spec"), + "h2d_gbps": h2d, "mtp": {"on": str(info.get("spec")) == "mtp", "acceptance": stat.get("spec_accept"), "tokens_per_verify": stat.get("tok_per_verify"), "k": stat.get("spec_k"), - "drafts_accepted_total": accepted, "drafts_offered_total": offered, "acceptance_total": round(accepted / offered, 3) if offered else None}, + "drafts_accepted_total": accepted, "drafts_offered_total": offered, "acceptance_total": round(accepted / offered, 3) if offered else None, + "mode": asked, "line": _mtp_line(info.get("spec"), h2d, asked)}, "images": None if info.get("images") is None else str(info.get("images")) == "1", "vision": info.get("vision"), "last_request": { diff --git a/terminal/serve/server.py b/terminal/serve/server.py index affa045920..01f3df56ce 100644 --- a/terminal/serve/server.py +++ b/terminal/serve/server.py @@ -5632,7 +5632,7 @@ class Service: "gen": getattr(self.engine, "gen", None), **dict(getattr(self.engine, "info", {}) or {})} if getattr(self.engine, "ling32_engine", False) is True: # Ling-3.2-Air: the memory tier, experts per tier, the lookahead hit rate, tok/s (serve/ling32_kind.py) - engine["ling32"] = ling32_kind.stats_view(getattr(self.engine, "info", None), getattr(self.engine, "last", None), getattr(self.engine, "stat", None), self.totals) + engine["ling32"] = ling32_kind.stats_view(getattr(self.engine, "info", None), getattr(self.engine, "last", None), getattr(self.engine, "stat", None), self.totals, args=(getattr(self.engine, "spawn", None) or (None, []))[1]) if getattr(self.vision, "cpu_note", None): # the card had no room for the picture reader: the Terminal says so in its summary engine["vision_note"] = self.vision.cpu_note tel = self.telemetry.snapshot() if getattr(self, "telemetry", None) else {"now": {}, "history": {}, "static": {}} @@ -5730,7 +5730,7 @@ class Service: "in_flight": running + int(s.get("queued") or 0), "last_request_at": int(last_at) if last_at else None}, "last_timings": last_t, - **({"ling32": ling32_kind.stats_view(getattr(self.engine, "info", None), getattr(self.engine, "last", None), getattr(self.engine, "stat", None), self.totals)} + **({"ling32": ling32_kind.stats_view(getattr(self.engine, "info", None), getattr(self.engine, "last", None), getattr(self.engine, "stat", None), self.totals, args=(getattr(self.engine, "spawn", None) or (None, []))[1])} if getattr(self.engine, "ling32_engine", False) is True else {}), "vram": dict((getattr(self.engine, "info", {}) or {}).get("vram") or {}, elastic=bool((getattr(self.engine, "info", {}) or {}).get("vram_elastic"))), diff --git a/terminal/serve/test_ling32_mtp.py b/terminal/serve/test_ling32_mtp.py index f0dab7f19f..e9c1e6f79c 100644 --- a/terminal/serve/test_ling32_mtp.py +++ b/terminal/serve/test_ling32_mtp.py @@ -162,9 +162,79 @@ class EngineArgs(unittest.TestCase): self.assertEqual(args.count("--spec"), 1) self.assertNotIn("--mtp", args) + # ---- `--mtp auto` (the default): the engine decides at start (`--mtp-auto FILE`); `on` forces it (`--mtp FILE`) + def test_auto_makes_mtp_auto_flags_when_the_engine_can_decide_and_on_forces(self): + import os + with tempfile.TemporaryDirectory(ignore_cleanup_errors=True) as td: + os.environ["LING32_MOCK_CAPS"] = "mtp=1 mtp_auto=1" + for mode, flag in (("auto", "--mtp-auto"), ("on", "--mtp")): + cfg = self.cfg(Path(td), ling32_mtp_mode=mode) + args = ling32_kind.engine_args(cfg, self.exe(Path(td)), announce=False) + self.assertEqual(args[args.index(flag):], [flag, cfg["ling32_mtp"], "--spec", "mtp", "--spec-adaptive"]) + self.assertEqual(args.count("--mtp") + args.count("--mtp-auto"), 1) + cfg = self.cfg(Path(td)) # no mode key: auto (the new default) + self.assertIn("--mtp-auto", ling32_kind.engine_args(cfg, self.exe(Path(td)), announce=False)) + cfg = self.cfg(Path(td), ling32_mtp_mode="nonsense") + self.assertIn("--mtp-auto", ling32_kind.engine_args(cfg, self.exe(Path(td)), announce=False)) + + def test_auto_with_an_engine_that_cannot_decide(self): + import os + with tempfile.TemporaryDirectory(ignore_cleanup_errors=True) as td: + os.environ["LING32_MOCK_CAPS"] = "mtp=1" # says mtp=1 but not mtp_auto=1: an older engine + tier_b = ling32_kind.engine_args(self.cfg(Path(td), ling32_mtp_mode="auto", ling32_plan_tier="B"), self.exe(Path(td)), announce=False) + self.assertNotIn("--mtp", tier_b) + self.assertNotIn("--mtp-auto", tier_b) # not tier A: the sidecar does not surely pay, so none + tier_c = ling32_kind.engine_args(self.cfg(Path(td), ling32_mtp_mode="auto", ling32_plan_tier="C"), self.exe(Path(td)), announce=False) + self.assertNotIn("--mtp", tier_c) + a = ling32_kind.engine_args(self.cfg(Path(td), ling32_mtp_mode="auto", ling32_plan_tier="A"), self.exe(Path(td)), announce=False) + self.assertIn("--mtp", a) # tier A: it surely pays + m = ling32_kind.engine_args(self.cfg(Path(td), ling32_mtp_mode="auto", backend="metal"), self.exe(Path(td)), announce=False) + self.assertIn("--mtp", m) # one memory pool (a Mac): it pays + legacy = ling32_kind.engine_args(self.cfg(Path(td)), self.exe(Path(td)), announce=False) + self.assertIn("--mtp", legacy) # a config written before the word: forced, as then + forced = ling32_kind.engine_args(self.cfg(Path(td), ling32_mtp_mode="on", ling32_plan_tier="B"), self.exe(Path(td)), announce=False) + self.assertIn("--mtp", forced) + + def test_a_hand_written_mtp_auto_is_theirs(self): + import os + with tempfile.TemporaryDirectory(ignore_cleanup_errors=True) as td: + os.environ["LING32_MOCK_CAPS"] = "mtp=1 mtp_auto=1" + cfg = self.cfg(Path(td)) + cfg["args"] += ["--mtp-auto", "x.strata"] + args = ling32_kind.engine_args(cfg, self.exe(Path(td)), announce=False) + self.assertEqual(args.count("--mtp-auto"), 1) + self.assertNotIn("--mtp", args) + + def test_the_capability_is_mtp_auto_1_in_the_info_line(self): + self.assertTrue(ling32_kind.has_mtp_auto({"mtp": "1", "mtp_auto": "1"})) + self.assertFalse(ling32_kind.has_mtp_auto({"mtp": "1"})) + self.assertFalse(ling32_kind.has_mtp_auto(None)) + got = ling32_kind.parse_info("arch=ling32 layers=42 vocab=157184 drafter=none mtp=1 mtp_auto=1 images=1 tiers=A,B,C") + self.assertEqual((got["mtp"], got["mtp_auto"]), ("1", "1")) + + def test_the_status_says_what_was_chosen_and_why_from_measured_keys_only(self): + from strata_control import ling32_fit + v = ling32_kind.stats_view({"spec": "mtp", "h2d_gbps": "46.0"}, {}, {}, args=["--mtp-auto", "m", "--spec", "mtp"]) + self.assertEqual((v["h2d_gbps"], v["mtp"]["mode"], v["mtp"]["line"]), (46.0, "auto", "MTP: on (auto: link 46 GB/s)")) + v = ling32_kind.stats_view({"spec": "off", "h2d_gbps": "24.4"}, {}, {}, args=["--mtp-auto", "m"]) + self.assertEqual(v["mtp"]["line"], "MTP: off (auto: 24 GB/s link: no gain)") + self.assertFalse(v["mtp"]["on"]) + v = ling32_kind.stats_view({"spec": "off", "h2d_gbps": "0.0"}, {}, {}, args=["--mtp-auto", "m"]) + self.assertEqual(v["mtp"]["line"], "MTP: off (auto)") # not measured (tier A, no tier store): no figure is made up + v = ling32_kind.stats_view({"spec": "mtp"}, {}, {}, args=["--mtp-auto", "m"]) + self.assertEqual(v["mtp"]["line"], "MTP: on (auto)") + v = ling32_kind.stats_view({"spec": "mtp"}, {}, {}, args=["--mtp", "m"]) + self.assertEqual((v["mtp"]["mode"], v["mtp"]["line"]), ("on", "MTP: on (forced)")) + v = ling32_kind.stats_view({"spec": "off"}, {}, {}, args=["--model", "x"]) # no sidecar asked for: nothing to say + self.assertEqual((v["mtp"]["mode"], v["mtp"]["line"], v["h2d_gbps"]), (None, None, None)) + self.assertEqual(ling32_fit.mtp_status_line("mtp", 53.5), "MTP: on (auto: link 54 GB/s)") + self.assertFalse(any(ch.isdigit() for ch in ling32_fit.MTP_AUTO_NOTE.replace("32 GB/s", ""))) # the plan's note carries no speed figure but the engine's threshold + def test_stats_view_without_an_engine_is_safe(self): v = ling32_kind.stats_view(None, None, None) - self.assertEqual(v["mtp"], {"on": False, "acceptance": None, "tokens_per_verify": None, "k": None, "drafts_accepted_total": 0, "drafts_offered_total": 0, "acceptance_total": None}) + self.assertEqual(v["mtp"], {"on": False, "acceptance": None, "tokens_per_verify": None, "k": None, "drafts_accepted_total": 0, "drafts_offered_total": 0, "acceptance_total": None, + "mode": None, "line": None}) + self.assertIsNone(v["h2d_gbps"]) def test_the_stat_line_with_spec_keys(self): got = ling32_kind.parse_stat("STAT prefetch_hit=0 decode_tps=61.5 spec_accept=0.87 tok_per_verify=1.9 spec_k=3") diff --git a/terminal/setup.py b/terminal/setup.py index e66867c71d..fb8acbd40a 100644 --- a/terminal/setup.py +++ b/terminal/setup.py @@ -10905,7 +10905,10 @@ def install_ling32_air(a, family, gpu, hip, amd, cuda_tk, multi, port, ram, adop files = ling32_family.files_of(vision=False, mtp=False) # the model first; the Vision shard and the MTP sidecar are fetched on their own below (their absence never stops the install) if local_native is not None: files = [local_native.name] - mtp_on = ling32_mtp_wanted(a, vram_gib, unified) # the MTP sidecar: ON by default in every tier except a card of 12 GB or less (--mtp on / off win); in the download set when it is wanted + mtp_mode = ling32_fit.mtp_mode(ling32_mtp_choice(a), default_on=ling32_family.DEFAULT_MTP, vram_gib=vram_gib, unified=unified) # "auto" (the default: the engine decides at start), "on" (forced) or "off" + mtp_on = mtp_mode != "off" + mtp_plan = "auto" if mtp_mode == "auto" else mtp_on # what the planner is told: auto counts the sidecar where the engine surely loads it (tier A, one memory pool) + # the MTP sidecar: auto by default in every tier except on a card of 12 GB or less (--mtp on / auto / off win); the file is in the download set whenever the mode is not off left = 0.0 for n in files: if local_native is not None and n == local_native.name: @@ -10927,7 +10930,7 @@ def install_ling32_air(a, family, gpu, hip, amd, cuda_tk, multi, port, ram, adop pv = folder / ling32_family.VISION_FILE if not ling32_have(a, pv): left += (ling32_family.FILES[ling32_family.VISION_FILE][0] - (pv.with_name(pv.name + ".part").stat().st_size if pv.with_name(pv.name + ".part").is_file() else 0)) / 1e9 - args_fit, adv = ling32_engine_args(a, vram_gib, ram_gib, unified, ctx, vision, vision_device, mtp=mtp_on, backend=backend) + args_fit, adv = ling32_engine_args(a, vram_gib, ram_gib, unified, ctx, vision, vision_device, mtp=mtp_plan, backend=backend) say() p = adv["plan"] if backend == "metal": # a Mac keeps the whole model in one memory pool, no tiers: no hard minimum, a clear warning below the recommendation @@ -10967,7 +10970,7 @@ def install_ling32_air(a, family, gpu, hip, amd, cuda_tk, multi, port, ram, adop if WIN and unified and engine_program.is_file(): # a Windows integrated GPU (Strix Halo): the engine probes how much one process can allocate for the GPU (a few seconds), the plan follows it cap = ling32_fit.probe_cap(engine_program) if cap: - args_fit, adv = ling32_engine_args(a, None, ram_gib, True, ctx, vision, vision_device, gpu_cap_gib=cap, mtp=mtp_on, backend=backend) + args_fit, adv = ling32_engine_args(a, None, ram_gib, True, ctx, vision, vision_device, gpu_cap_gib=cap, mtp=mtp_plan, backend=backend) p = adv["plan"] ok(f"Windows integrated GPU: a process can allocate {cap:.1f} GiB for the GPU: tier {adv['tier']}, {p['vram_gb']:.1f} GB in the card part, {p['ram_gb']:.1f} GB in RAM, {p['ssd_gb']:.1f} GB read from the SSD") for w in adv["warnings"]: @@ -11002,9 +11005,9 @@ def install_ling32_air(a, family, gpu, hip, amd, cuda_tk, multi, port, ram, adop mtp_path = ling32_fetch_mtp(a, folder, own, paths[files[0]], [(data / "models" / ling32_family.FAMILY)]) if mtp_path is not None: lic = ling32_family.mtp_license(mtp_path) - ok(f"MTP: on ({mtp_path.name}); licence {lic['spdx']}") + ok(f"MTP: {'on' if mtp_mode == 'on' else 'auto (the engine decides at start whether it pays here)'} ({mtp_path.name}); licence {lic['spdx']}") say(f" The MTP sidecar's licence: {lic['spdx']}. {lic['attribution']}") - elif ling32_mtp_choice(a) is None and ling32_fit.mtp_small_card(vram_gib, unified): + elif ling32_mtp_choice(a) in (None, "auto") and ling32_fit.mtp_small_card(vram_gib, unified): ok("MTP: off (a card of 12 GB or less starts without it by default; --mtp on starts with it)") else: ok("MTP: off") @@ -11015,6 +11018,9 @@ def install_ling32_air(a, family, gpu, hip, amd, cuda_tk, multi, port, ram, adop cfg["backend"] = backend # serve picks the MTP flags of the program from it if mtp_path is not None: cfg[ling32_family.MTP_CONFIG_KEY] = str(mtp_path) + cfg[ling32_family.MTP_MODE_KEY] = "on" if mtp_mode == "on" else "auto" # "on" forces it (--mtp FILE), "auto" lets the engine decide (--mtp-auto FILE) + if adv.get("tier"): + cfg[ling32_family.PLAN_TIER_KEY] = adv["tier"] # for an engine that cannot decide by itself: auto = the sidecar in tier A only if isinstance(getattr(a, "_roles", None), dict): from strata_control import gpu_roles as GR rcards = getattr(a, "_roles_cards", None) or [gpu] @@ -12421,7 +12427,7 @@ def main() -> int: ap.add_argument("--peer-reserve-mib", type=int, metavar="N", help="Qwen3.6-35B-A3B on two GPUs (--gpus): VRAM in MiB the second-card expert tier (--peer-device) " "leaves free there (the engine's default: 600)") - ap.add_argument("--mtp", choices=["on", "off"], + ap.add_argument("--mtp", choices=["on", "off", "auto"], help="the draft layer (MTP): off starts the model without it, which frees about 1 GB of graphics memory " "for the expert cache and takes less RAM, at the price of speed; it is kept in the run config " "(\"mtp\": false) and a later setup run does not undo it. on: back to the default") diff --git a/terminal/strata_cli/launch/cmd.py b/terminal/strata_cli/launch/cmd.py index c0db856f20..24bee77c63 100644 --- a/terminal/strata_cli/launch/cmd.py +++ b/terminal/strata_cli/launch/cmd.py @@ -134,10 +134,10 @@ def add_parsers(sp: argparse._SubParsersAction) -> list[argparse.ArgumentParser] "'on' picks the reader by your graphics memory: the CPU reader under 24 GB, the GPU reader from 24 GB (any make); " "gpu / cpu choose one; off turns pictures off") g.add_argument("--parallel", type=_parallel, metavar="N", help="requests answered at the same time, 1 to 64 (Inkling-2-Mini runs up to 64; the Qwen engine keeps 16 on NVIDIA and AMD cards and 8 elsewhere; Hy4-Flash answers one; default: fit to your graphics card; one request at a time with the DFlash2 drafter)") - g.add_argument("--mtp", type=_choice("a draft layer setting", S.MTP_MODES), metavar="on|off", + g.add_argument("--mtp", type=_choice("a draft layer setting", S.MTP_MODES), metavar="on|off|auto", help="the draft layer that makes answers faster. off starts without it: about 1 GB less graphics memory and less RAM, " "slower answers; use it when the engine stops at start on a small card or a PC with little RAM. Default: on. Ling-3.2-Air: its MTP sidecar " - "(a file in the download set that drafts several tokens per step; the answer is the same; MIT licence) is on by default, except on a card of 12 GB or less (it takes memory the experts need there); on forces it, off starts without it.") + "(a file in the download set that drafts several tokens per step; the answer is the same; MIT licence) is auto by default: the engine decides at start whether it pays (loaded when the whole model is on the card, never in tier C, in tier B only over a fast link); not on a card of 12 GB or less; on forces it, off starts without it.") g.add_argument("--drafting", type=_choice("a drafting setting", (*S.DRAFTING_MODES, "dfly")), metavar="auto|mtp|dflash2|dfly|off", 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. Hy4-Flash GGUF also accepts dfly with --dfly-model. Auto uses the MTP when several requests run at once; --drafting dflash2 runs with the --parallel count you set. " diff --git a/terminal/strata_cli/launch/runner.py b/terminal/strata_cli/launch/runner.py index b11bf35354..c077f29235 100644 --- a/terminal/strata_cli/launch/runner.py +++ b/terminal/strata_cli/launch/runner.py @@ -858,15 +858,18 @@ def derive_config(base: dict, s: S.LaunchSettings, *, bool_flags: frozenset[str] mine = ling32_fit.tier_args(tier=s.tier or "auto", vram_budget_gib=s.vram_budget or 0.0, ram_budget_gib=s.ram_budget or 0.0, turbo_ssd=bool(s.turbo_ssd)) extra = {**extra, **{k: (v if v else "on") for k, v in _pairs(mine).items() if k not in extra}} cfg.pop("mtp", None) - if s.mtp == "off": # the MTP sidecar (strata_control/ling32_family.py): off drops the config key serve makes the engine flags from + from strata_control import ling32_family + if s.mtp == "off": # the MTP sidecar (strata_control/ling32_family.py): off drops the config keys serve makes the engine flags from cfg.pop("ling32_mtp", None) - elif s.mtp == "on" and not cfg.get("ling32_mtp"): - from strata_control import ling32_family + cfg.pop(ling32_family.MTP_MODE_KEY, None) + elif s.mtp in ("on", "auto") and not cfg.get("ling32_mtp"): cargs0 = [str(a) for a in cfg.get("args") or []] model0 = cargs0[cargs0.index("--model") + 1] if "--model" in cargs0[:-1] else None found = ling32_family.find_mtp(model0) if found is not None: cfg["ling32_mtp"] = str(found) + if s.mtp in ("on", "auto") and cfg.get("ling32_mtp"): # on forces the sidecar (--mtp FILE), auto lets the engine decide (--mtp-auto FILE) + cfg[ling32_family.MTP_MODE_KEY] = "on" if s.mtp == "on" else "auto" if isinstance(cfg.get("args"), list): # pictures: off takes the Vision shard out of this start; gpu / cpu name the encoder's device (only with a shard to read) cargs = [str(a) for a in cfg["args"]] if s.vision in ("off", "no"): diff --git a/terminal/strata_cli/launch/settings.py b/terminal/strata_cli/launch/settings.py index 013fd39480..0cfe091f09 100644 --- a/terminal/strata_cli/launch/settings.py +++ b/terminal/strata_cli/launch/settings.py @@ -29,7 +29,7 @@ ACCESS_WORDS = {"local": "This computer only", "lan": "My local network", "addre "tailscale": "Tailscale"} TUNE_MODES = ("quick", "thorough", "skip") VISION_MODES = ("off", "on", "gpu", "cpu") -MTP_MODES = ("on", "off") +MTP_MODES = ("on", "off", "auto") # auto: Ling-3.2-Air only (the engine decides at start; the default there); the other models take it as nothing said #: strata_control/split_engine.py MODES: the all-cards split engine on NVIDIA and AMD gfx1201 cards (auto = by itself where it is supported, the default) SPLIT_MODES = ("auto", "on", "off") #: Ling-3.2-Air (strata_control/ling32_family.py THINKING, TIERS; tests/terminal/test_ling32_launch.py keeps them the same) @@ -432,10 +432,10 @@ def check_ling32(s: LaunchSettings, *, vram_gb: float | None, ram_gb: float | No return out try: from strata_control import ling32_family, ling32_fit - mtp_on = ling32_fit.mtp_wanted(s.mtp, default_on=ling32_family.DEFAULT_MTP, vram_gib=vram_gb, unified=bool(unified)) + mtp_mode = ling32_fit.mtp_mode(s.mtp, default_on=ling32_family.DEFAULT_MTP, vram_gib=vram_gb, unified=bool(unified)) # auto (the default), on (forced) or off adv = ling32_fit.advise(vram_gb, float(ram_gb or 0.0), unified=unified, disk_free_gb=disk_free_gb, tier=s.tier or "auto", vram_budget_gib=s.vram_budget or 0.0, ram_budget_gib=s.ram_budget or 0.0, turbo_ssd=bool(s.turbo_ssd), ctx=s.context, vision=s.vision not in ("off", "no"), - vision_device=s.vision if s.vision in ("gpu", "cpu") else "auto", mtp=mtp_on) + vision_device=s.vision if s.vision in ("gpu", "cpu") else "auto", mtp="auto" if mtp_mode == "auto" else mtp_mode == "on") except Exception: # noqa: BLE001 - a plan that cannot be worked out stays silent rather than wrong return out v = str(vendor or "").lower() @@ -458,6 +458,8 @@ def check_ling32(s: LaunchSettings, *, vram_gb: float | None, ram_gb: float | No elif adv["tier"] not in (None, "A") and v != "apple": # a Mac has no tiers (its own notice above) out.append(Notice("warn", f"Memory tier {adv['tier']} ({ling32_fit.TIER_WORDS[adv['tier']]}) on this computer: {adv['speed']}.", "A card with more video memory, or more RAM, moves it up a tier." if adv["tier"] == "B" else "More RAM or video memory shortens the SSD reads; an NVMe drive matters most.")) + if mtp_mode == "auto" and adv["tier"] == "B": # the engine measures the card's link at start and loads the sidecar only over a fast one: said once, with the way to force or drop it + out.append(Notice("warn", ling32_fit.MTP_AUTO_NOTE, "--mtp on forces it, --mtp off leaves it out.")) if s.mtp == "on": # asked for by hand: what it is, and the licence (on by default it is part of the plan and says nothing more) out.append(Notice("warn", ling32_fit.MTP_NOTE if adv["tier"] in ("A", None) else ling32_fit.MTP_NOTE_TIERED, "Take --mtp on away (or --mtp off) to start without it.")) if ling32_fit.mtp_small_card(vram_gb, bool(unified)): diff --git a/terminal/strata_control/ling32_family.py b/terminal/strata_control/ling32_family.py index f4b20834db..0f0e374a91 100644 --- a/terminal/strata_control/ling32_family.py +++ b/terminal/strata_control/ling32_family.py @@ -44,7 +44,11 @@ DEFAULT_THINKING = "off" #: sidecar's memory whenever it is on. No speed figure is written into any text of the launcher: the measurements are still moving. MTP_FILE = "Ling-3.2-Air-MTP.strata" # the default: S2 experts + S6 non-expert + a 110 MB S2 draft head, 0.99 GB DEFAULT_MTP = True # the family default: nothing said = ON in every tier except a discrete card of 12 GB or less (ling32_fit.mtp_wanted); `--mtp off` always turns it off -MTP_MODES = ("on", "off") +MTP_MODES = ("auto", "on", "off") # `--mtp auto` (the default): the ENGINE decides at start (`--mtp-auto FILE`: tier A or unified memory loads the sidecar, tier C never, tier B only over a link of 32 GB/s or more); `on` forces it, `off` leaves it out +DEFAULT_MTP_MODE = "auto" +MTP_AUTO_MIN_LINK_GBPS = 32.0 # the engine's kMtpAutoMinLinkGbps (ling32_tier_planner.hpp): between PCIe 4.0 x16 (24.4 GB/s measured) and PCIe 5.0 x16 (45 GB/s and more) +MTP_MODE_KEY = "ling32_mtp_mode" # the run config's word next to the path: "auto" (also when the key is absent) or "on"; no path = off +PLAN_TIER_KEY = "ling32_plan_tier" # the tier the launcher's plan gave ("A" / "B" / "C"): what `auto` does with an engine that cannot decide by itself (no `mtp_auto=1` in its --info line) #: What a run config says: "ling32_mtp": the sidecar's path. The engine flags (`--mtp FILE --spec mtp --spec-adaptive`) are made from it at the start (serve/ling32_kind.py), NOT kept in the #: arguments, because Control reads `--mtp ` as Flash-Next's draft layer (doctor, discovery, drafting) and would try to fetch that. MTP_CONFIG_KEY = "ling32_mtp" diff --git a/terminal/strata_control/ling32_fit.py b/terminal/strata_control/ling32_fit.py index 6ce0d6355f..44103af358 100644 --- a/terminal/strata_control/ling32_fit.py +++ b/terminal/strata_control/ling32_fit.py @@ -312,10 +312,18 @@ def describe(p: dict) -> str: def chunk_for(vram_gib: float | None, unified: bool = False) -> int: - """The prompt chunk the launcher starts the engine with: the float logits buffer is 0.6 MB a token, so a small card takes a small chunk (P2 ran 8-16 GB plans at 256).""" + """The prompt chunk the launcher starts the engine with. The activation buffers scale with it (0.6 GiB at 256, about 2 GiB at 2048), and on a card that runs the pool layout every byte of + them is a pool slot, so a card with little memory takes a small chunk: under 16 GB 256 (P2 ran 8-16 GB plans at 256). But the layer-major span prefill runs sub-chunks of `--chunk` rows, + so a small chunk multiplies the per-sub-chunk work and starves the tensor-core tiles: L32-CUDA measured on an RTX 5090 (tier B, plain decode unaffected) a 4062-token prompt 33 % slower + and a 32,496-token prompt 115 % slower at 256 than at the engine's default. So 16 to 30 GB: 1024 (about 0.45 GiB, 100 slots of the pool, for a much faster long prefill; to be measured on a + 24 GB card), 30 to 48 GB: the engine's own default (2048), from 48 GB the static layout keeps 1024 (a bigger chunk takes hot ranks).""" if unified or not vram_gib: return 1024 - return 256 if vram_gib < 48 else 1024 # a card up to 32 GiB runs the pool layout (every byte of activations is a pool slot) and all the measurements use 256 + if vram_gib < 16: + return 256 + if vram_gib < 30: + return 1024 + return 2048 if vram_gib < 48 else 1024 def engine_chunk(device_gib: float | None) -> int: @@ -363,6 +371,29 @@ def mtp_wanted(word: str | None, *, default_on: bool = False, vram_gib: float | return bool(default_on) and not mtp_small_card(vram_gib, unified) +def mtp_mode(word: str | None, *, default_on: bool = False, vram_gib: float | None = None, unified: bool = False) -> str: + """The MTP word of a start: "off" (`--mtp off`, or the default on a card of 12 GB or less), "on" (`--mtp on`: forced, the engine loads the sidecar), "auto" (nothing said, or `--mtp auto`: + the engine decides at start, `--mtp-auto FILE`).""" + if not mtp_wanted(word, default_on=default_on, vram_gib=vram_gib, unified=unified): + return "off" + return "on" if word == "on" else "auto" + + +MTP_AUTO_NOTE = ("MTP: auto. The engine decides at start whether the sidecar pays here: it is loaded when the whole model is in video memory (or in one memory pool), never in tier C, and in " + "tier B only when the card's link to the system memory is fast (32 GB/s or more); the status line says which it chose. --mtp on forces it, --mtp off leaves it out.") + + +def mtp_status_line(spec: str | None, h2d_gbps: float | None, mode: str | None = "auto") -> str: + """One plain line for the status: what the engine chose and why, from its INFO (`spec=off|mtp`, `h2d_gbps=`). Only measured figures are in it.""" + on = str(spec) == "mtp" + link = f"link {h2d_gbps:.0f} GB/s" if h2d_gbps else None + if mode == "on": + return "MTP: on (forced)" if on else "MTP: off" + if on: + return f"MTP: on (auto: {link})" if link else "MTP: on (auto)" + return f"MTP: off (auto: {h2d_gbps:.0f} GB/s link: no gain)" if h2d_gbps else "MTP: off (auto)" + + def plan(vram_gib: float | None, ram_gib: float, *, unified: bool = False, tier: str = "auto", vram_budget_gib: float = 0.0, ram_budget_gib: float = 0.0, turbo_ssd: bool = False, ctx: int | None = None, chunk: int | None = None, prefetch: bool = True, vision: bool = False, vision_device: str = "auto", gpu_cap_gib: float | None = None, ram_floor_gib: float | None = None, mtp: bool = False, spec_block: int | None = None) -> dict: @@ -372,6 +403,20 @@ def plan(vram_gib: float | None, ram_gib: float, *, unified: bool = False, tier: cap (the engine registers ordinary pages with hipHostRegister; only the ring / staging, about 1 GiB, is hipHostMalloc and counts with the card). Budgets the person gave win. `vram_gib` is the card's free memory in GiB (None: no card); `ram_gib` the available RAM in GiB; with `unified` True `ram_gib` is the one pool (what the GPU can map) and `vram_gib` is ignored. `tier` is the person's word: auto, A, B, C (or the engine's vram / hybrid / nvme). Returns plan_tier()'s dict plus `tier` (the mode letter), `vram_gb` / `ram_gb` / `ssd_gb` (GB placed in each, the Hy4 table's words), `unified`, `chunk`, `ctx`.""" + if mtp == "auto": + # `--mtp auto`: the engine loads the sidecar in tier A and in one memory pool, never in tier C, and in tier B only over a fast link it measures at start (32 GB/s and more). The plan + # counts it where it is certain (A, unified) and leaves it out otherwise (the common PCIe 4.0 card does not load it), with one note. + args = dict(unified=unified, tier=tier, vram_budget_gib=vram_budget_gib, ram_budget_gib=ram_budget_gib, turbo_ssd=turbo_ssd, ctx=ctx, chunk=chunk, prefetch=prefetch, + vision=vision, vision_device=vision_device, gpu_cap_gib=gpu_cap_gib, ram_floor_gib=ram_floor_gib, spec_block=spec_block) + base = plan(vram_gib, ram_gib, mtp=False, **args) + if base["ok"] and (base["mode"] == "A" or unified): + got = plan(vram_gib, ram_gib, mtp=True, **args) + got["mtp"]["mode"] = "auto" + return got + base["mtp"]["mode"] = "auto" + if base["ok"] and base["mode"] == "B": + base["notes"].append(MTP_AUTO_NOTE) + return base n = DEFAULT_CONTEXT if ctx is None else int(ctx) enc = vision_encoder(vram_gib, unified=unified, pool_gib=ram_gib, device=vision_device) if vision else None ev, eh = (enc["vram_bytes"], enc["host_bytes"]) if enc else (0, 0) @@ -409,7 +454,7 @@ def plan(vram_gib: float | None, ram_gib: float, *, unified: bool = False, tier: counted = got["vram_total_planned"] + got["ring_bytes"] # the card part and the ring / staging count against the cap; the RAM tier does not if counted > (gpu_cap_gib - IGPU_CAP_RESERVE_GIB) * GIB: got["notes"].append(f"the card part and the ring need {counted / GIB:.1f} GiB of the {gpu_cap_gib:g} GiB this GPU can allocate (the engine keeps {IGPU_CAP_RESERVE_GIB:g} GiB); lower --vram-budget-gib") - got["mtp"] = {"on": bool(mtp), "vram_mib": round(mv / MIB), "k_max": (spec_block or MTP_DEFAULT_BLOCK) if mtp else None} + got["mtp"] = {"on": bool(mtp), "mode": "on" if mtp else "off", "vram_mib": round(mv / MIB), "k_max": (spec_block or MTP_DEFAULT_BLOCK) if mtp else None} got["gpu_cap_gib"] = gpu_cap_gib got["tier"] = got["mode"] if got["ok"] else None # an impossible choice (--tier A on a small card) has no tier: the error says why got["unified"] = bool(unified) diff --git a/terminal/tests/terminal/test_ling32_fit.py b/terminal/tests/terminal/test_ling32_fit.py index 50f6e383d8..4462cc4d40 100644 --- a/terminal/tests/terminal/test_ling32_fit.py +++ b/terminal/tests/terminal/test_ling32_fit.py @@ -286,6 +286,16 @@ def test_engine_chunk_rule_and_the_launchers_use_of_it(): assert p(96, 128, chunk=1024)["chunk"] == 1024 +def test_the_launcher_chunk_by_card_size(): + # L32-CUDA, RTX 5090 tier B: --chunk 256 made a 4062-token prefill 33 % slower and a 32K one 115 % slower than the engine's default; the small chunk stays where memory is the limit + assert [F.chunk_for(g) for g in (8, 12, 15.9, 16, 23.3, 24, 29.9, 30, 31.4, 32, 47.9, 48, 96)] == [256, 256, 256, 1024, 1024, 1024, 1024, 2048, 2048, 2048, 2048, 1024, 1024] + assert F.chunk_for(None) == 1024 and F.chunk_for(0) == 1024 and F.chunk_for(96, unified=True) == 1024 + assert p(32, 128)["chunk"] == 2048 and p(24, 128)["chunk"] == 1024 and p(12, 128)["chunk"] == 256 + # the bigger chunk costs pool slots (its activation buffers), a few percent on a 24 GB card + small, big = F.plan(24, 128, chunk=256, ctx=32768), F.plan(24, 128, chunk=1024, ctx=32768) + assert 0 < small["dyn_slots"] - big["dyn_slots"] < 0.1 * small["dyn_slots"] + + # ---- the MTP sidecar (L32-MTP): resident on the card in every tier ---- def test_mtp_bytes_are_the_file_plus_its_cache_ring_and_buffers(): @@ -359,6 +369,40 @@ def test_the_family_default_is_on(): assert ling32_family.DEFAULT_MTP is True +# ---- `--mtp auto` (the default; L32-CUDA's --mtp-auto): the engine decides at start; the plan counts the sidecar where it surely loads + +def test_the_mtp_word_is_auto_unless_said_or_a_small_card(): + assert ling32_family.MTP_MODES == ("auto", "on", "off") and ling32_family.DEFAULT_MTP_MODE == "auto" and ling32_family.MTP_AUTO_MIN_LINK_GBPS == 32.0 + kw = dict(default_on=ling32_family.DEFAULT_MTP) + assert F.mtp_mode(None, vram_gib=24, **kw) == "auto" and F.mtp_mode("auto", vram_gib=24, **kw) == "auto" and F.mtp_mode(None, unified=True, **kw) == "auto" + assert F.mtp_mode("on", vram_gib=24, **kw) == "on" and F.mtp_mode("off", vram_gib=24, **kw) == "off" + assert F.mtp_mode(None, vram_gib=12, **kw) == "off" and F.mtp_mode("auto", vram_gib=8, **kw) == "off" # a card of 12 GB or less starts without it by default (auto stays "nothing said" there) + assert F.mtp_mode("on", vram_gib=8, **kw) == "on" # --mtp on still forces it + + +def test_the_plan_with_auto_counts_the_sidecar_only_where_the_engine_surely_loads_it(): + a = F.plan(96, 128, mtp="auto", **KW) # tier A: loaded + assert a["tier"] == "A" and a["mtp"]["on"] is True and a["mtp"]["mode"] == "auto" + assert F.plan(96, 128, mtp=True, **KW)["vram_fixed"] == a["vram_fixed"] + b = F.plan(24, 128, mtp="auto", **KW) # tier B: the engine measures the link; the plan leaves the sidecar out and says so + assert b["tier"] == "B" and b["mtp"]["on"] is False and b["mtp"]["mode"] == "auto" and any("MTP: auto" in n for n in b["notes"]) + assert b["dyn_slots"] == F.plan(24, 128, mtp=False, **KW)["dyn_slots"] > F.plan(24, 128, mtp=True, **KW)["dyn_slots"] # a pool without the sidecar's bytes + c = F.plan(24, 16, mtp="auto", **KW) # tier C: never loaded, no note about the link + assert c["tier"] == "C" and c["mtp"]["on"] is False and not any("MTP: auto" in n for n in c["notes"]) + u = F.plan(None, 121, unified=True, mtp="auto", **KW) # one memory pool: loaded + assert u["mtp"]["on"] is True + assert F.plan(24, 128, mtp=True, **KW)["mtp"]["mode"] == "on" and F.plan(24, 128, **KW)["mtp"]["mode"] == "off" + adv = F.advise(24, 128, mtp="auto", **KW) + assert adv["tier"] == "B" and adv["download_gb"] == round(F.disk_gb() + 0.99, 2) # the file is in the download set whenever the mode is not off + + +def test_the_status_line_is_built_from_measured_keys(): + assert F.mtp_status_line("mtp", 46.0) == "MTP: on (auto: link 46 GB/s)" + assert F.mtp_status_line("off", 24.4) == "MTP: off (auto: 24 GB/s link: no gain)" + assert F.mtp_status_line("off", 0.0) == "MTP: off (auto)" and F.mtp_status_line("mtp", None) == "MTP: on (auto)" + assert F.mtp_status_line("mtp", 24.4, "on") == "MTP: on (forced)" and F.mtp_status_line("off", None, "on") == "MTP: off" + + def test_mtp_costs_a_machine_at_the_edge_its_tier_and_the_plan_says_so(): """A 90 GB card with 128 GB RAM is tier A without the sidecar; with it (1.7 GB more on the card) the plan is tier B: the plan still counts it, and the person sees the tier it gets.""" assert F.plan(90, 128, **KW)["tier"] == "A" and F.plan(90, 128, mtp=True, **KW)["tier"] == "B" diff --git a/terminal/tests/terminal/test_ling32_launch.py b/terminal/tests/terminal/test_ling32_launch.py index 7d905d854a..65e8d9d81f 100644 --- a/terminal/tests/terminal/test_ling32_launch.py +++ b/terminal/tests/terminal/test_ling32_launch.py @@ -253,6 +253,22 @@ class Mtp(unittest.TestCase): self.assertNotIn("mtp", cfg) # Flash-Next's own key is never written for Ling self.assertEqual(R.derive_config(base, S.LaunchSettings(family="ling-3.2-air"), bool_flags=tune_knobs.BOOL_FLAGS, log="x.log").get("ling32_mtp"), None) # nothing said: off for now + def test_auto_and_on_write_the_mode_next_to_the_path_and_off_takes_both_out(self): + with tempfile.TemporaryDirectory() as td: + base, side = self.with_sidecar(td) + d = lambda **kw: R.derive_config(base, S.LaunchSettings(family="ling-3.2-air", **kw), bool_flags=tune_knobs.BOOL_FLAGS, log="x.log") + on, auto = d(mtp="on"), d(mtp="auto") + self.assertEqual((on["ling32_mtp"], on[ling32_family.MTP_MODE_KEY]), (str(side), "on")) # forced: --mtp FILE + self.assertEqual((auto["ling32_mtp"], auto[ling32_family.MTP_MODE_KEY]), (str(side), "auto")) # the engine decides: --mtp-auto FILE + for cfg in (on, auto): + for flag in ("--mtp", "--mtp-auto", "--spec", "--spec-adaptive"): + self.assertNotIn(flag, cfg["args"]) + off = R.derive_config({**base, "ling32_mtp": str(side), ling32_family.MTP_MODE_KEY: "auto"}, S.LaunchSettings(family="ling-3.2-air", mtp="off"), + bool_flags=tune_knobs.BOOL_FLAGS, log="x.log") + self.assertNotIn("ling32_mtp", off) + self.assertNotIn(ling32_family.MTP_MODE_KEY, off) + self.assertEqual(S.MTP_MODES, ("on", "off", "auto")) + def test_off_takes_it_out_and_on_without_a_file_adds_nothing(self): with tempfile.TemporaryDirectory() as td: base, side = self.with_sidecar(td) diff --git a/terminal/tools/ling32_mock_engine.py b/terminal/tools/ling32_mock_engine.py index e1d4a29325..01b7781769 100644 --- a/terminal/tools/ling32_mock_engine.py +++ b/terminal/tools/ling32_mock_engine.py @@ -81,7 +81,7 @@ def main(argv=None) -> int: if args[:1] == ["--info"]: # `exe --info FILE --kv`: the facts serve reads before a start caps = caps_of(os.environ) if "--kv" in args: - say(f"arch=ling32 layers=42 vocab=157184 drafter=none images={caps.get('images', '0')} tiers=A,B,C" + (" mtp=1" if caps.get("mtp") == "1" else "")) + say(f"arch=ling32 layers=42 vocab=157184 drafter=none images={caps.get('images', '0')} tiers=A,B,C" + (" mtp=1" if caps.get("mtp") == "1" else "") + (" mtp_auto=1" if caps.get("mtp_auto") == "1" else "")) else: say("arch=ling32 model=Ling-3.2-Air layers=42 kda=35 mla=7 dense=2 moe=40 hidden=2560 vocab=157184 experts=512 top_k=8 ctx_max=262144") return 0 @@ -102,7 +102,8 @@ def main(argv=None) -> int: base = os.path.basename(str(opts.get("--model") or opts.get("--native") or "mock.strata")) caps = caps_of(os.environ) # `--spec mtp` needs `--mtp FILE` (the engine refuses a missing sidecar at load, as the real one does) and the engine's `mtp=1` capability - if opts.get("--spec") == "mtp" and ("--mtp" not in opts or not os.path.isfile(str(opts.get("--mtp")))): + sidecar = opts.get("--mtp") or opts.get("--mtp-auto") # --mtp-auto FILE: the engine decides (here: always loads it when the mock says mtp_auto=1) + if opts.get("--spec") == "mtp" and (not sidecar or not os.path.isfile(str(sidecar))): say("ERR --spec mtp needs --mtp FILE (the sidecar)") return 2 spec_word = "mtp" if opts.get("--spec") == "mtp" else "off" @@ -111,7 +112,7 @@ def main(argv=None) -> int: images_info = f"images=1 vision={'cpu' if device == 'auto' else device}" if has_vision else "images=0" say(f"INFO engine=strata-ling32-serve-0 arch=ling32 backend=cuda model={base} layers=42 vocab=157184 chunk={chunk} session_reuse=1 tier={tier} " f"vram_ranks={nums['vram_ranks']} ram_ranks={nums['ram_ranks']} ssd_ranks={nums['ssd_ranks']} dyn_slots={nums['dyn_slots']} lookahead_k={nums['lookahead_k']} " - f"prefetch={nums['prefetch']} turbo_ssd={1 if '--turbo-ssd' in opts else 0} spec={spec_word} {images_info}") + f"prefetch={nums['prefetch']} turbo_ssd={1 if '--turbo-ssd' in opts else 0} spec={spec_word} " + (f"h2d_gbps={caps['h2d_gbps']} " if "h2d_gbps" in caps else "") + images_info) say(f"READY {ctx} stop") stop = threading.Event() lines: list[str] = [] diff --git a/terminal/tools/test_setup_ling32.py b/terminal/tools/test_setup_ling32.py index 798a9f6b5d..ecd473d6c7 100644 --- a/terminal/tools/test_setup_ling32.py +++ b/terminal/tools/test_setup_ling32.py @@ -473,18 +473,24 @@ class Install(unittest.TestCase): _, w, says, _ = self.run_install(mtp="off") self.assertNotIn(ling32_family.MTP_CONFIG_KEY, w["cfg"]) self.assertTrue(any(s == "ok MTP: off" for s in says)) - _, w, says, mine = self.run_install(mtp_beside=True, vram_gb=96.0, ram=128) # nothing said: on + _, w, says, mine = self.run_install(mtp_beside=True, vram_gb=96.0, ram=128) # nothing said: auto (the engine decides at start; the file is in the set) self.assertEqual(w["cfg"][ling32_family.MTP_CONFIG_KEY], str(mine.parent / ling32_family.MTP_FILE)) - self.assertTrue(any(s.startswith("ok MTP: on (Ling-3.2-Air-MTP.strata); licence MIT") for s in says)) + self.assertEqual(w["cfg"][ling32_family.MTP_MODE_KEY], "auto") + self.assertEqual(w["cfg"][ling32_family.PLAN_TIER_KEY], "A") # the plan's tier, for an engine that cannot decide by itself + self.assertTrue(any(s.startswith("ok MTP: auto (the engine decides at start whether it pays here) (Ling-3.2-Air-MTP.strata); licence MIT") for s in says)) _, w, says, mine = self.run_install(mtp="on", mtp_beside=True) cfg = w["cfg"] self.assertEqual(cfg[ling32_family.MTP_CONFIG_KEY], str(mine.parent / ling32_family.MTP_FILE)) + self.assertEqual(cfg[ling32_family.MTP_MODE_KEY], "on") # forced: --mtp FILE + _, w, _, _ = self.run_install(mtp="auto", mtp_beside=True) + self.assertEqual(w["cfg"][ling32_family.MTP_MODE_KEY], "auto") for flag in ("--mtp", "--spec", "--spec-adaptive"): self.assertNotIn(flag, cfg["args"]) # Control reads --mtp as Flash-Next's draft layer: serve makes the flags self.assertTrue(any(s.startswith("ok MTP: on (Ling-3.2-Air-MTP.strata); licence MIT") for s in says)) self.assertTrue(any("The MTP sidecar's licence: MIT. Derived from the MTP" in s and "ff099487" in s for s in says)) _, w, says, _ = self.run_install(mtp="off", mtp_beside=True) self.assertNotIn(ling32_family.MTP_CONFIG_KEY, w["cfg"]) + self.assertNotIn(ling32_family.MTP_MODE_KEY, w["cfg"]) def test_with_the_default_on_nothing_said_means_every_tier(self): """The owner's rule (2026-12-01): MTP is ON by default in tier A, B and C when the sidecar is there; --mtp off turns it off.""" diff --git a/tools/test_settings_register.py b/tools/test_settings_register.py index af7b6cb2eb..3f8abac12c 100644 --- a/tools/test_settings_register.py +++ b/tools/test_settings_register.py @@ -80,7 +80,7 @@ class LaunchSettings(unittest.TestCase): def test_ling_options_are_all_there(self): names = {e["name"] for e in sr.launch_settings() if e.get("family") == "ling-3.2-air"} - for want in ("--thinking on|off", "--tier auto|A|B|C", "--vram-budget-gib N", "--ram-budget-gib N", "--turbo-ssd", "--cpu-coexec N", "--mtp on/off", "--map-experts", + for want in ("--thinking on|off", "--tier auto|A|B|C", "--vram-budget-gib N", "--ram-budget-gib N", "--turbo-ssd", "--cpu-coexec N", "--mtp auto/on/off", "--map-experts", "STRATA_LING32_SOURCE", "STRATA_LING32_SHOW"): self.assertIn(want, names) self.assertFalse([n for n in names if "dfly" in n.lower()]) # no DFly for Ling