Documented tree replacement (the history has no git-subtree metadata): 3-way merge of the old subtree (570201a:engine/strata) against upstream 41cf05a06a25dd29103b7b27a2279a3f60c21876 (2026-10-25), merge base = the old pin d9ab8435 (tree-identical to upstream 5b734e42; d9ab8435 is not an ancestor of upstream main). Local patches re-applied by hand where they conflicted (15 files): STRATA_CUDA_STATIC profile, experimental KAR experts and KAR PLE arms, keyless V-only arm (now beside upstream's K8V4 hybrid KV and fused norm+rope). Details, conflict table and left-out files are in docs/upstream.md. Left out (weights, captures, logs, media): new bench/results (2022 files), binary media and app assets (61), docs/work/evidence (24), *.bin / *.gguf data files, and the 7 files the first import already left out. scripts/build-cpu.sh: build the 11 CPU tests upstream registered since the old pin (they ran as "Not Run"). Checked: build-cpu.sh 16/16 ctest in WSL; sm_86 CUDA objects of the patched files compile, also with the KAR macros on. No GPU run, no quality gate. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
64 lines
3.4 KiB
Python
64 lines
3.4 KiB
Python
"""serve/server.py: the run settings' "gpu_roles" (Main / Helper / Off) become the engine's card list, Main LAST, Off left out."""
|
|
from __future__ import annotations
|
|
|
|
import sys
|
|
import unittest
|
|
from pathlib import Path
|
|
|
|
sys.path.insert(0, str(Path(__file__).resolve().parents[1]))
|
|
from serve.server import card_roles_lines, child_env, gpu_list, ordered_gpus # noqa: E402
|
|
|
|
|
|
class Roles(unittest.TestCase):
|
|
def test_roles_alone_give_the_order_main_last_and_off_left_out(self):
|
|
cfg = {"gpu_roles": {"0": "helper", "1": "main", "2": "off"}, "args": []}
|
|
self.assertEqual(gpu_list(cfg), [0, 1])
|
|
self.assertEqual(gpu_list({"gpu_roles": {"0": "main", "1": "helper"}, "args": []}), [1, 0])
|
|
env = child_env({"gpu_roles": {"0": "main", "1": "helper", "2": "off"}, "args": []})
|
|
self.assertEqual(env["CUDA_VISIBLE_DEVICES"], "1,0")
|
|
|
|
def test_the_mirror_is_used_and_never_re_sorted_by_speed(self):
|
|
cfg = {"gpu_roles": {"0": "main", "1": "helper"}, "gpu": [1, 0], "gpu_order": "as_given", "args": []}
|
|
self.assertEqual(ordered_gpus(cfg, {0: 1.0, 1: 9.0}), [1, 0]) # the faster card is Helper on purpose
|
|
cfg2 = {"gpu_roles": {"0": "main", "1": "helper"}, "gpu": [1, 0], "args": []} # even without gpu_order
|
|
self.assertEqual(ordered_gpus(cfg2, {0: 1.0, 1: 9.0}), [1, 0])
|
|
|
|
def test_one_card_on(self):
|
|
cfg = {"gpu_roles": {"0": "off", "1": "main"}, "gpu": 1, "gpu_order": "as_given", "args": []}
|
|
self.assertEqual(gpu_list(cfg), [1])
|
|
self.assertEqual(child_env(cfg)["CUDA_VISIBLE_DEVICES"], "1")
|
|
|
|
def test_a_hand_edited_gpu_wins(self):
|
|
cfg = {"gpu_roles": {"0": "helper", "1": "main"}, "gpu": [1, 0], "gpu_order": "as_given", "args": []}
|
|
self.assertEqual(gpu_list(cfg), [1, 0])
|
|
self.assertTrue(any("edited by hand" in l for l in card_roles_lines(cfg)))
|
|
self.assertEqual(ordered_gpus({**cfg, "gpu_order": None}, {0: 1.0, 1: 9.0}), [0, 1]) # the legacy rule again
|
|
|
|
def test_bad_roles_are_ignored(self):
|
|
for bad in ({"0": "boss"}, {"0": "main", "1": "main"}, "x", {}):
|
|
self.assertEqual(gpu_list({"gpu_roles": bad, "gpu": 1, "args": []}), [1])
|
|
|
|
def test_legacy_settings_are_untouched(self):
|
|
self.assertEqual(gpu_list({"gpu": "0,2", "args": []}), [0, 2])
|
|
self.assertEqual(gpu_list({"args": []}), [])
|
|
self.assertEqual(card_roles_lines({"gpu": [1, 0], "args": []}), [])
|
|
|
|
def test_the_log_line_names_every_role(self):
|
|
lines = card_roles_lines({"gpu_roles": {"0": "helper", "1": "main", "2": "off"}, "gpu": [0, 1], "args": []})
|
|
self.assertEqual(lines, ["[strata] card roles: Main GPU 1, Helper GPU 0, Off GPU 2 (numbers as nvidia-smi gives them)"])
|
|
|
|
def test_every_card_off(self):
|
|
cfg = {"gpu_roles": {"0": "off", "1": "off"}, "gpu": [], "gpu_none": True, "args": []}
|
|
self.assertEqual(gpu_list(cfg), [])
|
|
env = child_env(cfg)
|
|
self.assertEqual((env["CUDA_VISIBLE_DEVICES"], env["HIP_VISIBLE_DEVICES"]), ("", ""))
|
|
with self.assertRaises(SystemExit) as e:
|
|
card_roles_lines(cfg) # a CUDA engine cannot start without a card: said plainly
|
|
self.assertIn("Turn a card on", str(e.exception))
|
|
cpu = card_roles_lines({**cfg, "backend": "cpu"})
|
|
self.assertIn("Performance is degraded on CPU only.", cpu[0])
|
|
|
|
|
|
if __name__ == "__main__":
|
|
unittest.main()
|