mirror of
https://github.com/Niko1221/Strata.git
synced 2026-12-06 00:08:52 +00:00
launch: Qwen4's "fit to your card" requests use the card's real backend, so AMD, Metal and Intel get one request unless a person asked
runner.fit_parallel_for asked qwen4_family.parallel_for(..., backend="cuda") whatever the card was. ensure_profile wrote the answer into the launch profile (parallel=16 on a Strix Halo) and the server, which adds --parallel for an engine that takes it (0.1.75.1), started 16 slots: the documented rule "AMD is not measured: 1 request" was bypassed. fit_parallel_for takes the backend; Runner.ensure_profile passes the run config's own `backend` (setup writes it for everything but cuda), else the detected one. The Terminal's Parallel line shows the same number. An explicit --parallel still wins; cuda keeps its measured number. Runner.loop_backend (the detected backend for the Loop table and for parallel_offered in ensure_profile) used a module name that was never imported there, so its NameError was swallowed and every computer counted as cuda. It now goes through engine_backend(). The server (serve/qwen4_kind.py) and the app host (qwen4ParallelFor, qwen4ParallelDefault) already read the config's backend and are not changed.
This commit is contained in:
1 parent
4d2338ae0e
commit
ca1be5afc2
3 files changed
+157
-11
No files matched your search
@@ -519,7 +519,16 @@ def installed_cards(base: dict | None, usable: list[dict] | None = None) -> list
|
||||
return cards or None
|
||||
|
||||
|
||||
def fit_parallel_for(catalog, s: S.LaunchSettings, vram_gb: float | None) -> int:
|
||||
def engine_backend() -> str | None:
|
||||
"""The engine backend of this computer ("cuda" / "hip" / "metal" / "sycl") as engine_component detects it; None when it cannot be told (that counts as cuda)."""
|
||||
try:
|
||||
from strata_control import engine_component
|
||||
return engine_component.detect_backend()[0]
|
||||
except Exception: # noqa: BLE001 - no tool to ask: the default
|
||||
return None
|
||||
|
||||
|
||||
def fit_parallel_for(catalog, s: S.LaunchSettings, vram_gb: float | None, backend: str | None = None) -> int:
|
||||
""""Fit to your card": the VRAM table (S.fit_parallel), except for a model with an engine path of its own (Qwen3.6-35B-A3B), whose
|
||||
engine refuses to start when the slots' sessions do not fit (#5239: 3 slots planned at 128K on a 24 GB card, 5.56 GiB each, the start
|
||||
failed after the download): there setup's own rule for that model and context decides (own_path_parallel_recommend; 0 = one at a time),
|
||||
@@ -529,7 +538,7 @@ def fit_parallel_for(catalog, s: S.LaunchSettings, vram_gb: float | None) -> int
|
||||
from strata_control import qwen4_family
|
||||
build = str(s.model) if str(s.model) in qwen4_family.BUILDS else None
|
||||
if build is not None: # a .strata build: the Qwen4 table (placeholders: 1), 1 with Loop on; the GGUF build keeps the generic rule
|
||||
return qwen4_family.parallel_for(build, vram_gb, s.context, str(s.loop or "").lower() == "on", backend="cuda") # (ensure_profile drops it for a backend that is not on the standalone host)
|
||||
return qwen4_family.parallel_for(build, vram_gb, s.context, str(s.loop or "").lower() == "on", backend=backend or "cuda") # the card's own backend: AMD (hip) is not measured, so 1 there (ensure_profile drops it for a backend that is not on the standalone host); None = cuda
|
||||
if s.family == "inkling-2-mini":
|
||||
# Every slot reserves K/V for the whole context; slots whose fp16 K/V does not fit next to the experts spill it to host RAM and a long session
|
||||
# reads half of it over PCIe (Olares, 3 slots at 32K on 24 GB: decode 86 -> 44 tok/s after 30K tokens). The table's number, but no more
|
||||
@@ -1849,10 +1858,7 @@ class Runner:
|
||||
|
||||
def loop_backend(self) -> str | None:
|
||||
"""The engine backend of this computer ("cuda" / "hip" / "metal"), for the Loop table (qwen4_family.LOOP_READY); None when it cannot be told (that counts as cuda)."""
|
||||
try:
|
||||
return engine_component.detect_backend()[0]
|
||||
except Exception: # noqa: BLE001 - no tool to ask: the default
|
||||
return None
|
||||
return engine_backend() # (the module had no `engine_component` name here: the NameError was swallowed and every computer counted as cuda)
|
||||
|
||||
def other_copy(self) -> Path | None:
|
||||
"""The data folder of an installed copy of this model that this launch does not use, else None: another --data-dir was given, and the
|
||||
@@ -2717,7 +2723,7 @@ class Runner:
|
||||
def ensure_profile(self, config: Path) -> None:
|
||||
from strata_control import profiles
|
||||
name = self.profile
|
||||
parallel = self.s.parallel if self.s.parallel else (getattr(self, "four_card_parallel", None) or self.catalog_parallel())
|
||||
parallel = self.s.parallel if self.s.parallel else (getattr(self, "four_card_parallel", None) or self.catalog_parallel(config))
|
||||
if self.is_hy4() or self.is_ling32():
|
||||
parallel = None # one request at a time (the engine has no slots)
|
||||
if self.is_qwen4():
|
||||
@@ -2760,10 +2766,21 @@ class Runner:
|
||||
return False
|
||||
return "--batch" in args or "--slots" in args
|
||||
|
||||
def catalog_parallel(self) -> int | None:
|
||||
def run_backend(self, config: Path | None = None) -> str | None:
|
||||
"""The backend this launch's engine runs on: the run config's own `backend` (setup writes it for everything but cuda), else the one detected on this computer; None counts as cuda."""
|
||||
if config is not None:
|
||||
try:
|
||||
saved = read_config(config).get("backend")
|
||||
except Exception: # noqa: BLE001
|
||||
saved = None
|
||||
if isinstance(saved, str) and saved.strip():
|
||||
return saved.strip().lower()
|
||||
return self.loop_backend()
|
||||
|
||||
def catalog_parallel(self, config: Path | None = None) -> int | None:
|
||||
try:
|
||||
comp = self.catalog.computer()
|
||||
return fit_parallel_for(self.catalog, self.s, comp.main_vram_gb) if comp.usable_gpus else None
|
||||
return fit_parallel_for(self.catalog, self.s, comp.main_vram_gb, self.run_backend(config)) if comp.usable_gpus else None
|
||||
except Exception: # noqa: BLE001
|
||||
return None
|
||||
|
||||
|
||||
@@ -2027,7 +2027,7 @@ class SaveScreen(Base):
|
||||
def summary_lines(self) -> list[tuple[str, str]]:
|
||||
s = self.ctx.settings
|
||||
from strata_cli.launch import modelstate
|
||||
from strata_cli.launch.runner import fit_parallel_for
|
||||
from strata_cli.launch.runner import engine_backend, fit_parallel_for
|
||||
is_hy4 = s.family == "hy4-flash"
|
||||
is_inkling = s.family == "inkling-2-mini"
|
||||
is_native_strata = is_hy4 or is_inkling
|
||||
@@ -2043,7 +2043,7 @@ class SaveScreen(Base):
|
||||
[("Drafting", dict(DraftingScreen.CHOICES).get(s.drafting or ("off" if modelstate.layer_off_without_choice(self.ctx.base_config()) else "auto"), "Auto (recommended)"))] if drafting_choice_available(self.ctx) else []),
|
||||
*([("Parallel", f"{s.parallel} at a time" if s.parallel else f"fit to your card ({8 if (self.ctx.computer.main_vram_gb or 0) >= 22 else 4 if (self.ctx.computer.main_vram_gb or 0) >= 15 else 1})")] if is_inkling else
|
||||
[] if is_hy4 else [
|
||||
("Parallel", f"{s.parallel} at a time" if s.parallel else f"fit to your card ({fit_parallel_for(self.ctx.catalog, s, self.ctx.computer.main_vram_gb)})"),
|
||||
("Parallel", f"{s.parallel} at a time" if s.parallel else f"fit to your card ({fit_parallel_for(self.ctx.catalog, s, self.ctx.computer.main_vram_gb, engine_backend())})"),
|
||||
("Tuning", {"quick": "quick (about 20 min)", "thorough": "thorough (up to 2 h)", "skip": "skipped"}[s.tune]),
|
||||
]),
|
||||
("Access", f"{S.ACCESS_WORDS[s.access]}, port {s.port}" + (", API key on" if s.api_key else ", no API key")),
|
||||
|
||||
@@ -0,0 +1,129 @@
|
||||
"""Qwen4's "fit to your card" requests and the backend: a card that is not NVIDIA gets one request at a time unless a person asked for more.
|
||||
|
||||
STRIX-HIP found it on the int-0227 head: runner.fit_parallel_for asked qwen4_family.parallel_for(..., backend="cuda") whatever the card was, ensure_profile wrote the
|
||||
answer (parallel=16 on a Strix Halo) into the launch profile, and the server adds `--parallel 16` for an engine that takes it. The documented rule is "AMD is not measured:
|
||||
1 request" (qwen4_family.parallel_for). Now the launch passes the backend of the run config (else the detected one). An explicit --parallel still wins.
|
||||
|
||||
python -m pytest tests/terminal/test_qwen4_parallel_backend.py
|
||||
"""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
import json
|
||||
import unittest
|
||||
from pathlib import Path
|
||||
from unittest import mock
|
||||
|
||||
from strata_cli.launch import settings as S
|
||||
from strata_cli.launch.runner import Runner, fit_parallel_for
|
||||
from strata_control import profiles
|
||||
from strata_control import qwen4_family as F
|
||||
from tests.terminal.launch_support import HW_12, Home, catalog
|
||||
import serve.server # noqa: F401
|
||||
|
||||
CARD24 = {"name": "NVIDIA GeForce RTX 3090", "vram_gb": 24.0, "usable": True, "vendor": "nvidia", "index": 0}
|
||||
HW_NVIDIA = {**HW_12, "ram_gb": 64.0, "disk_free_gb": 900.0, "engine_vendor": "nvidia", "gpus": [CARD24]}
|
||||
HALO = {"name": "AMD Radeon 8060S", "vram_gb": 96.0, "usable": True, "vendor": "amd", "arch": "gfx1151", "index": 0}
|
||||
HW_HALO = {**HW_12, "ram_gb": 128.0, "disk_free_gb": 900.0, "engine_vendor": "amd", "gpus": [HALO]}
|
||||
|
||||
CFG = {"exe": "component:strata-q4-lite/strata-q4-lite", "arch": "qwen4exp_q4_lite", "model_name": "qwen4-35b-a3b-compact", "port": 8080, "tokenizer": "/m/tok",
|
||||
"args": ["--model", "/m/Qwen4-35B-A3B-Compact.strata", "--ple-gguf", "/m/PLE-Q4.gguf", "--max-ctx", "32768"]}
|
||||
|
||||
|
||||
def ready():
|
||||
"""The engine takes --parallel (0.1.75.1 and later)."""
|
||||
return mock.patch.object(F, "strata_parallel_ready", lambda *a, **k: True)
|
||||
|
||||
|
||||
class FitNumber(unittest.TestCase):
|
||||
def setUp(self):
|
||||
self.home = Home().__enter__()
|
||||
self.addCleanup(self.home.__exit__, None, None, None)
|
||||
|
||||
def fit(self, backend, *, vram=24.0, loop=None, model="Compact"):
|
||||
s = S.LaunchSettings(family="qwen4-35b-a3b", model=model, context=32768, loop=loop)
|
||||
return fit_parallel_for(catalog(HW_NVIDIA), s, vram, backend)
|
||||
|
||||
def test_cuda_keeps_the_measured_number(self):
|
||||
with ready():
|
||||
want = F.parallel_for("Compact", 24.0, 32768, False, backend="cuda")
|
||||
self.assertGreater(want, 1, "the 24 GB card runs more than one request: the test would prove nothing otherwise")
|
||||
self.assertEqual(self.fit("cuda"), want)
|
||||
self.assertEqual(self.fit(None), want, "no backend named: cuda, as before")
|
||||
self.assertEqual(self.fit("CUDA"), want)
|
||||
|
||||
def test_hip_metal_and_sycl_get_one(self):
|
||||
with ready():
|
||||
for backend in ("hip", "metal", "sycl"):
|
||||
self.assertEqual(self.fit(backend), 1, backend)
|
||||
self.assertEqual(self.fit(backend, vram=96.0), 1, backend + " on a big card")
|
||||
|
||||
def test_loop_on_is_one_everywhere(self):
|
||||
with ready():
|
||||
self.assertEqual(self.fit("cuda", loop="on"), 1)
|
||||
|
||||
|
||||
class LaunchProfile(unittest.TestCase):
|
||||
"""What Runner.ensure_profile saves for a Qwen4 .strata build: the profile's `parallel` override."""
|
||||
|
||||
def setUp(self):
|
||||
self.home = Home().__enter__()
|
||||
self.addCleanup(self.home.__exit__, None, None, None)
|
||||
for patch in (mock.patch.object(Runner, "intel_chosen", lambda self: False), ready()):
|
||||
patch.start()
|
||||
self.addCleanup(patch.stop)
|
||||
|
||||
def overrides(self, cfg_backend, *, hw, parallel=None, detected=None):
|
||||
cfg = dict(CFG)
|
||||
if cfg_backend:
|
||||
cfg["backend"] = cfg_backend
|
||||
cfgfile = Path(self.home.base) / "cfg.json"
|
||||
cfgfile.write_text(json.dumps(cfg), encoding="utf-8")
|
||||
s = S.LaunchSettings(family="qwen4-35b-a3b", model="Compact", context=32768, tune="skip", parallel=parallel)
|
||||
r = Runner(s, catalog=catalog(hw))
|
||||
with mock.patch("strata_cli.launch.runner.engine_backend", lambda: detected):
|
||||
r.ensure_profile(cfgfile)
|
||||
prof, _rev = profiles.load(r.profile)
|
||||
return dict(prof.get("overrides") or {})
|
||||
|
||||
def test_cuda_writes_the_fitted_number_as_before(self):
|
||||
ov = self.overrides(None, hw=HW_NVIDIA, detected="cuda")
|
||||
self.assertEqual(ov.get("parallel"), F.parallel_for("Compact", 24.0, 32768, False, backend="cuda"))
|
||||
self.assertGreater(ov["parallel"], 1)
|
||||
|
||||
def test_hip_run_config_writes_no_more_than_one(self):
|
||||
ov = self.overrides("hip", hw=HW_HALO, detected="hip")
|
||||
self.assertIn(ov.get("parallel"), (None, 1), ov)
|
||||
|
||||
def test_the_run_configs_backend_decides_before_the_detected_one(self):
|
||||
self.assertIn(self.overrides("hip", hw=HW_HALO, detected="cuda").get("parallel"), (None, 1))
|
||||
self.assertGreater(self.overrides(None, hw=HW_NVIDIA, detected="cuda").get("parallel"), 1)
|
||||
|
||||
def test_no_saved_backend_uses_the_detected_one(self):
|
||||
self.assertIn(self.overrides(None, hw=HW_HALO, detected="hip").get("parallel"), (None, 1))
|
||||
|
||||
def test_metal_and_sycl_run_configs_write_no_more_than_one(self):
|
||||
for backend in ("metal", "sycl"):
|
||||
self.assertIn(self.overrides(backend, hw=HW_HALO, detected=backend).get("parallel"), (None, 1), backend)
|
||||
|
||||
def test_an_explicit_parallel_still_wins_on_hip(self):
|
||||
self.assertEqual(self.overrides("hip", hw=HW_HALO, parallel=4, detected="hip").get("parallel"), 4)
|
||||
|
||||
|
||||
class ServerSide(unittest.TestCase):
|
||||
"""The server's own rule (serve/qwen4_kind.py _with_parallel) already reads the config's backend: no --parallel unless asked on a card that is not NVIDIA."""
|
||||
|
||||
def test_hip_config_without_a_number_adds_no_parallel_flag(self):
|
||||
from serve import qwen4_kind
|
||||
base = ["--model", "/m/Qwen4-35B-A3B-Compact.strata", "--max-ctx", "32768"]
|
||||
with ready():
|
||||
hip = qwen4_kind._with_parallel(list(base), {"backend": "hip"}, "Compact", announce=False)
|
||||
self.assertNotIn("--parallel", hip)
|
||||
asked = qwen4_kind._with_parallel(list(base), {"backend": "hip", "parallel": 4}, "Compact", announce=False)
|
||||
self.assertEqual(asked[asked.index("--parallel") + 1], "4", "a person's number still goes through")
|
||||
one = qwen4_kind._with_parallel(list(base), {"backend": "hip", "parallel": 1}, "Compact", announce=False)
|
||||
self.assertNotIn("--parallel", one)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
unittest.main()
|
||||
Reference in new issue
Block a user