-
Notifications
You must be signed in to change notification settings - Fork 43
Add report generation for OSU Benchmark #807
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
Open
allkoow
wants to merge
12
commits into
NVIDIA:main
Choose a base branch
from
allkoow:ako/osu-report-gen
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+498
−7
Open
Changes from all commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
5556f02
Add report generation for OSU Benchmark
allkoow b20fbe0
Merge branch 'main' into ako/osu-report-gen
allkoow d7958bb
Update number of reporters in ut
allkoow 23850e6
Update copyright year range in osu_bench
allkoow 38c3a35
Cover edge cases in osu bench ut
allkoow 012ea69
Handle missing size key in osu bench report
allkoow b6d18d7
Cover osu bench report in test_custom_reporters
allkoow aec7acf
Handle value error in osu report generation
allkoow d68ac3c
Add ut to handle ivalid output in osu bench
allkoow 218780c
Fix issue in osu bench ut format
allkoow e4427e3
Remove duplicated comment from osu_bench reporter
allkoow 7ee6d6c
Merge branch 'main' into ako/osu-report-gen
podkidyshev File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
148 changes: 148 additions & 0 deletions
148
src/cloudai/workloads/osu_bench/osu_comparison_report.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,148 @@ | ||
| # SPDX-FileCopyrightText: NVIDIA CORPORATION & AFFILIATES | ||
| # Copyright (c) 2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved. | ||
| # SPDX-License-Identifier: Apache-2.0 | ||
| # | ||
| # Licensed under the Apache License, Version 2.0 (the "License"); | ||
| # you may not use this file except in compliance with the License. | ||
| # You may obtain a copy of the License at | ||
| # | ||
| # http://www.apache.org/licenses/LICENSE-2.0 | ||
| # | ||
| # Unless required by applicable law or agreed to in writing, software | ||
| # distributed under the License is distributed on an "AS IS" BASIS, | ||
| # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| # See the License for the specific language governing permissions and | ||
| # limitations under the License. | ||
|
|
||
| from __future__ import annotations | ||
|
|
||
| import logging | ||
| from pathlib import Path | ||
| from typing import TYPE_CHECKING | ||
|
|
||
| from rich.table import Table | ||
|
|
||
| from cloudai.core import System, TestRun, TestScenario | ||
| from cloudai.report_generator.comparison_report import ComparisonReport, ComparisonReportConfig | ||
| from cloudai.report_generator.groups import GroupedTestRuns | ||
| from cloudai.util.lazy_imports import lazy | ||
|
|
||
| from .osu_bench import OSUBenchTestDefinition | ||
|
|
||
| if TYPE_CHECKING: | ||
| import bokeh.plotting as bk | ||
| import pandas as pd | ||
|
|
||
|
|
||
| class OSUBenchComparisonReport(ComparisonReport): | ||
| """Comparison report for OSU Bench.""" | ||
|
|
||
| INFO_COLUMNS = ("size",) | ||
|
|
||
| def __init__( | ||
| self, system: System, test_scenario: TestScenario, results_root: Path, config: ComparisonReportConfig | ||
| ) -> None: | ||
| super().__init__(system, test_scenario, results_root, config) | ||
| self.report_file_name = "osu_bench_comparison.html" | ||
|
|
||
| def load_test_runs(self): | ||
| super().load_test_runs() | ||
| self.trs = [tr for tr in self.trs if isinstance(tr.test, OSUBenchTestDefinition)] | ||
|
|
||
| def extract_data_as_df(self, tr: TestRun) -> pd.DataFrame: | ||
| csv_path = tr.output_path / "osu_bench.csv" | ||
| if not csv_path.exists(): | ||
| return lazy.pd.DataFrame() | ||
|
|
||
| df = lazy.pd.read_csv(csv_path) | ||
|
|
||
| if "size" not in df.columns: | ||
| logging.warning("%s: missing 'size' column, skipping", csv_path) | ||
| return lazy.pd.DataFrame() | ||
|
|
||
| df["size"] = df["size"].astype(int) | ||
| return df | ||
allkoow marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| @staticmethod | ||
| def _has_metric(dfs: list["pd.DataFrame"], col: str) -> bool: | ||
| """Only include a metric if all compared DataFrames have it.""" | ||
| return bool(dfs) and all((col in df.columns) and df[col].notna().any() for df in dfs) | ||
allkoow marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| def create_tables(self, cmp_groups: list[GroupedTestRuns]) -> list[Table]: | ||
| tables: list[Table] = [] | ||
| for group in cmp_groups: | ||
| dfs = [self.extract_data_as_df(item.tr) for item in group.items] | ||
|
|
||
| if self._has_metric(dfs, "avg_lat"): | ||
| tables.append( | ||
| self.create_table( | ||
| group, | ||
| dfs=dfs, | ||
| title="Latency", | ||
| info_columns=list(self.INFO_COLUMNS), | ||
| data_columns=["avg_lat"], | ||
| ) | ||
| ) | ||
| if self._has_metric(dfs, "mb_sec"): | ||
| tables.append( | ||
| self.create_table( | ||
| group, | ||
| dfs=dfs, | ||
| title="Bandwidth", | ||
| info_columns=list(self.INFO_COLUMNS), | ||
| data_columns=["mb_sec"], | ||
| ) | ||
| ) | ||
| if self._has_metric(dfs, "messages_sec"): | ||
| tables.append( | ||
| self.create_table( | ||
| group, | ||
| dfs=dfs, | ||
| title="Message Rate", | ||
| info_columns=list(self.INFO_COLUMNS), | ||
| data_columns=["messages_sec"], | ||
| ) | ||
| ) | ||
|
|
||
| return tables | ||
|
|
||
| def create_charts(self, cmp_groups: list[GroupedTestRuns]) -> list[bk.figure]: | ||
| charts: list[bk.figure] = [] | ||
| for group in cmp_groups: | ||
| dfs = [self.extract_data_as_df(item.tr) for item in group.items] | ||
|
|
||
| if self._has_metric(dfs, "avg_lat"): | ||
| charts.append( | ||
| self.create_chart( | ||
| group, | ||
| dfs, | ||
| "Latency", | ||
| list(self.INFO_COLUMNS), | ||
| ["avg_lat"], | ||
| "Time (us)", | ||
| ) | ||
| ) | ||
| if self._has_metric(dfs, "mb_sec"): | ||
| charts.append( | ||
| self.create_chart( | ||
| group, | ||
| dfs, | ||
| "Bandwidth", | ||
| list(self.INFO_COLUMNS), | ||
| ["mb_sec"], | ||
| "Bandwidth (MB/s)", | ||
| ) | ||
| ) | ||
| if self._has_metric(dfs, "messages_sec"): | ||
| charts.append( | ||
| self.create_chart( | ||
| group, | ||
| dfs, | ||
| "Message Rate", | ||
| list(self.INFO_COLUMNS), | ||
| ["messages_sec"], | ||
| "Messages/s", | ||
| ) | ||
| ) | ||
|
|
||
| return charts | ||
allkoow marked this conversation as resolved.
Show resolved
Hide resolved
allkoow marked this conversation as resolved.
Show resolved
Hide resolved
|
||
156 changes: 156 additions & 0 deletions
156
src/cloudai/workloads/osu_bench/report_generation_strategy.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,156 @@ | ||
| # SPDX-FileCopyrightText: NVIDIA CORPORATION & AFFILIATES | ||
| # Copyright (c) 2025-2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved. | ||
| # SPDX-License-Identifier: Apache-2.0 | ||
| # | ||
| # Licensed under the Apache License, Version 2.0 (the "License"); | ||
| # you may not use this file except in compliance with the License. | ||
| # You may obtain a copy of the License at | ||
| # | ||
| # http://www.apache.org/licenses/LICENSE-2.0 | ||
| # | ||
| # Unless required by applicable law or agreed to in writing, software | ||
| # distributed under the License is distributed on an "AS IS" BASIS, | ||
| # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| # See the License for the specific language governing permissions and | ||
| # limitations under the License. | ||
|
|
||
| from __future__ import annotations | ||
|
|
||
| import logging | ||
| import re | ||
| from enum import Enum | ||
| from functools import cache | ||
| from pathlib import Path | ||
| from typing import TYPE_CHECKING | ||
|
|
||
| from cloudai.core import ReportGenerationStrategy | ||
| from cloudai.util.lazy_imports import lazy | ||
|
|
||
| if TYPE_CHECKING: | ||
| import pandas as pd | ||
|
|
||
|
|
||
| class BenchmarkType(Enum): | ||
| """Type of benchmark to extract data from.""" | ||
|
|
||
| BANDWIDTH = 0 | ||
| """Bandwidth benchmark.""" | ||
|
|
||
| MULTIPLE_BANDWIDTH = 1 | ||
| """Multiple bandwidth benchmark.""" | ||
|
|
||
| LATENCY = 2 | ||
| """Latency benchmark.""" | ||
|
|
||
|
|
||
| HEADERS = { | ||
| BenchmarkType.LATENCY: ( | ||
| r"#\s*Size\s+Avg Latency\(us\)" | ||
| r"(?:\s+Min Latency\(us\)\s+Max Latency\(us\)\s+Iterations)?" | ||
| ), | ||
| BenchmarkType.MULTIPLE_BANDWIDTH: r"#\s*Size\s+MB/s\s+Messages/s", | ||
| BenchmarkType.BANDWIDTH: r"#\s*Size\s+Bandwidth\s*\(MB/s\)", | ||
| } | ||
|
|
||
|
|
||
| def _detect_benchmark_type(line: str) -> BenchmarkType | None: | ||
| for b_type, header in HEADERS.items(): | ||
| if re.match(header, line): | ||
| return b_type | ||
|
|
||
| return None | ||
|
|
||
|
|
||
| def _parse_data_row(parts: list[str], benchmark_type: BenchmarkType) -> list[str] | None: | ||
| if len(parts) < 2: | ||
| return None | ||
|
|
||
| try: | ||
| int(parts[0]) # message size | ||
| except ValueError: | ||
| return None | ||
|
|
||
| # Append row data based on benchmark type. | ||
| if benchmark_type == BenchmarkType.MULTIPLE_BANDWIDTH: | ||
| if len(parts) >= 3: | ||
| try: | ||
| float(parts[1]) # MB/s | ||
| float(parts[2]) # Messages/s | ||
| except ValueError: | ||
| return None | ||
| # size, MB/s, Messages/s | ||
| return [parts[0], parts[1], parts[2]] | ||
| return None | ||
|
|
||
| # BANDWIDTH and LATENCY: both use size + one value; column names in _columns_for_type | ||
| try: | ||
| float(parts[1]) # metric value | ||
| except ValueError: | ||
| return None | ||
| return [parts[0], parts[1]] | ||
coderabbitai[bot] marked this conversation as resolved.
Show resolved
Hide resolved
allkoow marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
|
|
||
| def _columns_for_type(benchmark_type: BenchmarkType) -> list[str]: | ||
| if benchmark_type == BenchmarkType.MULTIPLE_BANDWIDTH: | ||
| return ["size", "mb_sec", "messages_sec"] | ||
|
|
||
| if benchmark_type == BenchmarkType.BANDWIDTH: | ||
| return ["size", "mb_sec"] | ||
|
|
||
| return ["size", "avg_lat"] | ||
|
|
||
|
|
||
| @cache | ||
allkoow marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| def extract_osu_bench_data(stdout_file: Path) -> pd.DataFrame: | ||
| if not stdout_file.exists(): | ||
| logging.debug(f"{stdout_file} not found") | ||
| return lazy.pd.DataFrame() | ||
|
|
||
| data: list[list[str]] = [] | ||
| benchmark_type: BenchmarkType | None = None | ||
|
|
||
| for line in stdout_file.read_text().splitlines(): | ||
| if benchmark_type is None: | ||
| benchmark_type = _detect_benchmark_type(line) | ||
| continue | ||
|
|
||
| if row := _parse_data_row(line.split(), benchmark_type): | ||
| data.append(row) | ||
|
|
||
| if benchmark_type is None: | ||
| return lazy.pd.DataFrame() | ||
|
|
||
| columns = _columns_for_type(benchmark_type) | ||
| df = lazy.pd.DataFrame(data, columns=lazy.pd.Index(columns)) | ||
|
|
||
| df["size"] = df["size"].astype(int) | ||
|
|
||
| if "mb_sec" in df.columns: | ||
| df["mb_sec"] = df["mb_sec"].astype(float) | ||
|
|
||
| if "messages_sec" in df.columns: | ||
| df["messages_sec"] = df["messages_sec"].astype(float) | ||
|
|
||
| if "avg_lat" in df.columns: | ||
| df["avg_lat"] = df["avg_lat"].astype(float) | ||
|
|
||
| return df | ||
|
|
||
|
|
||
| class OSUBenchReportGenerationStrategy(ReportGenerationStrategy): | ||
| """Report generation strategy for OSU Bench.""" | ||
|
|
||
| @property | ||
| def results_file(self) -> Path: | ||
| return self.test_run.output_path / "stdout.txt" | ||
|
|
||
| def can_handle_directory(self) -> bool: | ||
| df = extract_osu_bench_data(self.results_file) | ||
| return not df.empty | ||
|
|
||
| def generate_report(self) -> None: | ||
| if not self.can_handle_directory(): | ||
| return | ||
|
|
||
| df = extract_osu_bench_data(self.results_file) | ||
| df.to_csv(self.test_run.output_path / "osu_bench.csv", index=False) | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.