-
Notifications
You must be signed in to change notification settings - Fork 189
fix(config): propagate export level to benchmark plans #1452
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -10,12 +10,16 @@ | |
| from pydantic import ValidationError | ||
| from pytest import param | ||
|
|
||
| from aiperf.cli_runner._strategy import validate_convergence_config | ||
| from aiperf.common.enums import ExportLevel | ||
| from aiperf.config import ( | ||
| AIPerfConfig, | ||
| BenchmarkConfig, | ||
| BenchmarkPlan, | ||
| BenchmarkRun, | ||
| ) | ||
| from aiperf.config.flags import CLIConfig | ||
| from aiperf.config.flags.resolver import resolve_config | ||
| from aiperf.config.loader import build_benchmark_plan, load_benchmark_plan | ||
| from aiperf.config.resolution.plan import FailurePolicy | ||
| from aiperf.config.sweep import ( | ||
|
|
@@ -249,6 +253,138 @@ def test_multi_run_only(self) -> None: | |
| assert plan.confidence_level == 0.99 | ||
| assert not plan.is_single_run | ||
|
|
||
| @pytest.mark.parametrize("source", [param("cli"), param("yaml")]) | ||
| @pytest.mark.parametrize( | ||
| "export_level", | ||
| [param(ExportLevel.SUMMARY), param(ExportLevel.RECORDS), param(ExportLevel.RAW)], | ||
| ) # fmt: skip | ||
| def test_distribution_convergence_respects_export_level( | ||
| self, source: str, export_level: ExportLevel, tmp_path: Path | ||
| ) -> None: | ||
| if source == "cli": | ||
| config = resolve_config( | ||
| CLIConfig( | ||
| model_names=["test-model"], | ||
| url="http://localhost:8000", | ||
| num_profile_runs=3, | ||
| convergence_metric="request_latency", | ||
| convergence_mode="distribution", | ||
| export_level=export_level, | ||
| ) | ||
| ) | ||
| plan = build_benchmark_plan(config) | ||
| else: | ||
| path = tmp_path / "benchmark.yaml" | ||
| path.write_text( | ||
| yaml.safe_dump( | ||
| { | ||
| "benchmark": { | ||
| **_MINIMAL_CONFIG_KWARGS, | ||
| "artifacts": { | ||
| "records": False | ||
| if export_level == ExportLevel.SUMMARY | ||
| else ["jsonl"], | ||
| "raw": export_level == ExportLevel.RAW, | ||
| }, | ||
| }, | ||
| "multi_run": { | ||
| "num_runs": 3, | ||
| "convergence": { | ||
| "metric": "request_latency", | ||
| "mode": "distribution", | ||
| }, | ||
| }, | ||
| } | ||
| ) | ||
| ) | ||
| plan = load_benchmark_plan(path, substitute_env=False) | ||
|
|
||
| assert plan.configs[0].artifacts.export_level == export_level | ||
| assert plan.export_level == export_level | ||
| if export_level == ExportLevel.SUMMARY: | ||
| with pytest.raises(ValueError, match="requires per-request JSONL data"): | ||
| validate_convergence_config(plan) | ||
| else: | ||
| validate_convergence_config(plan) | ||
|
|
||
| @pytest.mark.parametrize( | ||
| "sweep_type", [param("grid"), param("zip"), param("scenarios")] | ||
| ) # fmt: skip | ||
| @pytest.mark.parametrize( | ||
| "base_records, swept_field, values, expected_levels", | ||
| [ | ||
| param( | ||
| True, "records", [["jsonl"], False], ["records", "summary"], | ||
| id="summary-last", | ||
| ), | ||
| param( | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The 🤖 AI FixRemove the |
||
| True, "records", [False, ["jsonl"]], ["summary", "records"], | ||
| id="summary-first", | ||
| ), | ||
| param( | ||
| False, "records", [["jsonl"], ["jsonl"]], ["records", "records"], | ||
| id="summary-base-overridden", | ||
| ), | ||
| param( | ||
| True, "raw", [False, True], ["records", "raw"], | ||
| id="mixed-records-raw", | ||
| ), | ||
| ], | ||
| ) # fmt: skip | ||
| def test_distribution_convergence_checks_expanded_sweep_exports( | ||
| self, | ||
| sweep_type: str, | ||
| base_records: bool, | ||
| swept_field: str, | ||
| values: list[object], | ||
| expected_levels: list[str], | ||
| tmp_path: Path, | ||
| ) -> None: | ||
| sweep: dict[str, object] = { | ||
| "type": sweep_type, | ||
| "iteration_order": "independent", | ||
| } | ||
| if sweep_type == "scenarios": | ||
| sweep["runs"] = [ | ||
| {"name": f"point-{i}", "benchmark": {"artifacts": {swept_field: value}}} | ||
| for i, value in enumerate(values) | ||
| ] | ||
| else: | ||
| sweep["parameters"] = {f"artifacts.{swept_field}": values} | ||
| path = tmp_path / "sweep.yaml" | ||
| path.write_text( | ||
| yaml.safe_dump( | ||
| { | ||
| "benchmark": { | ||
| **_MINIMAL_CONFIG_KWARGS, | ||
| "artifacts": { | ||
| "records": ["jsonl"] if base_records else False, | ||
| "raw": False, | ||
| }, | ||
| }, | ||
| "sweep": sweep, | ||
| "multi_run": { | ||
| "num_runs": 3, | ||
| "convergence": { | ||
| "metric": "request_latency", | ||
| "mode": "distribution", | ||
| }, | ||
| }, | ||
| } | ||
| ) | ||
| ) | ||
| plan = load_benchmark_plan(path, substitute_env=False) | ||
|
|
||
| assert [cfg.artifacts.export_level for cfg in plan.configs] == expected_levels | ||
| if "summary" in expected_levels: | ||
| with pytest.raises( | ||
| ValueError, match="requires per-request JSONL data" | ||
| ) as exc: | ||
| validate_convergence_config(plan) | ||
| assert f"config {expected_levels.index('summary') + 1}" in str(exc.value) | ||
| else: | ||
| validate_convergence_config(plan) | ||
|
|
||
| def test_grid_sweep(self) -> None: | ||
| config = _make_aiperf_config( | ||
| sweep={ | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,126 @@ | ||
| # SPDX-FileCopyrightText: Copyright (c) 2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved. | ||
| # SPDX-License-Identifier: Apache-2.0 | ||
| """Validate dynamically proposed exports without running an optimizer or benchmark.""" | ||
|
|
||
| from pathlib import Path | ||
| from unittest.mock import AsyncMock, MagicMock | ||
|
|
||
| import pytest | ||
| from pytest import param | ||
|
|
||
| from aiperf.cli_runner._strategy import validate_convergence_config | ||
| from aiperf.config import AIPerfConfig, BenchmarkConfig | ||
| from aiperf.config.loader import build_benchmark_plan | ||
| from aiperf.config.sweep import SweepVariation, _set_nested_value | ||
| from aiperf.orchestrator.executor import RunExecutor | ||
| from aiperf.orchestrator.orchestrator import MultiRunOrchestrator | ||
|
|
||
|
|
||
| @pytest.mark.asyncio | ||
| @pytest.mark.parametrize( | ||
| "mode, records, raw_values, rejected_index", | ||
| [ | ||
| param("distribution", False, [0], 0, id="summary-first"), | ||
| param("distribution", False, [1, 0], 1, id="summary-after-valid-point"), | ||
| param("distribution", False, [1, 1], None, id="raw-points"), | ||
| param("distribution", True, [0, 1], None, id="mixed-records-raw"), | ||
| param("ci_width", False, [1, 0], None, id="ci-width-allows-summary"), | ||
| param("cv", False, [1, 0], None, id="cv-allows-summary"), | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The 🤖 AI FixDrop the |
||
| param(None, False, [1, 0], None, id="fixed-trials-allow-summary"), | ||
| ], | ||
| ) # fmt: skip | ||
| async def test_adaptive_search_validates_each_proposed_export( | ||
| mode: str | None, | ||
| records: bool, | ||
| raw_values: list[int], | ||
| rejected_index: int | None, | ||
| tmp_path: Path, | ||
| monkeypatch: pytest.MonkeyPatch, | ||
| ) -> None: | ||
| """Reject an invalid proposal before any of its trials can be dispatched.""" | ||
| config = AIPerfConfig.model_validate( | ||
| { | ||
| "benchmark": { | ||
| "models": ["test-model"], | ||
| "endpoint": {"urls": ["http://localhost:8000/v1/chat/completions"]}, | ||
| "datasets": [{"name": "default", "type": "synthetic"}], | ||
| "phases": [ | ||
| { | ||
| "name": "profiling", | ||
| "type": "concurrency", | ||
| "concurrency": 1, | ||
| "requests": 10, | ||
| } | ||
| ], | ||
| "artifacts": {"records": ["jsonl"] if records else False, "raw": True}, | ||
| }, | ||
| "multi_run": { | ||
| "num_runs": 3, | ||
| "convergence": {"metric": "request_latency", "mode": mode} | ||
| if mode is not None | ||
| else None, | ||
| }, | ||
| "sweep": { | ||
| "type": "adaptive_search", | ||
| "search_space": [ | ||
| {"path": "artifacts.raw", "lo": 0, "hi": 1, "kind": "int"} | ||
| ], | ||
| "objectives": [ | ||
| { | ||
| "metric": "output_token_throughput", | ||
| "stat": "avg", | ||
| "direction": "maximize", | ||
| } | ||
| ], | ||
| "max_iterations": 10, | ||
| }, | ||
| } | ||
| ) | ||
| plan = build_benchmark_plan(config) | ||
| validate_convergence_config(plan) | ||
|
|
||
| proposals = [] | ||
| for index, raw in enumerate(raw_values): | ||
| cfg_dict = plan.configs[0].model_dump(mode="python", exclude_none=True) | ||
| _set_nested_value(cfg_dict, "artifacts.raw", raw) | ||
| proposals.append( | ||
| ( | ||
| BenchmarkConfig.model_validate(cfg_dict), | ||
| SweepVariation( | ||
| index=index, | ||
| label=f"search_iter_{index:04d}", | ||
| values={"artifacts.raw": raw}, | ||
| ), | ||
| ) | ||
| ) | ||
| planner = MagicMock() | ||
| planner.history.return_value = [] | ||
| planner.ask.side_effect = [*proposals, None] | ||
| planner.iter_count = len(proposals) | ||
| planner.convergence_reason.return_value = "max_iterations" | ||
|
|
||
| orchestrator = MultiRunOrchestrator(base_dir=tmp_path) | ||
| run_cell = AsyncMock(return_value=([], False)) | ||
| monkeypatch.setattr(orchestrator, "_run_independent_cell", run_cell) | ||
| monkeypatch.setattr( | ||
| "aiperf.exporters.search_history.write_search_history", MagicMock() | ||
| ) | ||
| monkeypatch.setattr( | ||
| "aiperf.orchestrator.search_planner.write_search_checkpoint", MagicMock() | ||
| ) | ||
| executor = MagicMock(spec=RunExecutor) | ||
| if rejected_index is not None: | ||
| with pytest.raises( | ||
| ValueError, | ||
| match=f"search iteration {rejected_index} has export level 'summary'", | ||
| ): | ||
| await orchestrator.execute(plan, executor, search_planner=planner) | ||
| else: | ||
| await orchestrator.execute(plan, executor, search_planner=planner) | ||
|
|
||
| executed_count = rejected_index if rejected_index is not None else len(proposals) | ||
| assert run_cell.await_count == executed_count | ||
| assert [ | ||
| call.kwargs["variation"].index for call in run_cell.await_args_list | ||
| ] == list(range(executed_count)) | ||
| assert planner.tell.call_count == executed_count | ||
Uh oh!
There was an error while loading. Please reload this page.