From 2a9ccfe3ea684256b788fda140a2bc6263e16b6e Mon Sep 17 00:00:00 2001 From: Niko1221 Date: Fri, 30 Oct 2026 19:07:47 +0100 Subject: [PATCH] serve: the parallel stack default only where it was run (Linux CUDA nine switches, Linux HIP seven, nothing on Windows or macOS) --- serve/server.py | 13 +++++++++++++ serve/test_parallel.py | 13 +++++++++++-- 2 files changed, 24 insertions(+), 2 deletions(-) diff --git a/serve/server.py b/serve/server.py index 329bc7ea..1db90f4c 100644 --- a/serve/server.py +++ b/serve/server.py @@ -3677,6 +3677,9 @@ PARALLEL_STACK_ENV = { "STRATA_SLOT_COPY_BATCHSYNC": "1", "STRATA_BATCH_GDN_GROUPS": "1", "STRATA_BATCH_ATTN_ROWS": "1", "STRATA_BATCH_SELF_COMMIT": "1", "STRATA_QSA_SLOTS": "1", } +# Only where the stack was run: Linux CUDA all nine; Linux HIP seven (the two one-launch-for-all-rows switches were not run there); +# nothing on Windows (no run; its host-arena / pinned-memory path differs). +PARALLEL_STACK_NOT_HIP = ("STRATA_BATCH_GDN_GROUPS", "STRATA_BATCH_ATTN_ROWS") def parallel_slots(cfg: dict) -> int: @@ -3692,12 +3695,22 @@ def parallel_slots(cfg: dict) -> int: return n if isinstance(n, int) and not isinstance(n, bool) and n > 1 else 0 +def parallel_stack_platform() -> bool: + """Linux only: the stack was run on Linux CUDA and HIP; Windows (own host-arena path) and macOS were not.""" + return sys.platform.startswith("linux") + + def parallel_stack_env(env: dict, cfg: dict) -> None: """Switch the exact parallel stack on (setdefault: a value the user or the config set stays) when the config runs batch slots on a CUDA or HIP Qwen engine. Other engines (DeepSeek, SYCL, Metal) do not read these.""" if parallel_slots(cfg) < 2 or (cfg.get("arch") or "") == "deepseek41" or cfg.get("backend") in ("sycl", "metal", "vulkan"): return + if not parallel_stack_platform(): + return + hip = cfg.get("backend") == "hip" for k, v in PARALLEL_STACK_ENV.items(): + if hip and k in PARALLEL_STACK_NOT_HIP: + continue env.setdefault(k, v) diff --git a/serve/test_parallel.py b/serve/test_parallel.py index 1bd2fdae..497972ae 100644 --- a/serve/test_parallel.py +++ b/serve/test_parallel.py @@ -812,10 +812,10 @@ class ParallelService(FakeEngineCase): class ParallelStackDefaults(unittest.TestCase): """The exact parallel stack is the default with batch slots; an explicit value wins.""" - def env_for(self, cfg, base=None): + def env_for(self, cfg, base=None, linux=True): import os from unittest import mock - with mock.patch.dict(os.environ, base or {}, clear=False): + with mock.patch.dict(os.environ, base or {}, clear=False), mock.patch.object(server, "parallel_stack_platform", return_value=linux): for k in list(os.environ): if k in server.PARALLEL_STACK_ENV and not (base and k in base): del os.environ[k] @@ -823,10 +823,19 @@ class ParallelStackDefaults(unittest.TestCase): def test_on_with_parallel(self): env = self.env_for({"parallel": 8, "args": []}) + hip = self.env_for({"parallel": 8, "args": [], "backend": "hip"}) for k, v in server.PARALLEL_STACK_ENV.items(): self.assertEqual(env.get(k), v, k) + if k in server.PARALLEL_STACK_NOT_HIP: + self.assertNotIn(k, hip) # HIP: the stack as it was run (seven switches) + else: + self.assertEqual(hip.get(k), v, k) self.assertEqual(self.env_for({"args": ["--batch", "4"]}).get("STRATA_BATCH_SELF_COMMIT"), "1") + def test_off_on_windows_and_mac(self): + self.assertNotIn("STRATA_CKPT_POOL", self.env_for({"parallel": 8, "args": []}, linux=False)) + self.assertTrue(server.parallel_stack_platform.__doc__) + def test_off_without_slots(self): self.assertNotIn("STRATA_CKPT_POOL", self.env_for({"args": []})) self.assertNotIn("STRATA_CKPT_POOL", self.env_for({"parallel": 1, "args": []}))