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): keep multi-stream rounds populated after round three (#44)
Afloat6f1623327534
diff --git a/bench/multi.py b/bench/multi.pyindex 67ee1ea..196912c 100644--- a/bench/multi.py+++ b/bench/multi.py@@ -28,14 +28,18 @@ def req(port, p, out, i):def main():ap = argparse.ArgumentParser()ap.add_argument("--out", required=True)- ap.add_argument("--rounds", type=int, default=3)+ ap.add_argument("--rounds", type=int, default=3, help="positive round count; prompts cycle after the first three rounds")a = ap.parse_args()+ if a.rounds < 1:+ ap.error("--rounds must be positive")os.makedirs(a.out, exist_ok=True)P = [json.loads(l) for l in open("prompts24.jsonl")]P = [p for p in P if not p["id"].startswith("code-")][:12] # short prompts: the 2k-per-stream context fits+ if len(P) < 4:+ ap.error("need at least four non-code prompts for the four-stream comparison")f = open(os.path.join(a.out, "multi.jsonl"), "a")for rd in range(a.rounds):- ps = P[rd * 4:(rd + 1) * 4]+ ps = [P[(rd * 4 + i) % len(P)] for i in range(4)]order = list(ARMS)random.Random(f"m{rd}").shuffle(order)for arm in order:diff --git a/bench/test_multi_rounds.py b/bench/test_multi_rounds.pynew file mode 100644index 0000000..b91f9a7--- /dev/null+++ b/bench/test_multi_rounds.py@@ -0,0 +1,61 @@+import contextlib+import io+import json+import os+from pathlib import Path+import tempfile+import time+import unittest+from unittest.mock import Mock, patch++import multi+++class MultiRoundTest(unittest.TestCase):+ def run_rounds(self, rounds, count=12):+ with tempfile.TemporaryDirectory() as directory:+ root = Path(directory)+ prompts = [{"id": str(i), "messages": []} for i in range(count)]+ (root / "prompts24.jsonl").write_text("".join(json.dumps(p) + "\n" for p in prompts))+ out = root / "results"+ old = os.getcwd()++ def request(port, prompt, result, index):+ reply = {"timings": {"predicted_n": 1, "predicted_per_second": 1},+ "choices": [{"message": {"content": prompt["id"]}}]}+ result[index] = (reply, 0.1, time.time())++ try:+ os.chdir(root)+ with patch.object(multi, "ARMS", {"test_m4": {}}), \+ patch.object(multi, "start", return_value=(1, Mock(pid=1), "unused")), \+ patch.object(multi, "stop"), patch.object(multi, "post"), \+ patch.object(multi, "req", side_effect=request), \+ patch.object(multi, "Sampler", return_value=Mock(anon=1, avail=1)), \+ patch("sys.argv", ["multi.py", "--out", str(out), "--rounds", str(rounds)]), \+ contextlib.redirect_stdout(io.StringIO()), contextlib.redirect_stderr(io.StringIO()):+ multi.main()+ return [json.loads(line) for line in (out / "multi.jsonl").read_text().splitlines()]+ finally:+ os.chdir(old)++ def test_more_than_three_rounds_keep_four_streams(self):+ rows = self.run_rounds(4)+ self.assertEqual(len(rows), 4)+ self.assertTrue(all(len(r["prompts"]) == 4 for r in rows))+ self.assertEqual(rows[3]["prompts"], rows[0]["prompts"])+ self.assertTrue(all(all(r["identical_to_alone"]) for r in rows))++ def test_nonpositive_round_count_is_rejected(self):+ with self.assertRaises(SystemExit) as error:+ self.run_rounds(0)+ self.assertEqual(error.exception.code, 2)++ def test_too_few_prompts_is_rejected_before_start(self):+ with self.assertRaises(SystemExit) as error:+ self.run_rounds(1, count=3)+ self.assertEqual(error.exception.code, 2)+++if __name__ == "__main__":+ unittest.main()