diff --git a/docs/ai-lab.md b/docs/ai-lab.md index 933393e..96b4abb 100644 --- a/docs/ai-lab.md +++ b/docs/ai-lab.md @@ -43,8 +43,9 @@ Each run reads the existing `llama3.2:3b` GGUF blob; it does not copy, delete, or modify the model. The Debian user must be able to read the path printed by `ollama show --modelfile llama3.2:3b`. Inaccessible or non-GGUF files stop the test. Reports and model output are saved with mode 0600 under the lab's `reports` -directory. Review the llama.cpp log for actual GPU offload and prompt versus -generation timing; the parsed timing values alone do not identify the phase. +directory. The report labels llama.cpp's prompt and generation speeds when its +timing summary is present; a null value means timing was not recognized. +Review the log to confirm actual GPU offload. Each benchmark is one cold request, using the same prompt, maximum output, context size and temperature. CLI and Ollama prompt templates, sampling options, @@ -75,3 +76,6 @@ while the benchmark runs. The engines may use different prompts, sampling, context handling and timing boundaries; compare both the logs and answer quality rather than treating the elapsed times as a conclusive ranking. These are single-request experiments; neither backend is registered with OmniRoute. +Both Qwen runs request greedy sampling and disable thinking, so the limited +output budget is available for the answer. Check the logs to confirm that each +engine honored those settings and produced a complete answer. diff --git a/scripts/ai-lab.py b/scripts/ai-lab.py index 19ef767..bf7af98 100644 --- a/scripts/ai-lab.py +++ b/scripts/ai-lab.py @@ -186,6 +186,26 @@ def make_report(backend, result, log): print(f"Private report: {reports / (name + '.json')}") +def parse_llama_timings(log): + """Read phase-specific timing from the pinned llama-cli's summary.""" + cleaned = re.sub(r"\x1b\[[0-9;]*[A-Za-z]", "", log) + match = re.search(r"Prompt:\s*([0-9]+(?:\.[0-9]+)?)\s*t/s\s*\|\s*Generation:\s*([0-9]+(?:\.[0-9]+)?)\s*t/s", cleaned) + if match: + return {"prompt_tokens_per_second": float(match.group(1)), "generation_tokens_per_second": float(match.group(2))} + return {"prompt_tokens_per_second": None, "generation_tokens_per_second": None} + + +def colibri_args(): + return ["env", "COLI_VULKAN=0", "COLI_CUDA=0", sys.executable, str(COLIBRI_CLI), "run", "--model", str(QWEN_DIR), "--gpu", "none", "--ctx", "4096", "--ngen", "128", "--temp", "0", "--no-think", PROMPT] + + +def llama_args(path, backend, device): + args = [str(CLI), "-m", str(path), "--device", device, "-ngl", "0" if backend in ("cpu", "qwen-cpu") else "999", "-c", "4096", "-n", "128", "--temp", "0", "--single-turn", "--perf"] + if backend == "qwen-cpu": + args.extend(["--reasoning", "off"]) + return args + ["-p", PROMPT] + + def benchmark(backend): if backend not in ("ollama", "cpu", "vulkan", "colibri", "qwen-cpu"): raise RuntimeError("Choose ollama, cpu, vulkan, colibri or qwen-cpu") @@ -212,7 +232,7 @@ def benchmark(backend): if available < 2 * 1024 * 1024: raise RuntimeError("Less than 2 GiB RAM is currently available; retry when the host has more headroom") started = time.monotonic() - completed = command(["env", "COLI_VULKAN=0", "COLI_CUDA=0", sys.executable, str(COLIBRI_CLI), "run", "--model", str(QWEN_DIR), "--gpu", "none", "--ctx", "4096", "--ngen", "128", PROMPT], capture=True, timeout=600) + completed = command(colibri_args(), capture=True, timeout=600) log = completed.stdout + "\n" + completed.stderr common.update({"device": "cpu", "elapsed_seconds": round(time.monotonic() - started, 3), "colibri_version": COLIBRI_TAG, "note": common["note"] + " Review the log for generation timings and output quality."}) make_report(backend, common, log) @@ -222,12 +242,11 @@ def benchmark(backend): device = "none" if backend in ("cpu", "qwen-cpu") else os.environ.get("JEANNIE_AI_LAB_VULKAN_DEVICE", "Vulkan0") if backend == "vulkan" and not re.fullmatch(r"Vulkan[0-9]+", device): raise RuntimeError("Vulkan device must have a name such as Vulkan0") - args = [str(CLI), "-m", str(path), "--device", device, "-ngl", "0" if backend in ("cpu", "qwen-cpu") else "999", "-c", "4096", "-n", "128", "--temp", "0", "--single-turn", "--perf", "-p", PROMPT] + args = llama_args(path, backend, device) started = time.monotonic() completed = command(args, capture=True, timeout=600) log = completed.stdout + "\n" + completed.stderr - rates = re.findall(r"([0-9]+(?:\.[0-9]+)?)\s+tokens per second", log) - common.update({"device": device, "elapsed_seconds": round(time.monotonic() - started, 3), "llama_cpp_version": TAG, "tokens_per_second_reported": [float(rate) for rate in rates], "note": common["note"] + " Confirm actual GPU offload and identify prompt/generation rates in the log."}) + common.update({"device": device, "elapsed_seconds": round(time.monotonic() - started, 3), "llama_cpp_version": TAG, **parse_llama_timings(log), "note": common["note"] + " Confirm actual GPU offload in the log; unavailable timing values are null."}) make_report(backend, common, log) diff --git a/tests/jeannie/test_ai_lab.py b/tests/jeannie/test_ai_lab.py index 0ce97ae..3076775 100644 --- a/tests/jeannie/test_ai_lab.py +++ b/tests/jeannie/test_ai_lab.py @@ -61,6 +61,19 @@ class AiLabTest(unittest.TestCase): self.assertEqual(len(lab.QWEN_SHA256), 64) self.assertIn("Qwen/Qwen3-0.6B-GGUF", lab.QWEN_URL) + def test_llama_cli_phase_timings_are_labeled(self): + result = lab.parse_llama_timings("\x1b[32m[ Prompt: 208.5 t/s | Generation: 44.3 t/s ]\x1b[0m") + self.assertEqual(result, {"prompt_tokens_per_second": 208.5, "generation_tokens_per_second": 44.3}) + self.assertEqual(lab.parse_llama_timings("unrecognized"), {"prompt_tokens_per_second": None, "generation_tokens_per_second": None}) + + def test_qwen_runs_request_no_thinking_and_greedy_sampling(self): + colibri = lab.colibri_args() + llama = lab.llama_args(Path("/demo/qwen.gguf"), "qwen-cpu", "none") + self.assertIn("--no-think", colibri) + self.assertEqual(colibri[colibri.index("--temp") + 1], "0") + self.assertEqual(llama[llama.index("--reasoning") + 1], "off") + self.assertEqual(llama[llama.index("--temp") + 1], "0") + if __name__ == "__main__": unittest.main()