Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 0 additions & 14 deletions src/guidellm/benchmark/output.py
Original file line number Diff line number Diff line change
Expand Up @@ -330,20 +330,6 @@ def _get_profile_str(self, benchmark: GenerativeBenchmark) -> str:

return ", ".join(f"{key}={value}" for key, value in profile_args.items())

def _get_args_str(self, benchmark: GenerativeBenchmark) -> str:
args = benchmark.args
args_dict = OrderedDict(
{
"max_number": args.max_number,
"max_duration": args.max_duration,
"warmup_number": args.warmup_number,
"warmup_duration": args.warmup_duration,
"cooldown_number": args.cooldown_number,
"cooldown_duration": args.cooldown_duration,
}
)
return ", ".join(f"{key}={value}" for key, value in args_dict.items())

def _print_section_header(self, title: str, indent: int = 0, new_lines: int = 2):
self._print_line(
f"{title}:",
Expand Down
2 changes: 1 addition & 1 deletion src/guidellm/scheduler/objects.py
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ class ScheduledRequestInfo(StandardBaseModel):
)
scheduler_start_time: float = Field(
description="Unix timestamp for the local time when scheduler processing began",
default=-1,
default=-1.0,
)

error: str | None = Field(
Expand Down
105 changes: 35 additions & 70 deletions tests/unit/benchmark/test_output.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
from guidellm.benchmark import (
GenerativeBenchmarksReport,
)
from guidellm.benchmark.output import GenerativeBenchmarksConsole
from guidellm.benchmark.output import GenerativeBenchmarkerConsole, GenerativeBenchmarkerCSV
from tests.unit.mock_benchmark import mock_generative_benchmark


Expand All @@ -37,8 +37,8 @@ def test_generative_benchmark_marshalling():
deserialized = GenerativeBenchmarksReport.model_validate(serialized)
deserialized_benchmark = deserialized.benchmarks[0]

for field in mock_benchmark.model_fields:
assert getattr(mock_benchmark, field) == getattr(deserialized_benchmark, field)
# model_dump as workaround for duplicate fields for computed fields.
assert mock_benchmark.model_dump() == deserialized_benchmark.model_dump()


def test_file_json():
Expand All @@ -55,8 +55,8 @@ def test_file_json():
loaded_report = GenerativeBenchmarksReport.load_file(mock_path)
loaded_benchmark = loaded_report.benchmarks[0]

for field in mock_benchmark.model_fields:
assert getattr(mock_benchmark, field) == getattr(loaded_benchmark, field)
# model_dump as workaround for duplicate fields for computed fields.
assert mock_benchmark.model_dump() == loaded_benchmark.model_dump()

mock_path.unlink()

Expand All @@ -75,18 +75,20 @@ def test_file_yaml():
loaded_report = GenerativeBenchmarksReport.load_file(mock_path)
loaded_benchmark = loaded_report.benchmarks[0]

for field in mock_benchmark.model_fields:
assert getattr(mock_benchmark, field) == getattr(loaded_benchmark, field)
# model_dump as workaround for duplicate fields for computed fields.
assert mock_benchmark.model_dump() == loaded_benchmark.model_dump()

mock_path.unlink()


def test_file_csv():
@pytest.mark.skip(reason="CSV fix not merged yet")
@pytest.mark.asyncio
async def test_file_csv():
mock_benchmark = mock_generative_benchmark()
report = GenerativeBenchmarksReport(benchmarks=[mock_benchmark])

mock_path = Path("mock_report.csv")
report.save_csv(mock_path)
csv_benchmarker = GenerativeBenchmarkerCSV(output_path=mock_path)
await csv_benchmarker.finalize(report)

with mock_path.open("r") as file:
reader = csv.reader(file)
Expand All @@ -100,109 +102,72 @@ def test_file_csv():


def test_console_benchmarks_profile_str():
console = GenerativeBenchmarksConsole(enabled=True)
console = GenerativeBenchmarkerConsole()
mock_benchmark = mock_generative_benchmark()
console.benchmarks = [mock_benchmark]
assert (
console.benchmarks_profile_str == "type=synchronous, strategies=['synchronous']"
)


def test_console_benchmarks_args_str():
console = GenerativeBenchmarksConsole(enabled=True)
mock_benchmark = mock_generative_benchmark()
console.benchmarks = [mock_benchmark]
assert console.benchmarks_args_str == (
"max_number=None, max_duration=10.0, warmup_number=None, "
"warmup_duration=None, cooldown_number=None, cooldown_duration=None"
console._get_profile_str(mock_benchmark) == "type=synchronous, strategies=['synchronous']"
)


def test_console_benchmarks_worker_desc_str():
console = GenerativeBenchmarksConsole(enabled=True)
mock_benchmark = mock_generative_benchmark()
console.benchmarks = [mock_benchmark]
assert console.benchmarks_worker_desc_str == str(mock_benchmark.worker)


def test_console_benchmarks_request_loader_desc_str():
console = GenerativeBenchmarksConsole(enabled=True)
mock_benchmark = mock_generative_benchmark()
console.benchmarks = [mock_benchmark]
assert console.benchmarks_request_loader_desc_str == str(
mock_benchmark.request_loader
)


def test_console_benchmarks_extras_str():
console = GenerativeBenchmarksConsole(enabled=True)
mock_benchmark = mock_generative_benchmark()
console.benchmarks = [mock_benchmark]
assert console.benchmarks_extras_str == "None"


def test_console_print_section_header():
console = GenerativeBenchmarksConsole(enabled=True)
console = GenerativeBenchmarkerConsole()
with patch.object(console.console, "print") as mock_print:
console.print_section_header("Test Header")
console._print_section_header("Test Header")
mock_print.assert_called_once()


def test_console_print_labeled_line():
console = GenerativeBenchmarksConsole(enabled=True)
console = GenerativeBenchmarkerConsole()
with patch.object(console.console, "print") as mock_print:
console.print_labeled_line("Label", "Value")
console._print_labeled_line("Label", "Value")
mock_print.assert_called_once()


def test_console_print_line():
console = GenerativeBenchmarksConsole(enabled=True)
console = GenerativeBenchmarkerConsole()
with patch.object(console.console, "print") as mock_print:
console.print_line("Test Line")
console._print_line("Test Line")
mock_print.assert_called_once()


def test_console_print_table():
console = GenerativeBenchmarksConsole(enabled=True)
console = GenerativeBenchmarkerConsole()
headers = ["Header1", "Header2"]
rows = [["Row1Col1", "Row1Col2"], ["Row2Col1", "Row2Col2"]]
with (
patch.object(console, "print_section_header") as mock_header,
patch.object(console, "print_table_divider") as mock_divider,
patch.object(console, "print_table_row") as mock_row,
patch.object(console, "_print_section_header") as mock_header,
patch.object(console, "_print_table_divider") as mock_divider,
patch.object(console, "_print_table_row") as mock_row,
):
console.print_table(headers, rows, "Test Table")
console._print_table(headers, rows, "Test Table")
mock_header.assert_called_once()
mock_divider.assert_called()
mock_row.assert_called()


def test_console_print_benchmarks_metadata():
console = GenerativeBenchmarksConsole(enabled=True)
console = GenerativeBenchmarkerConsole()
mock_benchmark = mock_generative_benchmark()
console.benchmarks = [mock_benchmark]
with (
patch.object(console, "print_section_header") as mock_header,
patch.object(console, "print_labeled_line") as mock_labeled,
patch.object(console, "_print_section_header") as mock_header,
patch.object(console, "_print_labeled_line") as mock_labeled,
):
console.print_benchmarks_metadata()
console._print_benchmarks_metadata([mock_benchmark])
mock_header.assert_called_once()
mock_labeled.assert_called()


def test_console_print_benchmarks_info():
console = GenerativeBenchmarksConsole(enabled=True)
console = GenerativeBenchmarkerConsole()
mock_benchmark = mock_generative_benchmark()
console.benchmarks = [mock_benchmark]
with patch.object(console, "print_table") as mock_table:
console.print_benchmarks_info()
with patch.object(console, "_print_table") as mock_table:
console._print_benchmarks_info([mock_benchmark])
mock_table.assert_called_once()


def test_console_print_benchmarks_stats():
console = GenerativeBenchmarksConsole(enabled=True)
console = GenerativeBenchmarkerConsole()
mock_benchmark = mock_generative_benchmark()
console.benchmarks = [mock_benchmark]
with patch.object(console, "print_table") as mock_table:
console.print_benchmarks_stats()
with patch.object(console, "_print_table") as mock_table:
console._print_benchmarks_stats([mock_benchmark])
mock_table.assert_called_once()
7 changes: 2 additions & 5 deletions tests/unit/mock_benchmark.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
"""Mock benchmark objects for unit testing."""

from guidellm.backend import GenerationRequestTimings
from guidellm.backends import GenerationRequestTimings
from guidellm.benchmark import (
BenchmarkSchedulerStats,
GenerativeBenchmark,
Expand Down Expand Up @@ -101,7 +100,7 @@ def mock_generative_benchmark() -> GenerativeBenchmark:
worker_targeted_start_delay_avg=0.1,
request_start_delay_avg=0.1,
request_time_avg=0.1,
request_targeted_delay_avg=0.1,
request_targeted_start_delay_avg=0.1,
),
start_time=1000.0,
end_time=2000.0,
Expand Down Expand Up @@ -130,8 +129,6 @@ def mock_generative_benchmark() -> GenerativeBenchmark:
scheduler_info=ScheduledRequestInfo(
request_timings=GenerationRequestTimings(
request_start=1,
first_iteration=2,
last_iteration=6,
request_end=6,
)
),
Expand Down
Loading