From ce95384cc6167e5ae464f14101f637fc13a39bea Mon Sep 17 00:00:00 2001 From: Hao Li <18546749+haofrank@users.noreply.github.com> Date: Tue, 1 Sep 2026 16:25:13 -0700 Subject: [PATCH 1/7] Fix eval concurrency argument compatibility --- Magpie/scripts/benchmark/atom_mi300x.sh | 3 +- Magpie/scripts/benchmark/atom_mi355x.sh | 3 +- .../benchmark/magpie_bench_remote_compat.sh | 6 ++- Magpie/scripts/benchmark/sglang_mi300x.sh | 4 +- Magpie/scripts/benchmark/sglang_mi355x.sh | 3 +- Magpie/scripts/benchmark/vllm_mi300x.sh | 4 +- Magpie/scripts/benchmark/vllm_mi355x.sh | 3 +- tests/test_eval_concurrency_scripts.py | 43 +++++++++++++++++++ 8 files changed, 59 insertions(+), 10 deletions(-) create mode 100644 tests/test_eval_concurrency_scripts.py diff --git a/Magpie/scripts/benchmark/atom_mi300x.sh b/Magpie/scripts/benchmark/atom_mi300x.sh index 693ee8a..5fb7b26 100644 --- a/Magpie/scripts/benchmark/atom_mi300x.sh +++ b/Magpie/scripts/benchmark/atom_mi300x.sh @@ -144,7 +144,8 @@ if [[ "$PHASE" != "server" && "${RUN_EVAL}" = "true" ]]; then echo "[atom_mi300x] RUN_EVAL=true with BENCHMARK_BASE_URL but magpie_run_eval_remote_direct shim not available; skipping eval (results gate will see accuracy=None)." fi else - run_eval --framework lm-eval --port "$PORT" --concurrent-requests $CONC || exit $? + export EVAL_CONCURRENT_REQUESTS="${MAGPIE_EVAL_CONCURRENCY:-${EVAL_CONCURRENT_REQUESTS:-$CONC}}" + run_eval --framework lm-eval --port "$PORT" || exit $? append_lm_eval_summary fi fi diff --git a/Magpie/scripts/benchmark/atom_mi355x.sh b/Magpie/scripts/benchmark/atom_mi355x.sh index 12ca251..ef066f5 100644 --- a/Magpie/scripts/benchmark/atom_mi355x.sh +++ b/Magpie/scripts/benchmark/atom_mi355x.sh @@ -139,7 +139,8 @@ if [[ "$PHASE" != "server" && "${RUN_EVAL}" = "true" ]]; then echo "[atom_mi355x] RUN_EVAL=true with BENCHMARK_BASE_URL but magpie_run_eval_remote_direct shim not available; skipping eval (results gate will see accuracy=None)." fi else - run_eval --framework lm-eval --port "$PORT" --concurrent-requests $CONC || exit $? + export EVAL_CONCURRENT_REQUESTS="${MAGPIE_EVAL_CONCURRENCY:-${EVAL_CONCURRENT_REQUESTS:-$CONC}}" + run_eval --framework lm-eval --port "$PORT" || exit $? append_lm_eval_summary fi fi diff --git a/Magpie/scripts/benchmark/magpie_bench_remote_compat.sh b/Magpie/scripts/benchmark/magpie_bench_remote_compat.sh index 29cb305..8133eb3 100644 --- a/Magpie/scripts/benchmark/magpie_bench_remote_compat.sh +++ b/Magpie/scripts/benchmark/magpie_bench_remote_compat.sh @@ -102,10 +102,12 @@ magpie_run_benchmark_serving_remote_direct() { # Inputs (env, must already be set by the calling mi*x.sh): # MODEL model id passed to lm-eval # BENCHMARK_BASE_URL e.g. http://:8888 -# CONC concurrency cap (passed to local-completions) +# CONC performance concurrency (fallback for accuracy) # RESULT_DIR workspace dir; results land at $RESULT_DIR/lm_eval/ # # Inputs (env, optional): +# MAGPIE_EVAL_CONCURRENCY independent accuracy concurrency; falls back to +# EVAL_CONCURRENT_REQUESTS, then CONC, then 8 # MAGPIE_EVAL_TASKS comma-separated lm-eval task names (default: gsm8k) # MAGPIE_EVAL_LIMIT int; cap samples for smoke runs (default: empty = full) # MAGPIE_EVAL_BATCH_SIZE size for lm-eval (default: auto) @@ -130,7 +132,7 @@ magpie_run_eval_remote_direct() { local tasks="${MAGPIE_EVAL_TASKS:-gsm8k}" local batch_size="${MAGPIE_EVAL_BATCH_SIZE:-auto}" - local conc="${CONC:-8}" + local conc="${MAGPIE_EVAL_CONCURRENCY:-${EVAL_CONCURRENT_REQUESTS:-${CONC:-8}}}" # local-completions hits an OpenAI-compatible /v1/completions endpoint. # base_url ends in /v1/completions; tokenizer_backend=huggingface uses diff --git a/Magpie/scripts/benchmark/sglang_mi300x.sh b/Magpie/scripts/benchmark/sglang_mi300x.sh index 1776cc9..16a82ec 100644 --- a/Magpie/scripts/benchmark/sglang_mi300x.sh +++ b/Magpie/scripts/benchmark/sglang_mi300x.sh @@ -143,9 +143,9 @@ if [[ "$PHASE" != "server" && "${RUN_EVAL}" = "true" ]]; then echo "[sglang_mi300x] RUN_EVAL=true with BENCHMARK_BASE_URL but magpie_run_eval_remote_direct shim not available; skipping eval (results gate will see accuracy=None)." fi else - run_eval --framework lm-eval --port "$PORT" --concurrent-requests $CONC || exit $? + export EVAL_CONCURRENT_REQUESTS="${MAGPIE_EVAL_CONCURRENCY:-${EVAL_CONCURRENT_REQUESTS:-$CONC}}" + run_eval --framework lm-eval --port "$PORT" || exit $? append_lm_eval_summary fi fi set +x - diff --git a/Magpie/scripts/benchmark/sglang_mi355x.sh b/Magpie/scripts/benchmark/sglang_mi355x.sh index ff47084..2ee904d 100644 --- a/Magpie/scripts/benchmark/sglang_mi355x.sh +++ b/Magpie/scripts/benchmark/sglang_mi355x.sh @@ -138,7 +138,8 @@ if [[ "$PHASE" != "server" && "${RUN_EVAL}" = "true" ]]; then echo "[sglang_mi355x] RUN_EVAL=true with BENCHMARK_BASE_URL but magpie_run_eval_remote_direct shim not available; skipping eval (results gate will see accuracy=None)." fi else - run_eval --framework lm-eval --port "$PORT" --concurrent-requests $CONC || exit $? + export EVAL_CONCURRENT_REQUESTS="${MAGPIE_EVAL_CONCURRENCY:-${EVAL_CONCURRENT_REQUESTS:-$CONC}}" + run_eval --framework lm-eval --port "$PORT" || exit $? append_lm_eval_summary fi fi diff --git a/Magpie/scripts/benchmark/vllm_mi300x.sh b/Magpie/scripts/benchmark/vllm_mi300x.sh index f68460b..a11ec84 100644 --- a/Magpie/scripts/benchmark/vllm_mi300x.sh +++ b/Magpie/scripts/benchmark/vllm_mi300x.sh @@ -151,9 +151,9 @@ if [[ "$PHASE" != "server" && "${RUN_EVAL}" = "true" ]]; then echo "[vllm_mi300x] RUN_EVAL=true with BENCHMARK_BASE_URL but magpie_run_eval_remote_direct shim not available; skipping eval (results gate will see accuracy=None)." fi else - run_eval --framework lm-eval --port "$PORT" --concurrent-requests $CONC || exit $? + export EVAL_CONCURRENT_REQUESTS="${MAGPIE_EVAL_CONCURRENCY:-${EVAL_CONCURRENT_REQUESTS:-$CONC}}" + run_eval --framework lm-eval --port "$PORT" || exit $? append_lm_eval_summary fi fi set +x - diff --git a/Magpie/scripts/benchmark/vllm_mi355x.sh b/Magpie/scripts/benchmark/vllm_mi355x.sh index 1df07f2..488954a 100644 --- a/Magpie/scripts/benchmark/vllm_mi355x.sh +++ b/Magpie/scripts/benchmark/vllm_mi355x.sh @@ -147,7 +147,8 @@ if [[ "$PHASE" != "server" && "${RUN_EVAL}" = "true" ]]; then echo "[vllm_mi355x] RUN_EVAL=true with BENCHMARK_BASE_URL but magpie_run_eval_remote_direct shim not available; skipping eval (results gate will see accuracy=None)." fi else - run_eval --framework lm-eval --port "$PORT" --concurrent-requests $CONC || exit $? + export EVAL_CONCURRENT_REQUESTS="${MAGPIE_EVAL_CONCURRENCY:-${EVAL_CONCURRENT_REQUESTS:-$CONC}}" + run_eval --framework lm-eval --port "$PORT" || exit $? append_lm_eval_summary fi fi diff --git a/tests/test_eval_concurrency_scripts.py b/tests/test_eval_concurrency_scripts.py new file mode 100644 index 0000000..0e6c785 --- /dev/null +++ b/tests/test_eval_concurrency_scripts.py @@ -0,0 +1,43 @@ +from pathlib import Path + +import pytest + +ROOT = Path(__file__).parents[1] +LOCAL_EVAL_SCRIPTS = [ + "atom_mi300x.sh", + "atom_mi355x.sh", + "sglang_mi300x.sh", + "sglang_mi355x.sh", + "vllm_mi300x.sh", + "vllm_mi355x.sh", +] +CONCURRENCY_EXPORT = ( + 'export EVAL_CONCURRENT_REQUESTS="${MAGPIE_EVAL_CONCURRENCY:-' + '${EVAL_CONCURRENT_REQUESTS:-$CONC}}"' +) + + +@pytest.mark.parametrize("script_name", LOCAL_EVAL_SCRIPTS) +def test_local_eval_scripts_use_environment_for_concurrency(script_name: str): + script = ROOT / "Magpie" / "scripts" / "benchmark" / script_name + contents = script.read_text(encoding="utf-8") + + assert CONCURRENCY_EXPORT in contents + assert 'run_eval --framework lm-eval --port "$PORT" || exit $?' in contents + assert "--concurrent-requests" not in contents + + +def test_remote_eval_prefers_independent_accuracy_concurrency(): + script = ( + ROOT + / "Magpie" + / "scripts" + / "benchmark" + / "magpie_bench_remote_compat.sh" + ) + contents = script.read_text(encoding="utf-8") + + assert ( + 'local conc="${MAGPIE_EVAL_CONCURRENCY:-' + '${EVAL_CONCURRENT_REQUESTS:-${CONC:-8}}}"' + ) in contents From d7f8fa64755bbdf697d5aecee90692264e981db6 Mon Sep 17 00:00:00 2001 From: Hao Li <18546749+haofrank@users.noreply.github.com> Date: Tue, 1 Sep 2026 17:22:54 -0700 Subject: [PATCH 2/7] Persist lm-eval accuracy artifacts --- Magpie/scripts/benchmark/atom_mi300x.sh | 8 +- Magpie/scripts/benchmark/atom_mi355x.sh | 8 +- .../benchmark/magpie_bench_remote_compat.sh | 151 ++++++++++++++++++ Magpie/scripts/benchmark/sglang_mi300x.sh | 8 +- Magpie/scripts/benchmark/sglang_mi355x.sh | 8 +- Magpie/scripts/benchmark/vllm_mi300x.sh | 8 +- Magpie/scripts/benchmark/vllm_mi355x.sh | 8 +- docs/how-to/benchmarking/benchmark.md | 11 +- skills/magpie/reference.md | 2 + tests/test_eval_concurrency_scripts.py | 63 ++++++++ 10 files changed, 262 insertions(+), 13 deletions(-) diff --git a/Magpie/scripts/benchmark/atom_mi300x.sh b/Magpie/scripts/benchmark/atom_mi300x.sh index 5fb7b26..44d165f 100644 --- a/Magpie/scripts/benchmark/atom_mi300x.sh +++ b/Magpie/scripts/benchmark/atom_mi300x.sh @@ -145,8 +145,12 @@ if [[ "$PHASE" != "server" && "${RUN_EVAL}" = "true" ]]; then fi else export EVAL_CONCURRENT_REQUESTS="${MAGPIE_EVAL_CONCURRENCY:-${EVAL_CONCURRENT_REQUESTS:-$CONC}}" - run_eval --framework lm-eval --port "$PORT" || exit $? - append_lm_eval_summary + if declare -F magpie_run_eval_persisted &>/dev/null; then + magpie_run_eval_persisted --framework lm-eval --port "$PORT" || exit $? + else + run_eval --framework lm-eval --port "$PORT" || exit $? + append_lm_eval_summary + fi fi fi set +x diff --git a/Magpie/scripts/benchmark/atom_mi355x.sh b/Magpie/scripts/benchmark/atom_mi355x.sh index ef066f5..14c4047 100644 --- a/Magpie/scripts/benchmark/atom_mi355x.sh +++ b/Magpie/scripts/benchmark/atom_mi355x.sh @@ -140,8 +140,12 @@ if [[ "$PHASE" != "server" && "${RUN_EVAL}" = "true" ]]; then fi else export EVAL_CONCURRENT_REQUESTS="${MAGPIE_EVAL_CONCURRENCY:-${EVAL_CONCURRENT_REQUESTS:-$CONC}}" - run_eval --framework lm-eval --port "$PORT" || exit $? - append_lm_eval_summary + if declare -F magpie_run_eval_persisted &>/dev/null; then + magpie_run_eval_persisted --framework lm-eval --port "$PORT" || exit $? + else + run_eval --framework lm-eval --port "$PORT" || exit $? + append_lm_eval_summary + fi fi fi set +x diff --git a/Magpie/scripts/benchmark/magpie_bench_remote_compat.sh b/Magpie/scripts/benchmark/magpie_bench_remote_compat.sh index 8133eb3..f993a9e 100644 --- a/Magpie/scripts/benchmark/magpie_bench_remote_compat.sh +++ b/Magpie/scripts/benchmark/magpie_bench_remote_compat.sh @@ -167,5 +167,156 @@ magpie_run_eval_remote_direct() { if [[ $rc -ne 0 ]]; then echo "[magpie_bench_remote_compat] WARN lm_eval exited rc=$rc; accuracy gate will see no results" >&2 fi + magpie_write_accuracy_result "$out_dir" "$rc" return $rc } + +############################################################################### +# magpie_write_accuracy_result +# +# Convert the newest standard lm-eval result into a small, stable Magpie +# artifact. The raw lm-eval JSON remains alongside this file for consumers +# that need the complete result schema. +############################################################################### +magpie_write_accuracy_result() { + local eval_dir="$1" + local eval_rc="${2:-0}" + local py="${MAGPIE_EVAL_PYTHON:-python3}" + + "$py" - "$eval_dir" "$eval_rc" <<'PY' +import json +import os +import sys +from datetime import datetime, timezone +from pathlib import Path + +root = Path(sys.argv[1]) +eval_rc = int(sys.argv[2]) +output = root / "accuracy_result.json" +priority = ( + "exact_match,strict-match", + "exact_match,flexible-extract", + "acc,none", + "acc", +) + +candidates = [] +for path in root.rglob("*.json"): + if path == output: + continue + try: + payload = json.loads(path.read_text(encoding="utf-8")) + except (OSError, json.JSONDecodeError): + continue + if isinstance(payload, dict) and isinstance(payload.get("results"), dict): + candidates.append((path.stat().st_mtime, path, payload)) + +summary = { + "schema_version": "1.0", + "provider": "lm-eval", + "status": "ERROR", + "task": None, + "metric": None, + "score": None, + "samples": None, + "source_result": None, + "tasks": {}, + "error": None, + "created_at": datetime.now(timezone.utc).isoformat(), +} + +if not candidates: + summary["error"] = ( + f"lm-eval exited with code {eval_rc} and produced no result" + if eval_rc + else "lm-eval produced no result" + ) +else: + _, source, payload = max(candidates, key=lambda item: item[0]) + sample_payload = payload.get("n-samples", {}) + for task, task_result in payload["results"].items(): + if not isinstance(task_result, dict): + continue + sample_info = sample_payload.get(task) if isinstance(sample_payload, dict) else None + if isinstance(sample_info, dict): + samples = sample_info.get("effective", sample_info.get("original")) + else: + samples = sample_info + metrics = { + key: value + for key, value in task_result.items() + if isinstance(value, (int, float)) and not isinstance(value, bool) + } + summary["tasks"][task] = {"metrics": metrics, "samples": samples} + + if summary["tasks"]: + requested_tasks = [ + item.strip() + for item in os.environ.get("MAGPIE_EVAL_TASKS", "").split(",") + if item.strip() + ] + task = next( + (item for item in requested_tasks if item in summary["tasks"]), + next(iter(summary["tasks"])), + ) + metrics = summary["tasks"][task]["metrics"] + metric = next((item for item in priority if item in metrics), None) + summary.update( + status="COMPLETED" if eval_rc == 0 else "ERROR", + task=task, + metric=metric, + score=metrics.get(metric) if metric else None, + samples=summary["tasks"][task]["samples"], + source_result=str(source.relative_to(root)), + error=None if eval_rc == 0 else f"lm-eval exited with code {eval_rc}", + ) + else: + summary["source_result"] = str(source.relative_to(root)) + summary["error"] = "lm-eval result contains no task metrics" + +root.mkdir(parents=True, exist_ok=True) +output.write_text(json.dumps(summary, indent=2, sort_keys=True) + "\n", encoding="utf-8") +print(f"[magpie_bench_remote_compat] accuracy artifact: {output}", file=sys.stderr) +PY +} + +############################################################################### +# magpie_run_eval_persisted +# +# Run InferenceX's local-server eval while forcing its temporary result path +# onto Magpie's mounted workspace. InferenceX's append_lm_eval_summary then +# stages the raw JSON and metadata under $RESULT_DIR/lm_eval instead of the +# ephemeral container working directory. +############################################################################### +magpie_run_eval_persisted() { + if ! declare -F run_eval &>/dev/null; then + echo "[magpie_bench_remote_compat] ERROR run_eval is unavailable" >&2 + return 1 + fi + + local result_dir="${RESULT_DIR:-${WORKSPACE_DIR:-/workspace}}" + local eval_dir="${result_dir%/}/lm_eval" + local raw_dir="${eval_dir}/.raw-$$" + local eval_rc=0 + local stage_rc=0 + mkdir -p "$raw_dir" || { + echo "[magpie_bench_remote_compat] ERROR cannot mkdir $raw_dir" >&2 + return 1 + } + + export EVAL_RESULT_DIR="$raw_dir" + run_eval "$@" || eval_rc=$? + + if declare -F append_lm_eval_summary &>/dev/null; then + (cd "$eval_dir" && append_lm_eval_summary) || stage_rc=$? + else + echo "[magpie_bench_remote_compat] WARN append_lm_eval_summary is unavailable; preserving raw results" >&2 + eval_dir="$raw_dir" + fi + + magpie_write_accuracy_result "$eval_dir" "$eval_rc" || stage_rc=$? + if [[ $eval_rc -ne 0 ]]; then + return "$eval_rc" + fi + return "$stage_rc" +} diff --git a/Magpie/scripts/benchmark/sglang_mi300x.sh b/Magpie/scripts/benchmark/sglang_mi300x.sh index 16a82ec..3eff57f 100644 --- a/Magpie/scripts/benchmark/sglang_mi300x.sh +++ b/Magpie/scripts/benchmark/sglang_mi300x.sh @@ -144,8 +144,12 @@ if [[ "$PHASE" != "server" && "${RUN_EVAL}" = "true" ]]; then fi else export EVAL_CONCURRENT_REQUESTS="${MAGPIE_EVAL_CONCURRENCY:-${EVAL_CONCURRENT_REQUESTS:-$CONC}}" - run_eval --framework lm-eval --port "$PORT" || exit $? - append_lm_eval_summary + if declare -F magpie_run_eval_persisted &>/dev/null; then + magpie_run_eval_persisted --framework lm-eval --port "$PORT" || exit $? + else + run_eval --framework lm-eval --port "$PORT" || exit $? + append_lm_eval_summary + fi fi fi set +x diff --git a/Magpie/scripts/benchmark/sglang_mi355x.sh b/Magpie/scripts/benchmark/sglang_mi355x.sh index 2ee904d..1eb1612 100644 --- a/Magpie/scripts/benchmark/sglang_mi355x.sh +++ b/Magpie/scripts/benchmark/sglang_mi355x.sh @@ -139,8 +139,12 @@ if [[ "$PHASE" != "server" && "${RUN_EVAL}" = "true" ]]; then fi else export EVAL_CONCURRENT_REQUESTS="${MAGPIE_EVAL_CONCURRENCY:-${EVAL_CONCURRENT_REQUESTS:-$CONC}}" - run_eval --framework lm-eval --port "$PORT" || exit $? - append_lm_eval_summary + if declare -F magpie_run_eval_persisted &>/dev/null; then + magpie_run_eval_persisted --framework lm-eval --port "$PORT" || exit $? + else + run_eval --framework lm-eval --port "$PORT" || exit $? + append_lm_eval_summary + fi fi fi set +x diff --git a/Magpie/scripts/benchmark/vllm_mi300x.sh b/Magpie/scripts/benchmark/vllm_mi300x.sh index a11ec84..a7dac39 100644 --- a/Magpie/scripts/benchmark/vllm_mi300x.sh +++ b/Magpie/scripts/benchmark/vllm_mi300x.sh @@ -152,8 +152,12 @@ if [[ "$PHASE" != "server" && "${RUN_EVAL}" = "true" ]]; then fi else export EVAL_CONCURRENT_REQUESTS="${MAGPIE_EVAL_CONCURRENCY:-${EVAL_CONCURRENT_REQUESTS:-$CONC}}" - run_eval --framework lm-eval --port "$PORT" || exit $? - append_lm_eval_summary + if declare -F magpie_run_eval_persisted &>/dev/null; then + magpie_run_eval_persisted --framework lm-eval --port "$PORT" || exit $? + else + run_eval --framework lm-eval --port "$PORT" || exit $? + append_lm_eval_summary + fi fi fi set +x diff --git a/Magpie/scripts/benchmark/vllm_mi355x.sh b/Magpie/scripts/benchmark/vllm_mi355x.sh index 488954a..8a2fad0 100644 --- a/Magpie/scripts/benchmark/vllm_mi355x.sh +++ b/Magpie/scripts/benchmark/vllm_mi355x.sh @@ -148,8 +148,12 @@ if [[ "$PHASE" != "server" && "${RUN_EVAL}" = "true" ]]; then fi else export EVAL_CONCURRENT_REQUESTS="${MAGPIE_EVAL_CONCURRENCY:-${EVAL_CONCURRENT_REQUESTS:-$CONC}}" - run_eval --framework lm-eval --port "$PORT" || exit $? - append_lm_eval_summary + if declare -F magpie_run_eval_persisted &>/dev/null; then + magpie_run_eval_persisted --framework lm-eval --port "$PORT" || exit $? + else + run_eval --framework lm-eval --port "$PORT" || exit $? + append_lm_eval_summary + fi fi fi set +x diff --git a/docs/how-to/benchmarking/benchmark.md b/docs/how-to/benchmarking/benchmark.md index 4664491..bdeb4bb 100644 --- a/docs/how-to/benchmarking/benchmark.md +++ b/docs/how-to/benchmarking/benchmark.md @@ -73,7 +73,11 @@ results/benchmark_vllm_/ ├── config.yaml # Snapshot of benchmark configuration ├── container_stdout.log # Container stdout ├── container_stderr.log # Container stderr -├── inferencex_result.json # Raw InferenceX output +├── inferencex_result.json # Raw InferenceX performance output +├── lm_eval/ # Accuracy artifacts (when RUN_EVAL=true) +│ ├── accuracy_result.json # Stable Magpie accuracy summary +│ ├── results_*.json # Raw lm-eval result +│ └── meta_env.json # Evaluation environment metadata ├── torch_trace/ # Raw torch profiler traces │ ├── *-rank-0.*.pt.trace.json.gz │ ├── *-rank-1.*.pt.trace.json.gz @@ -94,6 +98,11 @@ results/benchmark_vllm_/ └── tracelens_collective_csvs/ # Legacy/direct PyTorch multi-rank collective report ``` +`lm_eval/accuracy_result.json` provides the selected task, metric, score, +effective sample count, and the path to the retained raw lm-eval result. It +reports evaluation execution status only; acceptance thresholds remain the +responsibility of the downstream qualification gate. + For TraceLens inference runs, the `*_ISL*_OSL*_CONC*_kernel_roofline_simple.csv` files are the fastest starting point for review. Each file covers one inference stage, encodes the benchmark diff --git a/skills/magpie/reference.md b/skills/magpie/reference.md index 089308a..d199514 100644 --- a/skills/magpie/reference.md +++ b/skills/magpie/reference.md @@ -112,6 +112,8 @@ Important outputs may include: - `benchmark_report.json`: throughput, latency, execution status, and optional profiling/analysis results; - `summary.txt`: human-readable summary; - framework benchmark results such as `inferencex_result.json`; +- `lm_eval/accuracy_result.json` plus the retained raw lm-eval result when + accuracy evaluation is enabled; - stdout/stderr logs; - torch traces and profiler output; - TraceLens reports; diff --git a/tests/test_eval_concurrency_scripts.py b/tests/test_eval_concurrency_scripts.py index 0e6c785..185475e 100644 --- a/tests/test_eval_concurrency_scripts.py +++ b/tests/test_eval_concurrency_scripts.py @@ -1,3 +1,6 @@ +import json +import os +import subprocess from pathlib import Path import pytest @@ -41,3 +44,63 @@ def test_remote_eval_prefers_independent_accuracy_concurrency(): 'local conc="${MAGPIE_EVAL_CONCURRENCY:-' '${EVAL_CONCURRENT_REQUESTS:-${CONC:-8}}}"' ) in contents + + +@pytest.mark.parametrize("script_name", LOCAL_EVAL_SCRIPTS) +def test_local_eval_scripts_persist_accuracy_results(script_name: str): + script = ROOT / "Magpie" / "scripts" / "benchmark" / script_name + contents = script.read_text(encoding="utf-8") + + assert "magpie_run_eval_persisted --framework lm-eval" in contents + + +def test_persisted_eval_writes_raw_and_formatted_results(tmp_path: Path): + compat = ( + ROOT + / "Magpie" + / "scripts" + / "benchmark" + / "magpie_bench_remote_compat.sh" + ) + result_payload = { + "lm_eval_version": "0.4.8", + "results": { + "gsm8k": { + "exact_match,strict-match": 0.98, + "exact_match,flexible-extract": 0.99, + } + }, + "n-samples": {"gsm8k": {"original": 1319, "effective": 100}}, + } + shell = r''' +source "$MAGPIE_COMPAT" +run_eval() { + mkdir -p "$EVAL_RESULT_DIR/model" + printf '%s\n' "$FAKE_EVAL_RESULT" > "$EVAL_RESULT_DIR/model/results_123.json" +} +append_lm_eval_summary() { + printf '%s\n' '{"model":"test"}' > "$EVAL_RESULT_DIR/meta_env.json" + find "$EVAL_RESULT_DIR" -type f -name '*.json*' -exec mv -f {} . \; + rm -rf "$EVAL_RESULT_DIR" +} +magpie_run_eval_persisted --framework lm-eval --port 8888 +''' + env = { + **os.environ, + "MAGPIE_COMPAT": str(compat), + "RESULT_DIR": str(tmp_path), + "FAKE_EVAL_RESULT": json.dumps(result_payload), + "MAGPIE_EVAL_TASKS": "gsm8k", + } + subprocess.run(["bash", "-c", shell], check=True, env=env) + + eval_dir = tmp_path / "lm_eval" + assert json.loads((eval_dir / "results_123.json").read_text()) == result_payload + assert (eval_dir / "meta_env.json").is_file() + summary = json.loads((eval_dir / "accuracy_result.json").read_text()) + assert summary["status"] == "COMPLETED" + assert summary["task"] == "gsm8k" + assert summary["metric"] == "exact_match,strict-match" + assert summary["score"] == 0.98 + assert summary["samples"] == 100 + assert summary["source_result"] == "results_123.json" From 1e0ed336b70769da422271e82b056da3c05a8199 Mon Sep 17 00:00:00 2001 From: Hao Li <18546749+haofrank@users.noreply.github.com> Date: Tue, 1 Sep 2026 17:31:54 -0700 Subject: [PATCH 3/7] Require persisted accuracy collection --- Magpie/scripts/benchmark/atom_mi300x.sh | 9 ++------- Magpie/scripts/benchmark/atom_mi355x.sh | 9 ++------- Magpie/scripts/benchmark/sglang_mi300x.sh | 9 ++------- Magpie/scripts/benchmark/sglang_mi355x.sh | 9 ++------- Magpie/scripts/benchmark/vllm_mi300x.sh | 9 ++------- Magpie/scripts/benchmark/vllm_mi355x.sh | 9 ++------- tests/test_eval_concurrency_scripts.py | 11 ++--------- 7 files changed, 14 insertions(+), 51 deletions(-) diff --git a/Magpie/scripts/benchmark/atom_mi300x.sh b/Magpie/scripts/benchmark/atom_mi300x.sh index 44d165f..90371cc 100644 --- a/Magpie/scripts/benchmark/atom_mi300x.sh +++ b/Magpie/scripts/benchmark/atom_mi300x.sh @@ -22,7 +22,7 @@ source "$(dirname "$0")/benchmark_lib.sh" source "$(dirname "$0")/server_cleanup.sh" # shellcheck source=magpie_bench_remote_compat.sh -[[ -f "$(dirname "$0")/magpie_bench_remote_compat.sh" ]] && source "$(dirname "$0")/magpie_bench_remote_compat.sh" +source "$(dirname "$0")/magpie_bench_remote_compat.sh" PHASE="${MAGPIE_RUN_PHASE:-all}" case "$PHASE" in @@ -145,12 +145,7 @@ if [[ "$PHASE" != "server" && "${RUN_EVAL}" = "true" ]]; then fi else export EVAL_CONCURRENT_REQUESTS="${MAGPIE_EVAL_CONCURRENCY:-${EVAL_CONCURRENT_REQUESTS:-$CONC}}" - if declare -F magpie_run_eval_persisted &>/dev/null; then - magpie_run_eval_persisted --framework lm-eval --port "$PORT" || exit $? - else - run_eval --framework lm-eval --port "$PORT" || exit $? - append_lm_eval_summary - fi + magpie_run_eval_persisted --framework lm-eval --port "$PORT" || exit $? fi fi set +x diff --git a/Magpie/scripts/benchmark/atom_mi355x.sh b/Magpie/scripts/benchmark/atom_mi355x.sh index 14c4047..5eac184 100644 --- a/Magpie/scripts/benchmark/atom_mi355x.sh +++ b/Magpie/scripts/benchmark/atom_mi355x.sh @@ -18,7 +18,7 @@ source "$(dirname "$0")/benchmark_lib.sh" source "$(dirname "$0")/server_cleanup.sh" # shellcheck source=magpie_bench_remote_compat.sh -[[ -f "$(dirname "$0")/magpie_bench_remote_compat.sh" ]] && source "$(dirname "$0")/magpie_bench_remote_compat.sh" +source "$(dirname "$0")/magpie_bench_remote_compat.sh" PHASE="${MAGPIE_RUN_PHASE:-all}" case "$PHASE" in @@ -140,12 +140,7 @@ if [[ "$PHASE" != "server" && "${RUN_EVAL}" = "true" ]]; then fi else export EVAL_CONCURRENT_REQUESTS="${MAGPIE_EVAL_CONCURRENCY:-${EVAL_CONCURRENT_REQUESTS:-$CONC}}" - if declare -F magpie_run_eval_persisted &>/dev/null; then - magpie_run_eval_persisted --framework lm-eval --port "$PORT" || exit $? - else - run_eval --framework lm-eval --port "$PORT" || exit $? - append_lm_eval_summary - fi + magpie_run_eval_persisted --framework lm-eval --port "$PORT" || exit $? fi fi set +x diff --git a/Magpie/scripts/benchmark/sglang_mi300x.sh b/Magpie/scripts/benchmark/sglang_mi300x.sh index 3eff57f..a5039ae 100644 --- a/Magpie/scripts/benchmark/sglang_mi300x.sh +++ b/Magpie/scripts/benchmark/sglang_mi300x.sh @@ -16,7 +16,7 @@ source "$(dirname "$0")/benchmark_lib.sh" source "$(dirname "$0")/server_cleanup.sh" # shellcheck source=magpie_bench_remote_compat.sh -[[ -f "$(dirname "$0")/magpie_bench_remote_compat.sh" ]] && source "$(dirname "$0")/magpie_bench_remote_compat.sh" +source "$(dirname "$0")/magpie_bench_remote_compat.sh" PHASE="${MAGPIE_RUN_PHASE:-all}" case "$PHASE" in @@ -144,12 +144,7 @@ if [[ "$PHASE" != "server" && "${RUN_EVAL}" = "true" ]]; then fi else export EVAL_CONCURRENT_REQUESTS="${MAGPIE_EVAL_CONCURRENCY:-${EVAL_CONCURRENT_REQUESTS:-$CONC}}" - if declare -F magpie_run_eval_persisted &>/dev/null; then - magpie_run_eval_persisted --framework lm-eval --port "$PORT" || exit $? - else - run_eval --framework lm-eval --port "$PORT" || exit $? - append_lm_eval_summary - fi + magpie_run_eval_persisted --framework lm-eval --port "$PORT" || exit $? fi fi set +x diff --git a/Magpie/scripts/benchmark/sglang_mi355x.sh b/Magpie/scripts/benchmark/sglang_mi355x.sh index 1eb1612..701eb34 100644 --- a/Magpie/scripts/benchmark/sglang_mi355x.sh +++ b/Magpie/scripts/benchmark/sglang_mi355x.sh @@ -17,7 +17,7 @@ source "$(dirname "$0")/benchmark_lib.sh" source "$(dirname "$0")/server_cleanup.sh" # shellcheck source=magpie_bench_remote_compat.sh -[[ -f "$(dirname "$0")/magpie_bench_remote_compat.sh" ]] && source "$(dirname "$0")/magpie_bench_remote_compat.sh" +source "$(dirname "$0")/magpie_bench_remote_compat.sh" PHASE="${MAGPIE_RUN_PHASE:-all}" case "$PHASE" in @@ -139,12 +139,7 @@ if [[ "$PHASE" != "server" && "${RUN_EVAL}" = "true" ]]; then fi else export EVAL_CONCURRENT_REQUESTS="${MAGPIE_EVAL_CONCURRENCY:-${EVAL_CONCURRENT_REQUESTS:-$CONC}}" - if declare -F magpie_run_eval_persisted &>/dev/null; then - magpie_run_eval_persisted --framework lm-eval --port "$PORT" || exit $? - else - run_eval --framework lm-eval --port "$PORT" || exit $? - append_lm_eval_summary - fi + magpie_run_eval_persisted --framework lm-eval --port "$PORT" || exit $? fi fi set +x diff --git a/Magpie/scripts/benchmark/vllm_mi300x.sh b/Magpie/scripts/benchmark/vllm_mi300x.sh index a7dac39..0c40e8e 100644 --- a/Magpie/scripts/benchmark/vllm_mi300x.sh +++ b/Magpie/scripts/benchmark/vllm_mi300x.sh @@ -21,7 +21,7 @@ source "$(dirname "$0")/benchmark_lib.sh" source "$(dirname "$0")/server_cleanup.sh" # shellcheck source=magpie_bench_remote_compat.sh -[[ -f "$(dirname "$0")/magpie_bench_remote_compat.sh" ]] && source "$(dirname "$0")/magpie_bench_remote_compat.sh" +source "$(dirname "$0")/magpie_bench_remote_compat.sh" PHASE="${MAGPIE_RUN_PHASE:-all}" case "$PHASE" in @@ -152,12 +152,7 @@ if [[ "$PHASE" != "server" && "${RUN_EVAL}" = "true" ]]; then fi else export EVAL_CONCURRENT_REQUESTS="${MAGPIE_EVAL_CONCURRENCY:-${EVAL_CONCURRENT_REQUESTS:-$CONC}}" - if declare -F magpie_run_eval_persisted &>/dev/null; then - magpie_run_eval_persisted --framework lm-eval --port "$PORT" || exit $? - else - run_eval --framework lm-eval --port "$PORT" || exit $? - append_lm_eval_summary - fi + magpie_run_eval_persisted --framework lm-eval --port "$PORT" || exit $? fi fi set +x diff --git a/Magpie/scripts/benchmark/vllm_mi355x.sh b/Magpie/scripts/benchmark/vllm_mi355x.sh index 8a2fad0..fe160c2 100644 --- a/Magpie/scripts/benchmark/vllm_mi355x.sh +++ b/Magpie/scripts/benchmark/vllm_mi355x.sh @@ -18,7 +18,7 @@ source "$(dirname "$0")/benchmark_lib.sh" source "$(dirname "$0")/server_cleanup.sh" # shellcheck source=magpie_bench_remote_compat.sh -[[ -f "$(dirname "$0")/magpie_bench_remote_compat.sh" ]] && source "$(dirname "$0")/magpie_bench_remote_compat.sh" +source "$(dirname "$0")/magpie_bench_remote_compat.sh" PHASE="${MAGPIE_RUN_PHASE:-all}" case "$PHASE" in @@ -148,12 +148,7 @@ if [[ "$PHASE" != "server" && "${RUN_EVAL}" = "true" ]]; then fi else export EVAL_CONCURRENT_REQUESTS="${MAGPIE_EVAL_CONCURRENCY:-${EVAL_CONCURRENT_REQUESTS:-$CONC}}" - if declare -F magpie_run_eval_persisted &>/dev/null; then - magpie_run_eval_persisted --framework lm-eval --port "$PORT" || exit $? - else - run_eval --framework lm-eval --port "$PORT" || exit $? - append_lm_eval_summary - fi + magpie_run_eval_persisted --framework lm-eval --port "$PORT" || exit $? fi fi set +x diff --git a/tests/test_eval_concurrency_scripts.py b/tests/test_eval_concurrency_scripts.py index 185475e..f5588c5 100644 --- a/tests/test_eval_concurrency_scripts.py +++ b/tests/test_eval_concurrency_scripts.py @@ -26,7 +26,8 @@ def test_local_eval_scripts_use_environment_for_concurrency(script_name: str): contents = script.read_text(encoding="utf-8") assert CONCURRENCY_EXPORT in contents - assert 'run_eval --framework lm-eval --port "$PORT" || exit $?' in contents + assert 'magpie_run_eval_persisted --framework lm-eval --port "$PORT"' in contents + assert "declare -F magpie_run_eval_persisted" not in contents assert "--concurrent-requests" not in contents @@ -46,14 +47,6 @@ def test_remote_eval_prefers_independent_accuracy_concurrency(): ) in contents -@pytest.mark.parametrize("script_name", LOCAL_EVAL_SCRIPTS) -def test_local_eval_scripts_persist_accuracy_results(script_name: str): - script = ROOT / "Magpie" / "scripts" / "benchmark" / script_name - contents = script.read_text(encoding="utf-8") - - assert "magpie_run_eval_persisted --framework lm-eval" in contents - - def test_persisted_eval_writes_raw_and_formatted_results(tmp_path: Path): compat = ( ROOT From e3979e3d2917405716eea5c48927671d6ea62ea6 Mon Sep 17 00:00:00 2001 From: Hao Li <18546749+haofrank@users.noreply.github.com> Date: Tue, 1 Sep 2026 17:33:46 -0700 Subject: [PATCH 4/7] Copy accuracy artifacts without modifying sources --- .../benchmark/magpie_bench_remote_compat.sh | 37 ++++++++++++------- tests/test_eval_concurrency_scripts.py | 11 ++++-- 2 files changed, 32 insertions(+), 16 deletions(-) diff --git a/Magpie/scripts/benchmark/magpie_bench_remote_compat.sh b/Magpie/scripts/benchmark/magpie_bench_remote_compat.sh index f993a9e..a48ca78 100644 --- a/Magpie/scripts/benchmark/magpie_bench_remote_compat.sh +++ b/Magpie/scripts/benchmark/magpie_bench_remote_compat.sh @@ -283,10 +283,9 @@ PY ############################################################################### # magpie_run_eval_persisted # -# Run InferenceX's local-server eval while forcing its temporary result path -# onto Magpie's mounted workspace. InferenceX's append_lm_eval_summary then -# stages the raw JSON and metadata under $RESULT_DIR/lm_eval instead of the -# ephemeral container working directory. +# Run InferenceX's local-server eval and copy its result artifacts into +# Magpie's mounted workspace. The source lm-eval directory is left untouched; +# Magpie owns only the copies under $RESULT_DIR/lm_eval. ############################################################################### magpie_run_eval_persisted() { if ! declare -F run_eval &>/dev/null; then @@ -296,23 +295,35 @@ magpie_run_eval_persisted() { local result_dir="${RESULT_DIR:-${WORKSPACE_DIR:-/workspace}}" local eval_dir="${result_dir%/}/lm_eval" - local raw_dir="${eval_dir}/.raw-$$" + local raw_dir="${EVAL_RESULT_DIR:-}" local eval_rc=0 local stage_rc=0 - mkdir -p "$raw_dir" || { - echo "[magpie_bench_remote_compat] ERROR cannot mkdir $raw_dir" >&2 + + if [[ -z "$raw_dir" ]]; then + raw_dir=$(mktemp -d /tmp/eval_out-magpie-XXXXXX) || { + echo "[magpie_bench_remote_compat] ERROR cannot create eval result directory" >&2 + return 1 + } + fi + mkdir -p "$raw_dir" "$eval_dir" || { + echo "[magpie_bench_remote_compat] ERROR cannot prepare accuracy directories" >&2 return 1 } export EVAL_RESULT_DIR="$raw_dir" run_eval "$@" || eval_rc=$? - if declare -F append_lm_eval_summary &>/dev/null; then - (cd "$eval_dir" && append_lm_eval_summary) || stage_rc=$? - else - echo "[magpie_bench_remote_compat] WARN append_lm_eval_summary is unavailable; preserving raw results" >&2 - eval_dir="$raw_dir" - fi + _write_lm_eval_meta_json \ + "$raw_dir/meta_env.json" "" "${CONC:-1}" || stage_rc=$? + + local source_file destination + while IFS= read -r -d '' source_file; do + destination="$eval_dir/$(basename "$source_file")" + if ! cp -p "$source_file" "$destination"; then + echo "[magpie_bench_remote_compat] WARN failed to copy $source_file" >&2 + stage_rc=1 + fi + done < <(find "$raw_dir" -type f \( -name "*.json" -o -name "*.jsonl" \) -print0 2>/dev/null) magpie_write_accuracy_result "$eval_dir" "$eval_rc" || stage_rc=$? if [[ $eval_rc -ne 0 ]]; then diff --git a/tests/test_eval_concurrency_scripts.py b/tests/test_eval_concurrency_scripts.py index f5588c5..e5c2996 100644 --- a/tests/test_eval_concurrency_scripts.py +++ b/tests/test_eval_concurrency_scripts.py @@ -72,22 +72,27 @@ def test_persisted_eval_writes_raw_and_formatted_results(tmp_path: Path): printf '%s\n' "$FAKE_EVAL_RESULT" > "$EVAL_RESULT_DIR/model/results_123.json" } append_lm_eval_summary() { - printf '%s\n' '{"model":"test"}' > "$EVAL_RESULT_DIR/meta_env.json" - find "$EVAL_RESULT_DIR" -type f -name '*.json*' -exec mv -f {} . \; - rm -rf "$EVAL_RESULT_DIR" + return 99 +} +_write_lm_eval_meta_json() { + printf '%s\n' '{"model":"test"}' > "$1" } magpie_run_eval_persisted --framework lm-eval --port 8888 ''' + source_dir = tmp_path / "source" env = { **os.environ, "MAGPIE_COMPAT": str(compat), "RESULT_DIR": str(tmp_path), + "EVAL_RESULT_DIR": str(source_dir), "FAKE_EVAL_RESULT": json.dumps(result_payload), "MAGPIE_EVAL_TASKS": "gsm8k", } subprocess.run(["bash", "-c", shell], check=True, env=env) eval_dir = tmp_path / "lm_eval" + assert json.loads((source_dir / "model" / "results_123.json").read_text()) == result_payload + assert (source_dir / "meta_env.json").is_file() assert json.loads((eval_dir / "results_123.json").read_text()) == result_payload assert (eval_dir / "meta_env.json").is_file() summary = json.loads((eval_dir / "accuracy_result.json").read_text()) From 4cfb2eadd51bbd4bbb3800329a77fbdec1c9dd84 Mon Sep 17 00:00:00 2001 From: Hao Li <18546749+haofrank@users.noreply.github.com> Date: Tue, 1 Sep 2026 17:35:02 -0700 Subject: [PATCH 5/7] Place accuracy summary beside benchmark report --- .../benchmark/magpie_bench_remote_compat.sh | 21 ++++++++++++------- docs/how-to/benchmarking/benchmark.md | 4 ++-- skills/magpie/reference.md | 2 +- tests/test_eval_concurrency_scripts.py | 4 ++-- 4 files changed, 19 insertions(+), 12 deletions(-) diff --git a/Magpie/scripts/benchmark/magpie_bench_remote_compat.sh b/Magpie/scripts/benchmark/magpie_bench_remote_compat.sh index a48ca78..b7a7cf0 100644 --- a/Magpie/scripts/benchmark/magpie_bench_remote_compat.sh +++ b/Magpie/scripts/benchmark/magpie_bench_remote_compat.sh @@ -167,7 +167,7 @@ magpie_run_eval_remote_direct() { if [[ $rc -ne 0 ]]; then echo "[magpie_bench_remote_compat] WARN lm_eval exited rc=$rc; accuracy gate will see no results" >&2 fi - magpie_write_accuracy_result "$out_dir" "$rc" + magpie_write_accuracy_result "$out_dir" "$rc" "$result_dir" return $rc } @@ -181,9 +181,10 @@ magpie_run_eval_remote_direct() { magpie_write_accuracy_result() { local eval_dir="$1" local eval_rc="${2:-0}" + local summary_dir="${3:-$eval_dir}" local py="${MAGPIE_EVAL_PYTHON:-python3}" - "$py" - "$eval_dir" "$eval_rc" <<'PY' + "$py" - "$eval_dir" "$eval_rc" "$summary_dir" <<'PY' import json import os import sys @@ -192,7 +193,8 @@ from pathlib import Path root = Path(sys.argv[1]) eval_rc = int(sys.argv[2]) -output = root / "accuracy_result.json" +output_root = Path(sys.argv[3]) +output = output_root / "accuracy_result.json" priority = ( "exact_match,strict-match", "exact_match,flexible-extract", @@ -267,14 +269,19 @@ else: metric=metric, score=metrics.get(metric) if metric else None, samples=summary["tasks"][task]["samples"], - source_result=str(source.relative_to(root)), + source_result=None, error=None if eval_rc == 0 else f"lm-eval exited with code {eval_rc}", ) else: - summary["source_result"] = str(source.relative_to(root)) + summary["source_result"] = None summary["error"] = "lm-eval result contains no task metrics" -root.mkdir(parents=True, exist_ok=True) + try: + summary["source_result"] = str(source.relative_to(output_root)) + except ValueError: + summary["source_result"] = str(source) + +output_root.mkdir(parents=True, exist_ok=True) output.write_text(json.dumps(summary, indent=2, sort_keys=True) + "\n", encoding="utf-8") print(f"[magpie_bench_remote_compat] accuracy artifact: {output}", file=sys.stderr) PY @@ -325,7 +332,7 @@ magpie_run_eval_persisted() { fi done < <(find "$raw_dir" -type f \( -name "*.json" -o -name "*.jsonl" \) -print0 2>/dev/null) - magpie_write_accuracy_result "$eval_dir" "$eval_rc" || stage_rc=$? + magpie_write_accuracy_result "$eval_dir" "$eval_rc" "$result_dir" || stage_rc=$? if [[ $eval_rc -ne 0 ]]; then return "$eval_rc" fi diff --git a/docs/how-to/benchmarking/benchmark.md b/docs/how-to/benchmarking/benchmark.md index bdeb4bb..ce4edf7 100644 --- a/docs/how-to/benchmarking/benchmark.md +++ b/docs/how-to/benchmarking/benchmark.md @@ -69,13 +69,13 @@ A successful benchmark run creates a timestamped workspace directory with the fo ``` results/benchmark_vllm_/ ├── benchmark_report.json # Main benchmark results +├── accuracy_result.json # Stable accuracy summary (when enabled) ├── summary.txt # Human-readable summary ├── config.yaml # Snapshot of benchmark configuration ├── container_stdout.log # Container stdout ├── container_stderr.log # Container stderr ├── inferencex_result.json # Raw InferenceX performance output ├── lm_eval/ # Accuracy artifacts (when RUN_EVAL=true) -│ ├── accuracy_result.json # Stable Magpie accuracy summary │ ├── results_*.json # Raw lm-eval result │ └── meta_env.json # Evaluation environment metadata ├── torch_trace/ # Raw torch profiler traces @@ -98,7 +98,7 @@ results/benchmark_vllm_/ └── tracelens_collective_csvs/ # Legacy/direct PyTorch multi-rank collective report ``` -`lm_eval/accuracy_result.json` provides the selected task, metric, score, +`accuracy_result.json` provides the selected task, metric, score, effective sample count, and the path to the retained raw lm-eval result. It reports evaluation execution status only; acceptance thresholds remain the responsibility of the downstream qualification gate. diff --git a/skills/magpie/reference.md b/skills/magpie/reference.md index d199514..a75d3c0 100644 --- a/skills/magpie/reference.md +++ b/skills/magpie/reference.md @@ -112,7 +112,7 @@ Important outputs may include: - `benchmark_report.json`: throughput, latency, execution status, and optional profiling/analysis results; - `summary.txt`: human-readable summary; - framework benchmark results such as `inferencex_result.json`; -- `lm_eval/accuracy_result.json` plus the retained raw lm-eval result when +- `accuracy_result.json` plus the retained raw result under `lm_eval/` when accuracy evaluation is enabled; - stdout/stderr logs; - torch traces and profiler output; diff --git a/tests/test_eval_concurrency_scripts.py b/tests/test_eval_concurrency_scripts.py index e5c2996..82d2345 100644 --- a/tests/test_eval_concurrency_scripts.py +++ b/tests/test_eval_concurrency_scripts.py @@ -95,10 +95,10 @@ def test_persisted_eval_writes_raw_and_formatted_results(tmp_path: Path): assert (source_dir / "meta_env.json").is_file() assert json.loads((eval_dir / "results_123.json").read_text()) == result_payload assert (eval_dir / "meta_env.json").is_file() - summary = json.loads((eval_dir / "accuracy_result.json").read_text()) + summary = json.loads((tmp_path / "accuracy_result.json").read_text()) assert summary["status"] == "COMPLETED" assert summary["task"] == "gsm8k" assert summary["metric"] == "exact_match,strict-match" assert summary["score"] == 0.98 assert summary["samples"] == 100 - assert summary["source_result"] == "results_123.json" + assert summary["source_result"] == "lm_eval/results_123.json" From c8e513304a01d7c179497598989a44d3ff8b76a5 Mon Sep 17 00:00:00 2001 From: Hao Li <18546749+haofrank@users.noreply.github.com> Date: Tue, 1 Sep 2026 17:36:44 -0700 Subject: [PATCH 6/7] Rename accuracy artifact to report --- Magpie/scripts/benchmark/magpie_bench_remote_compat.sh | 2 +- docs/how-to/benchmarking/benchmark.md | 4 ++-- skills/magpie/reference.md | 2 +- tests/test_eval_concurrency_scripts.py | 2 +- 4 files changed, 5 insertions(+), 5 deletions(-) diff --git a/Magpie/scripts/benchmark/magpie_bench_remote_compat.sh b/Magpie/scripts/benchmark/magpie_bench_remote_compat.sh index b7a7cf0..6dda5b5 100644 --- a/Magpie/scripts/benchmark/magpie_bench_remote_compat.sh +++ b/Magpie/scripts/benchmark/magpie_bench_remote_compat.sh @@ -194,7 +194,7 @@ from pathlib import Path root = Path(sys.argv[1]) eval_rc = int(sys.argv[2]) output_root = Path(sys.argv[3]) -output = output_root / "accuracy_result.json" +output = output_root / "accuracy_report.json" priority = ( "exact_match,strict-match", "exact_match,flexible-extract", diff --git a/docs/how-to/benchmarking/benchmark.md b/docs/how-to/benchmarking/benchmark.md index ce4edf7..499de8b 100644 --- a/docs/how-to/benchmarking/benchmark.md +++ b/docs/how-to/benchmarking/benchmark.md @@ -69,7 +69,7 @@ A successful benchmark run creates a timestamped workspace directory with the fo ``` results/benchmark_vllm_/ ├── benchmark_report.json # Main benchmark results -├── accuracy_result.json # Stable accuracy summary (when enabled) +├── accuracy_report.json # Stable accuracy summary (when enabled) ├── summary.txt # Human-readable summary ├── config.yaml # Snapshot of benchmark configuration ├── container_stdout.log # Container stdout @@ -98,7 +98,7 @@ results/benchmark_vllm_/ └── tracelens_collective_csvs/ # Legacy/direct PyTorch multi-rank collective report ``` -`accuracy_result.json` provides the selected task, metric, score, +`accuracy_report.json` provides the selected task, metric, score, effective sample count, and the path to the retained raw lm-eval result. It reports evaluation execution status only; acceptance thresholds remain the responsibility of the downstream qualification gate. diff --git a/skills/magpie/reference.md b/skills/magpie/reference.md index a75d3c0..61a51fe 100644 --- a/skills/magpie/reference.md +++ b/skills/magpie/reference.md @@ -112,7 +112,7 @@ Important outputs may include: - `benchmark_report.json`: throughput, latency, execution status, and optional profiling/analysis results; - `summary.txt`: human-readable summary; - framework benchmark results such as `inferencex_result.json`; -- `accuracy_result.json` plus the retained raw result under `lm_eval/` when +- `accuracy_report.json` plus the retained raw result under `lm_eval/` when accuracy evaluation is enabled; - stdout/stderr logs; - torch traces and profiler output; diff --git a/tests/test_eval_concurrency_scripts.py b/tests/test_eval_concurrency_scripts.py index 82d2345..ff1e051 100644 --- a/tests/test_eval_concurrency_scripts.py +++ b/tests/test_eval_concurrency_scripts.py @@ -95,7 +95,7 @@ def test_persisted_eval_writes_raw_and_formatted_results(tmp_path: Path): assert (source_dir / "meta_env.json").is_file() assert json.loads((eval_dir / "results_123.json").read_text()) == result_payload assert (eval_dir / "meta_env.json").is_file() - summary = json.loads((tmp_path / "accuracy_result.json").read_text()) + summary = json.loads((tmp_path / "accuracy_report.json").read_text()) assert summary["status"] == "COMPLETED" assert summary["task"] == "gsm8k" assert summary["metric"] == "exact_match,strict-match" From 2c669287be95035ff2964a52c3b8fc1312fec8ea Mon Sep 17 00:00:00 2001 From: Hao Li <18546749+haofrank@users.noreply.github.com> Date: Tue, 1 Sep 2026 17:52:18 -0700 Subject: [PATCH 7/7] Fix persisted batched eval artifacts --- .../benchmark/magpie_bench_remote_compat.sh | 29 ++++++- tests/test_eval_concurrency_scripts.py | 84 ++++++++++++++++++- 2 files changed, 108 insertions(+), 5 deletions(-) diff --git a/Magpie/scripts/benchmark/magpie_bench_remote_compat.sh b/Magpie/scripts/benchmark/magpie_bench_remote_compat.sh index 6dda5b5..7b20ff3 100644 --- a/Magpie/scripts/benchmark/magpie_bench_remote_compat.sh +++ b/Magpie/scripts/benchmark/magpie_bench_remote_compat.sh @@ -167,8 +167,12 @@ magpie_run_eval_remote_direct() { if [[ $rc -ne 0 ]]; then echo "[magpie_bench_remote_compat] WARN lm_eval exited rc=$rc; accuracy gate will see no results" >&2 fi - magpie_write_accuracy_result "$out_dir" "$rc" "$result_dir" - return $rc + local report_rc=0 + magpie_write_accuracy_result "$out_dir" "$rc" "$result_dir" || report_rc=$? + if [[ $rc -ne 0 ]]; then + return "$rc" + fi + return "$report_rc" } ############################################################################### @@ -316,12 +320,29 @@ magpie_run_eval_persisted() { echo "[magpie_bench_remote_compat] ERROR cannot prepare accuracy directories" >&2 return 1 } + raw_dir=$(cd "$raw_dir" && pwd -P) || return 1 export EVAL_RESULT_DIR="$raw_dir" + local caller_dir="$PWD" + # InferenceX stages batched-concurrency results into PWD rather than + # EVAL_RESULT_DIR. Run from raw_dir so both single and batched evaluations + # have one source tree that can be copied without modifying the artifacts. + cd "$raw_dir" || return 1 run_eval "$@" || eval_rc=$? + cd "$caller_dir" || return 1 - _write_lm_eval_meta_json \ - "$raw_dir/meta_env.json" "" "${CONC:-1}" || stage_rc=$? + if [[ -n "${EVAL_BATCHED_CONCS:-}" ]]; then + if declare -F append_lm_eval_summary &>/dev/null; then + (cd "$raw_dir" && append_lm_eval_summary) || stage_rc=$? + else + echo "[magpie_bench_remote_compat] ERROR append_lm_eval_summary is unavailable for batched eval" >&2 + stage_rc=1 + fi + else + _write_lm_eval_meta_json \ + "$raw_dir/meta_env.json" "" \ + "${EVAL_CONCURRENT_REQUESTS:-${CONC:-1}}" || stage_rc=$? + fi local source_file destination while IFS= read -r -d '' source_file; do diff --git a/tests/test_eval_concurrency_scripts.py b/tests/test_eval_concurrency_scripts.py index ff1e051..3c4dbd0 100644 --- a/tests/test_eval_concurrency_scripts.py +++ b/tests/test_eval_concurrency_scripts.py @@ -75,7 +75,7 @@ def test_persisted_eval_writes_raw_and_formatted_results(tmp_path: Path): return 99 } _write_lm_eval_meta_json() { - printf '%s\n' '{"model":"test"}' > "$1" + printf '{"model":"test","conc":%s}\n' "$3" > "$1" } magpie_run_eval_persisted --framework lm-eval --port 8888 ''' @@ -87,12 +87,15 @@ def test_persisted_eval_writes_raw_and_formatted_results(tmp_path: Path): "EVAL_RESULT_DIR": str(source_dir), "FAKE_EVAL_RESULT": json.dumps(result_payload), "MAGPIE_EVAL_TASKS": "gsm8k", + "CONC": "64", + "EVAL_CONCURRENT_REQUESTS": "8", } subprocess.run(["bash", "-c", shell], check=True, env=env) eval_dir = tmp_path / "lm_eval" assert json.loads((source_dir / "model" / "results_123.json").read_text()) == result_payload assert (source_dir / "meta_env.json").is_file() + assert json.loads((source_dir / "meta_env.json").read_text())["conc"] == 8 assert json.loads((eval_dir / "results_123.json").read_text()) == result_payload assert (eval_dir / "meta_env.json").is_file() summary = json.loads((tmp_path / "accuracy_report.json").read_text()) @@ -102,3 +105,82 @@ def test_persisted_eval_writes_raw_and_formatted_results(tmp_path: Path): assert summary["score"] == 0.98 assert summary["samples"] == 100 assert summary["source_result"] == "lm_eval/results_123.json" + + +def test_persisted_eval_collects_batched_concurrency_results(tmp_path: Path): + compat = ( + ROOT + / "Magpie" + / "scripts" + / "benchmark" + / "magpie_bench_remote_compat.sh" + ) + shell = r''' +source "$MAGPIE_COMPAT" +run_eval() { + local conc + for conc in $EVAL_CONCURRENT_REQUESTS; do + printf '{"results":{"gsm8k":{"exact_match,strict-match":0.%s}}}\n' \ + "$conc" > "results_conc${conc}.json" + done + export EVAL_BATCHED_CONCS="$EVAL_CONCURRENT_REQUESTS" + export EVAL_BATCHED_COMPLETED_CONCS="$EVAL_CONCURRENT_REQUESTS" + export EVAL_BATCHED_FAILED_CONCS="" + export EVAL_RESULT_DIR="" +} +append_lm_eval_summary() { + printf '%s\n' '{"eval_concs":[2,4]}' > ./meta_env.json +} +_write_lm_eval_meta_json() { + return 99 +} +magpie_run_eval_persisted --framework lm-eval --port 8888 +''' + env = { + **os.environ, + "MAGPIE_COMPAT": str(compat), + "RESULT_DIR": str(tmp_path), + "EVAL_CONCURRENT_REQUESTS": "2 4", + "MAGPIE_EVAL_TASKS": "gsm8k", + } + subprocess.run(["bash", "-c", shell], check=True, env=env) + + eval_dir = tmp_path / "lm_eval" + assert (eval_dir / "results_conc2.json").is_file() + assert (eval_dir / "results_conc4.json").is_file() + assert json.loads((eval_dir / "meta_env.json").read_text())["eval_concs"] == [ + 2, + 4, + ] + summary = json.loads((tmp_path / "accuracy_report.json").read_text()) + assert summary["status"] == "COMPLETED" + assert summary["task"] == "gsm8k" + + +def test_remote_eval_propagates_accuracy_report_failure(tmp_path: Path): + compat = ( + ROOT + / "Magpie" + / "scripts" + / "benchmark" + / "magpie_bench_remote_compat.sh" + ) + shell = r''' +source "$MAGPIE_COMPAT" +magpie_write_accuracy_result() { + return 73 +} +magpie_run_eval_remote_direct +''' + env = { + **os.environ, + "MAGPIE_COMPAT": str(compat), + "RESULT_DIR": str(tmp_path), + "BENCHMARK_BASE_URL": "http://127.0.0.1:8888", + "MAGPIE_EVAL_PYTHON": "true", + "MODEL": "test-model", + "CONC": "8", + } + completed = subprocess.run(["bash", "-c", shell], check=False, env=env) + + assert completed.returncode == 73