Skip to content

Qwen3.8-Flash-Next on any consumer hardware: one-click install for Windows / Linux. Strata inference engine, OpenAI/Anthropic API on localhost, optional image input.

C++

serve: the frozen-engine check does not end an engine whose GPU is busy (telemetry reading)

Niko12215aee72b10764
diff --git a/serve/server.py b/serve/server.py
index 6ea3b79d8..589a88d64 100644
--- a/serve/server.py
+++ b/serve/server.py
@@ -578,6 +578,7 @@ class StrataEngine:
"""
silence_s = ENGINE_SILENCE_S # #481: main() sets the config's engine_silence_s (survives restart())
silent_note = None # #481: why the server ended a silent engine (death_note says it)
+ gpu_busy = None # #1317: () -> bool, "the GPU is working" (the telemetry's reading); a GPU at work is not frozen
last_err = None # #997: an ERR that was its last stdout line (death_note says it)
batch = 0 # --batch: the engine's batch slots (0: one request at a time)
@@ -1577,7 +1578,11 @@ class StrataEngine:
if age < state.get("next", stall_s) or state["base"] is None:
return
now = self._activity()
- if now is not None and engine_frozen(state["base"], now):
+ try:
+ gpu_working = bool(self.gpu_busy()) if self.gpu_busy is not None else False
+ except Exception: # noqa: BLE001 - a telemetry hiccup must not decide anything
+ gpu_working = False
+ if now is not None and not gpu_working and engine_frozen(state["base"], now):
raise self._silent(f"the engine said nothing for {age:.0f} s and used no CPU or disk in that time (frozen; "
"STRATA_ENGINE_STALL_S sets this, 0 = off)")
if now is not None: # working: look again after another window from here, and say so once
@@ -2845,6 +2850,10 @@ class Service:
gpu_index=int(getattr(self, "gpu_index", 0) or 0),
gpu_indices=getattr(self, "gpu_indices", None),
amd=getattr(self, "backend", None) == "hip")
+ if getattr(self, "engine", None) is not None and hasattr(self.engine, "gpu_busy"):
+ # #1317: the quick frozen-engine check does not end an engine whose GPU is busy (a long prompt chunk on a
+ # slow card keeps the GPU at work while the host thread sleeps)
+ self.engine.gpu_busy = lambda: (self.telemetry.snapshot()["now"].get("gpu_util") or 0) >= 10
def _tok_s(self):
"""tok/s over the last RATE_WINDOW_S seconds. Returns 0.0 while nothing is generating. With parallel requests:
diff --git a/serve/test_server.py b/serve/test_server.py
index fd7020508..3de8c96dc 100644
--- a/serve/test_server.py
+++ b/serve/test_server.py
@@ -3971,6 +3971,17 @@ class SilentEngine(unittest.TestCase):
self.assertEqual(list(engine.generate([1], 10, {}, threading.Event())), [7])
engine.proc.kill.assert_not_called()
+ def test_a_busy_gpu_is_not_a_frozen_engine(self):
+ # #1317: no CPU and no disk, but the GPU is at work (a long prompt chunk on a slow card): not ended
+ from serve import server
+ engine = self.bare(300.0)
+ engine._activity = lambda: (12.0, 4096)
+ engine.gpu_busy = lambda: True
+ self.later(engine, 2.5, "T 7", "DONE 1 1 1 1 length")
+ with mock.patch.object(server, "ENGINE_STALL_S", 1.0):
+ self.assertEqual(list(engine.generate([1], 10, {}, threading.Event())), [7])
+ engine.proc.kill.assert_not_called()
+
def test_no_reading_means_no_kill_and_zero_is_off(self):
from serve import server
for stall, act in ((1.0, lambda: None), (0, lambda: (1.0, 1))):