mirror of
https://github.com/Niko1221/Strata.git
synced 2026-12-05 07:48:45 +00:00
serve: the drafter is sized from the card the engine serves from on a mixed NVIDIA + AMD computer (#5109)
On a computer with an idle NVIDIA card beside the AMD card the engine runs on, detect_hardware() answers "cuda" with the NVIDIA card first, so the start's drafting decision took the NVIDIA card's support line and card class, and drafting_vram_mib read the NVIDIA card (the report: RTX 3060 12 GB beside an RX 7900 XTX: --draft-conf 0.8 where the XTX's 9,239 slots prescribe 0.5). drafting.hardware_for(cfg["backend"]): the config's engine family wins and only its own cards' architectures are kept; engine_args uses it for the backend, the archs, the card class and the VRAM read. A computer with one vendor's cards gets exactly what it got before. Tests: tests/terminal/test_drafting_mixed_vendor.py (5 fail on the base, pass here); the drafting suites (365 passed) and the server's drafting tests pass.
This commit is contained in:
1 parent
2af552efea
commit
188aaf7bf7
3 files changed
+87
-2
No files matched your search
+2
-2
@@ -3988,9 +3988,9 @@ def engine_args(cfg: dict, exe: str | None = None, *, announce: bool = True) ->
|
||||
# has it, on one card and on a layer split over several cards. A choice that cannot be applied (no drafter file yet, several requests at once) starts the other one if it is on this computer,
|
||||
# else none, and says why in the engine's /metrics ("drafting_note"). The start never downloads.
|
||||
shaped = {**cfg, "args": args}
|
||||
backend, archs = drafting.detect_hardware()
|
||||
backend, archs = drafting.hardware_for(cfg.get("backend")) # #5109: the config's engine family, not an idle card of another vendor
|
||||
parallel_n = cfg.get("parallel")
|
||||
decision = drafting.apply(shaped, klass=drafting_card_class(), data_dir=drafting.data_dir_of(args), backend=backend, archs=archs,
|
||||
decision = drafting.apply(shaped, klass=drafting.card_class(archs) if archs else drafting_card_class(), data_dir=drafting.data_dir_of(args), backend=backend, archs=archs,
|
||||
vram_mib=drafting_vram_mib(cfg, backend, archs),
|
||||
slots=parallel_n if isinstance(parallel_n, int) and not isinstance(parallel_n, bool) else 0, engine=exe)
|
||||
args = shaped["args"]
|
||||
|
||||
@@ -171,6 +171,23 @@ def detect_hardware() -> tuple[str | None, list[str]]:
|
||||
return _HARDWARE[0]
|
||||
|
||||
|
||||
#: the card architectures of each engine family, by name (detect_hardware lists every vendor's cards a computer has)
|
||||
_FAMILY_ARCH_PREFIX = {"cuda": "sm_", "hip": "gfx"}
|
||||
|
||||
|
||||
def hardware_for(engine_backend: str | None) -> tuple[str | None, list[str]]:
|
||||
"""#5109: detect_hardware() for a start whose config names its engine family (cfg["backend"]). On a computer with an NVIDIA card beside the AMD
|
||||
card the engine serves from, detect_hardware() answers "cuda" with the NVIDIA card first, so the drafter's support line, card class and
|
||||
confidence were the idle NVIDIA card's. The config's family wins, and only its own cards' architectures are kept (in detect_hardware's order).
|
||||
Without a known family (or for one whose cards are not named here): detect_hardware() unchanged."""
|
||||
backend, archs = detect_hardware()
|
||||
want = str(engine_backend or "").strip().lower()
|
||||
prefix = _FAMILY_ARCH_PREFIX.get(want)
|
||||
if not prefix:
|
||||
return backend, archs
|
||||
return want, [a for a in archs if str(a).lower().startswith(prefix)]
|
||||
|
||||
|
||||
def hardware_support(backend: str | None, archs: Any = None, model_name: str | None = None) -> Support:
|
||||
"""Can the engine for this backend and card run DFlash2, and what was measured on it. ``backend`` is the engine family (cuda | hip | sycl | metal);
|
||||
``archs`` the cards' architectures (``sm_120``, ``gfx1151``...), the first one counts like card_class does. ``model_name``: on Metal the answer is
|
||||
|
||||
@@ -0,0 +1,68 @@
|
||||
"""#5109: on a computer with an idle NVIDIA card beside the AMD card the engine serves from (an RTX 3060 next to an RX 7900 XTX; the lent
|
||||
RTX 3080 + RX 6700 XT test box), detect_hardware() answers "cuda" with the NVIDIA card first. The drafter's support line, card class and
|
||||
confidence must come from the engine's own family (the config's "backend"), not from the idle card. No GPU needed."""
|
||||
from __future__ import annotations
|
||||
|
||||
import sys
|
||||
import unittest
|
||||
from pathlib import Path
|
||||
from unittest import mock
|
||||
|
||||
ROOT = Path(__file__).resolve().parents[2]
|
||||
sys.path.insert(0, str(ROOT))
|
||||
|
||||
from strata_control import drafting # noqa: E402
|
||||
|
||||
MIXED = ("cuda", ["sm_86", "gfx1100"])
|
||||
|
||||
|
||||
class HardwareFor(unittest.TestCase):
|
||||
def test_the_config_family_wins_with_its_own_cards(self):
|
||||
with mock.patch.object(drafting, "detect_hardware", return_value=MIXED):
|
||||
self.assertEqual(drafting.hardware_for("hip"), ("hip", ["gfx1100"]))
|
||||
self.assertEqual(drafting.hardware_for("cuda"), ("cuda", ["sm_86"]))
|
||||
self.assertEqual(drafting.hardware_for("HIP"), ("hip", ["gfx1100"]))
|
||||
|
||||
def test_no_family_or_another_family_keeps_detect_hardware(self):
|
||||
with mock.patch.object(drafting, "detect_hardware", return_value=MIXED):
|
||||
self.assertEqual(drafting.hardware_for(None), MIXED)
|
||||
self.assertEqual(drafting.hardware_for(""), MIXED)
|
||||
self.assertEqual(drafting.hardware_for("metal"), MIXED)
|
||||
self.assertEqual(drafting.hardware_for("sycl"), MIXED)
|
||||
|
||||
def test_one_vendor_computers_are_unchanged(self):
|
||||
for hw, fam in ((("cuda", ["sm_120"]), "cuda"), (("hip", ["gfx1201"]), "hip"), (("hip", ["gfx1151"]), "hip")):
|
||||
with mock.patch.object(drafting, "detect_hardware", return_value=hw):
|
||||
self.assertEqual(drafting.hardware_for(fam), hw)
|
||||
|
||||
def test_class_and_support_follow_the_serving_card(self):
|
||||
with mock.patch.object(drafting, "detect_hardware", return_value=MIXED):
|
||||
backend, archs = drafting.hardware_for("hip")
|
||||
self.assertEqual(drafting.card_class(archs), drafting.card_class(["gfx1100"]))
|
||||
self.assertNotEqual(drafting.card_class(archs), drafting.card_class(["sm_86"]))
|
||||
self.assertEqual(drafting.hardware_support(backend, archs), drafting.hardware_support("hip", ["gfx1100"]))
|
||||
|
||||
|
||||
class ServerStart(unittest.TestCase):
|
||||
"""serve/server.py engine_args hands drafting.apply the serving card's family, cards and class."""
|
||||
|
||||
def test_engine_args_on_a_mixed_computer(self):
|
||||
from serve import server
|
||||
seen = {}
|
||||
|
||||
def apply(shaped, **kw):
|
||||
seen.update(kw)
|
||||
return mock.Mock(note="", flags=[], vocab="", drafter="off")
|
||||
with mock.patch.object(drafting, "detect_hardware", return_value=MIXED), mock.patch.object(drafting, "apply", side_effect=apply), \
|
||||
mock.patch.object(server, "drafting_vram_mib", return_value=24560.0):
|
||||
try:
|
||||
server.engine_args({"args": ["--max-context", "4096"], "backend": "hip"}, announce=False)
|
||||
except Exception: # noqa: BLE001 - only the drafting call is under test here
|
||||
pass
|
||||
self.assertEqual(seen.get("backend"), "hip")
|
||||
self.assertEqual(seen.get("archs"), ["gfx1100"])
|
||||
self.assertEqual(seen.get("klass"), drafting.card_class(["gfx1100"]))
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
unittest.main()
|
||||
Reference in new issue
Block a user