ci / check (push) Successful in 11s
Several of one GPU: <gpu>/<model>/<N>x-<engine>-<profile>.md with gpus, tp and pp (tp × pp = gpus) and a declared PCIe topology. Different GPUs: mixed/<setup>/, named after its cards, with the same layout as a GPU folder and a generated mixed/README.md. Runs must sit in their recipe's setup folder. Energy, and bandwidth for pipeline parallel or mixed, are left out where bench-standard measures one GPU only; docs/ bench-standard-gaps.md lists those gaps for the benchmarks repo. The wanted lists take the fewest of one GPU a model fits in. Demo: 2x Arc B580 with vLLM TP 2 and llama.cpp layer split for Qwen3.8-27B, -sm row as what lost, and Arc Pro B60 + Arc B580 mixed. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
196 lines
7.5 KiB
Python
196 lines
7.5 KiB
Python
"""cookbook.py: command matching, generated blocks, Markdown, and validate on
|
||
copies of this repo with one thing broken."""
|
||
import json
|
||
import os
|
||
import shutil
|
||
import sys
|
||
from pathlib import Path
|
||
|
||
import pytest
|
||
|
||
sys.path.insert(0, os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
|
||
import cookbook # noqa: E402
|
||
|
||
RECIPE = "arc-pro-b65/qwen3.8-27b/vllm-single-user.md"
|
||
|
||
|
||
def test_command_words_ignores_layout_and_comments():
|
||
a = "docker run --rm \\\n -e A=1 img \\\n --flag 'x y'\n"
|
||
b = "# start it\ndocker run --rm -e A=1 img --flag 'x y'"
|
||
assert cookbook.command_words(a) == cookbook.command_words(b)
|
||
assert cookbook.command_words("x --flag 1") != cookbook.command_words("x --flag 2")
|
||
|
||
|
||
def test_command_words_redacts_like_bench_sh():
|
||
assert cookbook.command_words("HF_TOKEN=abc vllm serve m --api-key s3cret") == \
|
||
["HF_TOKEN=<redacted>", "vllm", "serve", "m", "--api-key", "<redacted>"]
|
||
|
||
|
||
def test_slug_matches_bench_sh():
|
||
assert cookbook.slug("Arc Pro B65") == "arc-pro-b65"
|
||
assert cookbook.slug("llama.cpp") == "llama.cpp"
|
||
assert cookbook.slug("Qwen3.8-27B") == "qwen3.8-27b"
|
||
|
||
|
||
def test_fill_replaces_only_the_block():
|
||
text = "a\n<!-- cookbook:x -->\nold\n<!-- /cookbook:x -->\nb\n"
|
||
assert cookbook.fill(text, "x", "new") == "a\n<!-- cookbook:x -->\nnew\n<!-- /cookbook:x -->\nb\n"
|
||
with pytest.raises(ValueError):
|
||
cookbook.fill(text, "y", "new")
|
||
|
||
|
||
def test_launch_block_takes_the_first_sh_block_under_launch():
|
||
body = "## Requirements\n```sh\nnot this\n```\n## Launch\ntext\n```sh\nthis\n```\n```sh\nnor this\n```\n"
|
||
assert cookbook.launch_block(body) == "this\n"
|
||
assert cookbook.launch_block("## Other\n```sh\nx\n```\n") is None
|
||
|
||
|
||
def test_md_to_html():
|
||
out = cookbook.md_to_html("## Head\n\n| a | b |\n|---|---|\n| `x` | [l](u.md) |\n\n- one\n- **two**\n\n"
|
||
"```sh\n<cmd>\n```\n", link=lambda u: "L:" + u)
|
||
assert '<h2 id="head">Head</h2>' in out
|
||
assert "<td><code>x</code></td>" in out and '<a href="L:u.md">l</a>' in out
|
||
assert "<ul><li>one</li><li><strong>two</strong></li></ul>" in out
|
||
assert "<pre><code><cmd></code></pre>" in out
|
||
|
||
|
||
# ---------------------------------------------------------------- the repo itself
|
||
def test_repo_validates_and_is_built():
|
||
cb = cookbook.Cookbook()
|
||
assert cb.errors == []
|
||
for path, text in cb.outputs().items():
|
||
assert path.read_text(encoding="utf-8") == text, f"{path} is out of date: run cookbook.py build"
|
||
|
||
|
||
def test_verified_needs_two_submitters():
|
||
cb = cookbook.Cookbook()
|
||
status = {r["id"]: r["status"] for r in cb.recipes}
|
||
assert status["arc-pro-b65/qwen3.8-27b/vllm-single-user"] == "verified by 2"
|
||
assert status["arc-pro-b65/qwen3.8-27b/vllm-throughput"] == "one submitter"
|
||
|
||
|
||
# ---------------------------------------------------------------- broken copies
|
||
@pytest.fixture
|
||
def repo(tmp_path):
|
||
root = tmp_path / "cookbook"
|
||
shutil.copytree(cookbook.ROOT, root, ignore=shutil.ignore_patterns(".git", "__pycache__", "*.html"))
|
||
for d in [*root.glob("*/results/*"), *root.glob("mixed/*/results/*")]: # only the reports' existence matters
|
||
if d.is_dir():
|
||
(d / f"{d.name}.html").touch()
|
||
return root
|
||
|
||
|
||
def edit(path, old, new):
|
||
text = path.read_text(encoding="utf-8")
|
||
assert old in text
|
||
path.write_text(text.replace(old, new, 1), encoding="utf-8")
|
||
|
||
|
||
def errors(root):
|
||
return "\n".join(cookbook.Cookbook(root).errors)
|
||
|
||
|
||
def test_copy_is_clean(repo):
|
||
assert errors(repo) == ""
|
||
|
||
|
||
def test_quick_run_cannot_back_a_recipe(repo):
|
||
edit(repo / RECIPE, '"261026_demo-2_qwen3.8-27b_vllm_1x-arc-pro-b65"',
|
||
'"261022_demo_qwen3.8-27b_vllm_1x-arc-pro-b65_quick_2"')
|
||
assert "is a quick run" in errors(repo)
|
||
|
||
|
||
def test_declared_values_must_match(repo):
|
||
edit(repo / RECIPE, 'kv = "fp16"', 'kv = "fp8"')
|
||
assert "kv is 'fp8' in the recipe but 'fp16' in the run" in errors(repo)
|
||
|
||
|
||
def test_launch_command_must_be_the_benchmarked_one(repo):
|
||
edit(repo / RECIPE, "--max-num-seqs 1", "--max-num-seqs 2")
|
||
assert "server-cmd.txt is not the recipe's launch command" in errors(repo)
|
||
|
||
|
||
def test_only_arc_gpus(repo):
|
||
edit(repo / RECIPE, 'gpu = "Arc Pro B65"', 'gpu = "RTX 4090"')
|
||
e = errors(repo)
|
||
assert "not an Intel Arc GPU" in e and "should be rtx-4090/" in e
|
||
|
||
|
||
def test_edited_results_are_caught(repo):
|
||
d = repo / "arc-pro-b65" / "results" / "261022_demo_qwen3.8-27b_vllm_1x-arc-pro-b65"
|
||
meta = json.loads((d / "meta.json").read_text(encoding="utf-8"))
|
||
meta["notes"]["spec"] = "none"
|
||
(d / "meta.json").write_text(json.dumps(meta), encoding="utf-8")
|
||
assert "differ (edited?)" in errors(repo)
|
||
|
||
|
||
def test_placeholder_digest_only_for_demo(repo):
|
||
(repo / "arc-pro-b65" / "results" / "261019_demo_qwen3.5-9b_llama.cpp_1x-arc-pro-b65" / "DEMO").unlink()
|
||
e = errors(repo)
|
||
assert "all-zero placeholder" in e
|
||
|
||
|
||
def test_tried_needs_an_existing_result(repo):
|
||
edit(repo / "arc-pro-b65/qwen3.5-9b/tried.md", "_quick_2", "_quick_9")
|
||
assert "is not in results/" in errors(repo)
|
||
|
||
|
||
def test_result_must_sit_in_its_gpu_folder(repo):
|
||
run = "261024_demo_qwen3.5-9b_llama.cpp_1x-arc-b580"
|
||
shutil.move(repo / "arc-b580" / "results" / run, repo / "arc-pro-b65" / "results" / run)
|
||
e = errors(repo)
|
||
assert "but it is in the Arc Pro B65 folder" in e and f"result {run} is not in results/" not in e
|
||
|
||
|
||
def test_stray_top_level_folder_warns(repo):
|
||
(repo / "arc-b999").mkdir()
|
||
assert any("arc-b999: not a GPU" in w for w in cookbook.Cookbook(repo).warnings)
|
||
|
||
|
||
# ---------------------------------------------------------------- multi-GPU and mixed
|
||
MULTI = "arc-b580/qwen3.8-27b/2x-vllm-single-user.md"
|
||
MIXED = "mixed/1x-arc-b580_1x-arc-pro-b60/qwen3.8-27b/llama.cpp-single-user.md"
|
||
|
||
|
||
def test_setup_names_folders_like_bench_sh_names_gpus():
|
||
assert cookbook.setup("Arc B580", 2) == ("arc-b580", "Arc B580", "2× Arc B580")
|
||
assert cookbook.setup(["Arc Pro B60", "Arc B580"]) == \
|
||
("mixed/1x-arc-b580_1x-arc-pro-b60", "Arc B580+Arc Pro B60", "Arc B580 + Arc Pro B60")
|
||
|
||
|
||
def test_multi_gpu_needs_topology(repo):
|
||
edit(repo / MULTI, 'topology = ["Gen4 x8 CPU", "Gen4 x8 CPU"]\n', "")
|
||
assert "declare topology" in errors(repo)
|
||
|
||
|
||
def test_tp_times_pp_is_the_gpu_count(repo):
|
||
edit(repo / MULTI, "tp = 2\n", "")
|
||
assert "tp × pp is 1, but the recipe runs on 2 GPUs" in errors(repo)
|
||
|
||
|
||
def test_gpu_count_is_in_the_file_name(repo):
|
||
shutil.move(repo / MULTI, repo / "arc-b580/qwen3.8-27b/vllm-single-user.md")
|
||
assert "should be arc-b580/qwen3.8-27b/2x-vllm-single-user.md" in errors(repo)
|
||
|
||
|
||
def test_mixed_needs_different_gpus(repo):
|
||
edit(repo / MIXED, 'gpu = ["Arc Pro B60", "Arc B580"]', 'gpu = ["Arc B580", "Arc B580"]')
|
||
assert "a mixed setup needs two different GPUs" in errors(repo)
|
||
|
||
|
||
def test_mixed_run_must_be_in_its_setup_folder(repo):
|
||
run = "261028_demo_qwen3.8-27b_llama.cpp_2x-arc-b580-arc-pro-b60"
|
||
src = repo / "mixed/1x-arc-b580_1x-arc-pro-b60/results" / run
|
||
dst = repo / "mixed/1x-arc-a770_1x-arc-b580/results"
|
||
dst.mkdir(parents=True)
|
||
shutil.move(src, dst / run)
|
||
assert f"{run} is in mixed/1x-arc-a770_1x-arc-b580/results, not mixed/1x-arc-b580_1x-arc-pro-b60/results" \
|
||
in errors(repo)
|
||
|
||
|
||
def test_wanted_takes_the_fewest_gpus_that_fit():
|
||
wanted = cookbook.Cookbook().wanted()
|
||
assert ("Arc A770", 2, "Qwen3.8-27B") in wanted
|
||
assert not any(g == "Arc B580" and m == "Qwen3.8-27B" for g, _, m in wanted) # has a 2× recipe
|
||
assert not any(g == "Arc B570" and m == "Qwen3.8-27B" for g, _, m in wanted) # 2 × 10 GB is too small
|