Fast local LLM inference on plain CPUs. No GPU, 8 GB of RAM. OpenAI-compatible server.
Python aiavx512cpu-inferenceedge-aiggufinference-enginellama-cppllmllm-inferencelocal-ailocal-llmno-gpuon-device-aiopenai-apiopenai-compatiblequantizationqwenself-hostedspeculative-decodingternary
fix(bench): stop request samplers on every exit path (#38)
Afloat149a4b444707
diff --git a/bench/bench2.py b/bench/bench2.pyindex 42411a9..e92b660 100644--- a/bench/bench2.py+++ b/bench/bench2.py@@ -193,7 +193,9 @@ def main() -> None:if proc.poll() is not None:port, proc, log = start(arm, arms[arm], logdir, f"r{a.rep}b{bi}x")continue- smp.halt = True+ finally:+ smp.halt = True+ smp.join()msg = r["choices"][0]["message"]reasoning = msg.get("reasoning_content") or ""try:diff --git a/bench/test_sampler_cleanup.py b/bench/test_sampler_cleanup.pynew file mode 100644index 0000000..721f8a3--- /dev/null+++ b/bench/test_sampler_cleanup.py@@ -0,0 +1,60 @@+import contextlib+import io+import json+import os+from pathlib import Path+import tempfile+import unittest+from unittest.mock import Mock, patch++import bench2+++class SamplerCleanupTest(unittest.TestCase):+ def run_benchmark(self, fail):+ samplers = []+ sampler_type = bench2.Sampler++ def sample(pid):+ sampler = sampler_type(pid)+ samplers.append(sampler)+ return sampler++ with tempfile.TemporaryDirectory() as directory:+ root = Path(directory)+ (root / "arms.json").write_text(json.dumps({"test": {"cmd": "unused"}}))+ (root / "prompts.jsonl").write_text(json.dumps({"id": "one", "task": "test", "messages": []}) + "\n")+ argv = ["bench2.py", "--arms", str(root / "arms.json"), "--prompts",+ str(root / "prompts.jsonl"), "--out", str(root / "results.jsonl")]+ proc = Mock(pid=os.getpid())+ proc.poll.return_value = None+ reply = {"choices": [{"message": {"content": "ok"}}], "timings": {}}+ try:+ with patch.object(bench2.sys, "argv", argv), \+ patch.object(bench2, "start", return_value=(1, proc, "unused")), \+ patch.object(bench2, "stop"), patch.object(bench2, "post"), \+ patch.object(bench2, "tokenize", return_value=[]), \+ patch.object(bench2, "majfaults", return_value=0), \+ patch.object(bench2, "Sampler", side_effect=sample), \+ patch.object(bench2, "request", side_effect=RuntimeError("request failed") if fail else None,+ return_value=(reply, "ok", 0.1)), \+ contextlib.redirect_stdout(io.StringIO()), contextlib.redirect_stderr(io.StringIO()):+ bench2.main()+ self.assertEqual(len(samplers), 1)+ self.assertFalse(samplers[0].is_alive(), "request sampler must stop before the next request")+ row = json.loads((root / "results.jsonl").read_text())+ self.assertEqual("error" in row, fail)+ finally:+ for sampler in samplers:+ sampler.halt = True+ sampler.join(timeout=2)++ def test_failed_request_stops_sampler(self):+ self.run_benchmark(True)++ def test_successful_request_joins_sampler(self):+ self.run_benchmark(False)+++if __name__ == "__main__":+ unittest.main()