Skip to content

Run frontier MoE models on hardware you already own — pure C, zero deps, experts streamed from disk. Tiny engine, immense model. 🐦

C

serve: say why the engine dispatcher stopped (#1941)

JustVugg5611276dfe8c
diff --git a/c/openai_server.py b/c/openai_server.py
index 419f0ef7..5463051c 100644
--- a/c/openai_server.py
+++ b/c/openai_server.py
@@ -4723,6 +4723,19 @@ def _engine_extension_args(engine_k):
return {"logprobs": engine_k, "gbytes_before_ext": True}
+def engine_exit_status(status):
+ """A child's exit status in words: a signal on POSIX (a SIGKILL is most often the
+ out-of-memory killer), the NTSTATUS on Windows."""
+ if status < 0:
+ name = {9: "SIGKILL, most often the out-of-memory killer", 11: "SIGSEGV", 6: "SIGABRT"}.get(-status)
+ return f"killed by signal {-status}" + (f", {name}" if name else "")
+ if status >= 0xC0000000:
+ name = {0xC0000005: "access violation", 0xC0000017: "out of memory", 0xC00000FD: "stack overflow",
+ 0xC0000409: "fail-fast or stack buffer overrun"}.get(status)
+ return f"exit status 0x{status:08X}" + (f", {name}" if name else "")
+ return f"exit status {status}"
+
+
class EngineLoadError(RuntimeError):
"""The engine said why it could not load, and exited before READY.
@@ -5629,9 +5642,24 @@ class Engine:
raise RuntimeError(f"invalid engine response: {' '.join(fields)}")
except Exception as error:
if not self.closed:
+ error = self._dispatcher_cause(error)
self.dispatcher_error = error
+ print(f"colibri: the engine dispatcher stopped: {error}", file=sys.stderr)
self._fail_pending(error)
+ def _dispatcher_cause(self, error):
+ """The dispatcher's error, with the engine's exit status when the engine is gone:
+ every later request fails with it, and the log used to say only "dispatcher
+ stopped" (#1941)."""
+ try:
+ gone = str(error) == "colibri engine exited unexpectedly"
+ status = self.process.wait(timeout=2) if gone else self.process.poll()
+ except Exception:
+ status = None
+ if status is None:
+ return error
+ return RuntimeError(f"{error} ({engine_exit_status(status)})")
+
def decide(self, record, cache_slot=0, cancelled=None):
"""One DECIDE round trip: the record out, the engine's DECISION back.
@@ -5650,7 +5678,8 @@ class Engine:
if self.closed:
raise RuntimeError("colibri engine is shutting down")
if self.dispatcher_error is not None:
- raise RuntimeError("colibri engine dispatcher stopped") from self.dispatcher_error
+ raise RuntimeError(f"colibri engine dispatcher stopped: {self.dispatcher_error}") \
+ from self.dispatcher_error
if self.process.poll() is not None:
raise RuntimeError("colibri engine is not running")
request_id = str(self.next_request_id)
@@ -5728,7 +5757,8 @@ class Engine:
if self.closed:
raise RuntimeError("colibri engine is shutting down")
if self.dispatcher_error is not None:
- raise RuntimeError("colibri engine dispatcher stopped") from self.dispatcher_error
+ raise RuntimeError(f"colibri engine dispatcher stopped: {self.dispatcher_error}") \
+ from self.dispatcher_error
if self.process.poll() is not None:
raise RuntimeError("colibri engine is not running")
request_id = str(self.next_request_id)
diff --git a/c/tests/test_openai_server.py b/c/tests/test_openai_server.py
index 91b6d24b..87a8ef7b 100644
--- a/c/tests/test_openai_server.py
+++ b/c/tests/test_openai_server.py
@@ -17,7 +17,7 @@ from pathlib import Path
import openai_server
from family_registry import family_by_id, family_ids
-from openai_server import (APIError, APIHandler, APIServer, ClientCancelled,
+from openai_server import (APIError, engine_exit_status, APIHandler, APIServer, ClientCancelled,
CONTINUATION_FAMILIES, _marker_cuts,
DEFAULT_CHAT_STOP_SEQUENCES, END, GenerationScheduler,
LOGPROBS_TOP_K_CAP, logprobs_options,
@@ -2229,10 +2229,31 @@ class DispatcherTest(unittest.TestCase):
engine = Engine("glm", "model")
with self.assertRaisesRegex(RuntimeError, "DATA size"):
engine.generate("hello", 4, 0.7, 0.9, lambda _: None)
- with self.assertRaisesRegex(RuntimeError, "dispatcher stopped"):
+ # the cause comes with every later failure, not only "dispatcher stopped" (#1941)
+ with self.assertRaisesRegex(RuntimeError, "dispatcher stopped: .*DATA size"):
engine.generate("again", 4, 0.7, 0.9, lambda _: None)
engine.close()
+ def test_an_engine_that_dies_names_its_exit_status(self):
+ def respond(process, frame):
+ process.returncode = -9 # the out-of-memory killer, as #1941 may have met
+ process.stdout.close()
+
+ process = FakeProcess(respond)
+ with patch("openai_server.subprocess.Popen", return_value=process):
+ engine = Engine("glm", "model")
+ with self.assertRaisesRegex(RuntimeError, "exited unexpectedly .*signal 9, SIGKILL"):
+ engine.generate("hello", 4, 0.7, 0.9, lambda _: None)
+ with self.assertRaisesRegex(RuntimeError, "dispatcher stopped: .*signal 9"):
+ engine.generate("again", 4, 0.7, 0.9, lambda _: None)
+ engine.close()
+
+ def test_engine_exit_status_words(self):
+ self.assertEqual(engine_exit_status(1), "exit status 1")
+ self.assertIn("SIGKILL", engine_exit_status(-9))
+ self.assertEqual(engine_exit_status(0xC0000005), "exit status 0xC0000005, access violation")
+ self.assertEqual(engine_exit_status(0xC0000017), "exit status 0xC0000017, out of memory")
+
def test_decodes_utf8_split_across_data_frames(self):
def respond(process, frame):
request_id = frame.split()[1]