Skip to content
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

38 guidance reportjson from default flow is very large #60

Draft
wants to merge 3 commits into
base: main
Choose a base branch
from
Draft
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
1 change: 1 addition & 0 deletions src/guidellm/backend/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -309,6 +309,7 @@ def _cachable_default_model(backend: Backend) -> str:
:rtype: str
:raises ValueError: If no models are available.
"""

logger.debug("Getting default model for backend: {}", backend)
models = backend.available_models()
if models:
Expand Down
4 changes: 4 additions & 0 deletions src/guidellm/backend/openai.py
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,7 @@ async def make_request(
stream=True,
**request_args,
)

token_count = 0
async for chunk in stream:
choice = chunk.choices[0]
Expand Down Expand Up @@ -145,6 +146,9 @@ def available_models(self) -> List[str]:
:raises openai.OpenAIError: If an error occurs while retrieving models.
"""

# TODO: Remove this line
return ["Meta-Llama-3-8B.Q4_K_M.gguf"]

try:
return [model.id for model in self._client.models.list().data]
except Exception as error:
Expand Down
66 changes: 64 additions & 2 deletions src/guidellm/core/report.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import time
from datetime import datetime
from typing import List, Optional
from pathlib import Path
from typing import List, Literal, Optional, Union, get_args

from loguru import logger
from pydantic import Field
Expand All @@ -10,11 +11,14 @@
from rich.table import Table

from guidellm.core.result import TextGenerationBenchmark, TextGenerationBenchmarkReport
from guidellm.core.serializable import Serializable
from guidellm.core.serializable import Serializable, SerializableFileType

__all__ = ["GuidanceReport"]


FlatFileType = Literal["csv"]


def _create_benchmark_report_details(report: TextGenerationBenchmarkReport) -> str:
"""
Create a detailed string representation of a benchmark report.
Expand Down Expand Up @@ -319,3 +323,61 @@ def print(
console.print(report_viz)

logger.info("Guidance report printing completed.")

def _get_data(self):
"""
Select the data from the report and return it
in a flat format to be saved to the CSV file.
"""

raise NotImplementedError("Work in progress...")

def save_data(
self,
path: Union[str, Path],
type_: FlatFileType = "csv",
) -> str:
"""
Save the data to a file in CSV format.

:param path: Path to the exact file or the containing directory.
If it is a directory, the file name will be inferred from the class name.
:param type_: Optional type to save ('csv' is only supported).
:return: The path to the saved file.
"""

logger.debug("Saving to file... {} with format: {}", path, type_)

if isinstance(path, str):
path = Path(path)

if path.suffix:
# is a file
ext = path.suffix[1:].lower()
if type_ not in get_args(FlatFileType):
raise ValueError(
f"Unsupported file extension: {type_}. "
f"Expected one of {SerializableFileType} "
f"for {path}"
)
type_ = ext # type: ignore # noqa: PGH003
else:
# is a directory
file_name = f"{self.__class__.__name__.lower()}.{type_}"
path = path / file_name

path.parent.mkdir(parents=True, exist_ok=True)

with path.open("w") as file:
if type_ == "csv":
file.write(self._get_data())
else:
raise ValueError(
f"Unsupported file extension: {type_}"
f"Expected one of {SerializableFileType} "
f"for {path}"
)

logger.info("Successfully saved {} to {}", self.__class__.__name__, path)

return str(path)
33 changes: 25 additions & 8 deletions src/guidellm/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@
),
)
@click.option(
"--output-path",
"--output-report-path",
type=str,
default=None,
help=(
Expand All @@ -142,6 +142,16 @@
"printed to the console."
),
)
@click.option(
"--output-data-path",
type=str,
default=None,
help=(
"The output path to save flat data results. "
"Ex: --output-data-path=data.csv"
"The default is None, meaning a file won't be generated."
),
)
@click.option(
"--enable-continuous-refresh",
is_flag=True,
Expand All @@ -162,7 +172,8 @@ def generate_benchmark_report_cli(
rate: Optional[float],
max_seconds: Optional[int],
max_requests: Optional[int],
output_path: str,
output_report_path: str,
output_data_path: str,
enable_continuous_refresh: bool,
):
"""
Expand All @@ -179,7 +190,8 @@ def generate_benchmark_report_cli(
rate=rate,
max_seconds=max_seconds,
max_requests=max_requests,
output_path=output_path,
output_report_path=output_report_path,
output_data_path=output_data_path,
cont_refresh_table=enable_continuous_refresh,
)

Expand All @@ -195,7 +207,8 @@ def generate_benchmark_report(
rate: Optional[float],
max_seconds: Optional[int],
max_requests: Optional[int],
output_path: str,
output_report_path: str,
output_data_path: str,
cont_refresh_table: bool,
) -> GuidanceReport:
"""
Expand All @@ -216,6 +229,7 @@ def generate_benchmark_report(
:param max_seconds: Maximum duration for each benchmark run in seconds.
:param max_requests: Maximum number of requests per benchmark run.
:param output_path: Path to save the output report file.
:param output_csv_path: Path to save the flat output data.
:param cont_refresh_table: Continually refresh the table in the CLI
until the user exits.
"""
Expand All @@ -224,7 +238,7 @@ def generate_benchmark_report(
)

# Create backend
backend_inst = Backend.create(
backend_inst: Backend = Backend.create(
backend_type=backend,
target=target,
model=model,
Expand Down Expand Up @@ -284,11 +298,14 @@ def generate_benchmark_report(
guidance_report = GuidanceReport()
guidance_report.benchmarks.append(report)

if output_path:
guidance_report.save_file(output_path)
if output_report_path:
guidance_report.save_file(output_report_path)

if output_data_path:
guidance_report.save_file(output_report_path)

guidance_report.print(
save_path=output_path if output_path is not None else "stdout",
save_path=output_report_path if output_report_path is not None else "stdout",
continual_refresh=cont_refresh_table,
)

Expand Down
Loading