serve: the qualified GDN speedups are on from the server (Linux CUDA: GDN_TC + GDN_CONVL2=2; Linux HIP gfx12 only: GDN_CHUNKED), Qwen3.8 only, explicit env wins

This commit is contained in:
Niko1221 committed 2026-10-30 22:46:09 +01:00
1 parent 7851a8dab6
commit bee469c462
2 files changed
+83

No files matched your search

+33
View File
@@ -3712,6 +3712,38 @@ def parallel_stack_env(env: dict, cfg: dict) -> None:
env.setdefault(k, v)
# 0.2.9: the qualified GDN prompt speedups (QUAL-GDN, Qwen3.8 IQ3_S). Linux only.
# CUDA: STRATA_GDN_TC=1 (the recurrence scan on the tensor cores) + STRATA_GDN_CONVL2=2 (conv, SiLU and q/k norm in one pass):
# KL mean 0.0019 / max 0.0125, 61-task suite 55 vs 54, prompt +4.4% at 4K, +5.5% at 16K, +5.7% at 32K (l620). The engine
# gates TC at run time (compute capability 8 or more, one SM per value head, shared memory) and falls back to the old
# kernels on anything else, so an older card or a CUDA 12 build simply does not use it.
# AMD gfx12 (RDNA4) only: STRATA_GDN_CHUNKED=1 (the chunked recurrence on the matrix cores): KL mean 0.0025, suite 55 vs 56,
# +3.5% at 4K, +5.5% at 16K (R9700). The same variable also turns the gfx11 path on in the engine and only gfx12 was
# qualified, so it is set only when every card the engine will see is gfx12.
# Other engines (Qwen3.6, DeepSeek), SYCL, Metal, Vulkan, Windows: nothing. An explicit variable (or the config's env) wins.
GDN_STACK_CUDA = {"STRATA_GDN_TC": "1", "STRATA_GDN_CONVL2": "2"}
GDN_STACK_GFX12 = {"STRATA_GDN_CHUNKED": "1"}
def gdn_stack_env(env: dict, cfg: dict, archs: dict | None = None) -> None:
if not parallel_stack_platform(): # Linux only (same rule as the parallel stack)
return
if (cfg.get("arch") or "qwen4exp") != "qwen4exp" or cfg.get("backend") in ("sycl", "metal", "vulkan"):
return # only the model the numbers are from
if cfg.get("backend") != "hip":
for k, v in GDN_STACK_CUDA.items():
env.setdefault(k, v)
return
ar = archs if archs is not None else hip_gpu_archs()
if not ar:
return # cannot tell the card: leave AMD out
want = hip_visible(cfg) or list(ar)
seen = [ar.get(i, "") for i in want]
if seen and all(a.startswith("gfx12") for a in seen):
for k, v in GDN_STACK_GFX12.items():
env.setdefault(k, v)
def child_env(cfg: dict, *, offline: bool = False) -> dict:
"""The engine's environment: the CUDA libraries setup installed (pip's nvidia packages, or the toolkit that
compiled it) first on the library search path."""
@@ -3729,6 +3761,7 @@ def child_env(cfg: dict, *, offline: bool = False) -> dict:
if (cfg.get("arch") or "") == "deepseek41": # (only this engine reads these; Qwen's environment is untouched)
deepseek_slot_env(env, cfg)
parallel_stack_env(env, cfg)
gdn_stack_env(env, cfg)
# Strict offline reaches children through the environment, because a tool subprocess or a model
# loader is code this server does not own. Applied last so a profile's own `env` cannot remove
# the policy by naming the same variable.
+50
View File
@@ -847,5 +847,55 @@ class ParallelStackDefaults(unittest.TestCase):
self.assertNotIn("STRATA_CKPT_POOL", self.env_for({"parallel": 8, "args": [], "arch": "deepseek41"}))
self.assertNotIn("STRATA_CKPT_POOL", self.env_for({"parallel": 8, "args": [], "backend": "sycl"}))
class GdnStackDefaults(unittest.TestCase):
"""The qualified GDN speedups are on from the server (Linux CUDA; Linux HIP gfx12 only); an explicit value wins."""
def env_for(self, cfg, archs=None, linux=True, base=None):
import os
from unittest import mock
env = {k: v for k, v in (base or {}).items()}
with mock.patch.object(server, "parallel_stack_platform", return_value=linux):
server.gdn_stack_env(env, cfg, archs)
return env
def test_cuda_on(self):
for cfg in ({"backend": "cuda"}, {}, {"arch": "qwen4exp"}):
env = self.env_for(cfg)
self.assertEqual(env.get("STRATA_GDN_TC"), "1")
self.assertEqual(env.get("STRATA_GDN_CONVL2"), "2")
self.assertNotIn("STRATA_GDN_CHUNKED", env)
def test_explicit_wins(self):
env = self.env_for({}, base={"STRATA_GDN_TC": "0"})
self.assertEqual(env["STRATA_GDN_TC"], "0")
self.assertEqual(env["STRATA_GDN_CONVL2"], "2")
def test_other_models_and_backends_off(self):
for cfg in ({"arch": "qwen35moe"}, {"arch": "deepseek41"}, {"backend": "sycl"}, {"backend": "metal"}, {"backend": "vulkan"}):
self.assertEqual(self.env_for(cfg), {}, cfg)
def test_windows_and_mac_off(self):
self.assertEqual(self.env_for({}, linux=False), {})
self.assertEqual(self.env_for({"backend": "hip"}, archs={0: "gfx1201"}, linux=False), {})
def test_hip_gfx12_only(self):
hip = {"backend": "hip", "gpu": [0, 1]}
env = self.env_for(hip, archs={0: "gfx1201", 1: "gfx1200"})
self.assertEqual(env, {"STRATA_GDN_CHUNKED": "1"}) # and nothing of the CUDA pair
for archs in ({0: "gfx1100", 1: "gfx1100"}, {0: "gfx1151"}, {0: "gfx1030", 1: "gfx1030"}, {0: "gfx1201", 1: "gfx1151"}, {}, None):
self.assertEqual(self.env_for(hip, archs=archs), {}, archs)
def test_hip_selected_cards_decide(self):
cfg = {"backend": "hip", "gpu": [1]}
self.assertEqual(self.env_for(cfg, archs={0: "gfx1151", 1: "gfx1201"}), {"STRATA_GDN_CHUNKED": "1"})
cfg = {"backend": "hip", "gpu": [0]}
self.assertEqual(self.env_for(cfg, archs={0: "gfx1151", 1: "gfx1201"}), {})
def test_child_env_wiring(self):
from unittest import mock
with mock.patch.object(server, "parallel_stack_platform", return_value=True):
env = server.child_env({"args": []})
self.assertEqual(env.get("STRATA_GDN_TC"), "1")
if __name__ == "__main__":
unittest.main()