Skip to content

guidellm.benchmark.outputs.html

HTML output formatter for benchmark results.

Transforms benchmark data into interactive web-based reports by building UI data structures, converting keys to camelCase for JavaScript compatibility, and injecting formatted data into HTML templates. The formatter processes GenerativeBenchmark instances and their associated metrics, creating histogram buckets for distributions, formatting percentile statistics for tabular display, and embedding all data as JavaScript objects within an HTML template for client-side rendering and visualization.

GenerativeBenchmarkerHTML

Bases: GenerativeBenchmarkerOutput

HTML output formatter for benchmark results.

Generates interactive HTML reports from benchmark data by transforming results into camelCase JSON structures and injecting them into HTML templates. The formatter processes benchmark metrics, creates histogram distributions, and embeds all data into a pre-built HTML template for browser-based visualization. Reports are saved to the specified output path or current working directory.

Attributes:

Name Type Description
DEFAULT_FILE str

Default filename for HTML output when a directory is provided

Source code in src/guidellm/benchmark/outputs/html.py
@GenerativeBenchmarkerOutput.register("html")
class GenerativeBenchmarkerHTML(GenerativeBenchmarkerOutput):
    """
    HTML output formatter for benchmark results.

    Generates interactive HTML reports from benchmark data by transforming results
    into camelCase JSON structures and injecting them into HTML templates. The
    formatter processes benchmark metrics, creates histogram distributions, and
    embeds all data into a pre-built HTML template for browser-based visualization.
    Reports are saved to the specified output path or current working directory.

    :cvar DEFAULT_FILE: Default filename for HTML output when a directory is provided
    """

    DEFAULT_FILE: ClassVar[str] = "benchmarks.html"

    output_path: Path = Field(
        default_factory=Path.cwd,
        description=(
            "Directory or file path for saving the HTML report, "
            "defaults to current working directory"
        ),
    )

    @classmethod
    def from_args(cls, args: BenchmarkOutputArgs) -> GenerativeBenchmarkerHTML:
        """
        Create an HTML output formatter from output arguments.

        :param args: Output configuration with path
        :return: Configured HTML output formatter
        """
        if not isinstance(args, HTMLBenchmarkOutputArgs):
            raise TypeError(f"Expected HTMLBenchmarkOutputArgs, got {type(args)}")

        return cls(output_path=args.path)

    async def finalize(self, report: GenerativeBenchmarksReport) -> Path:
        """
        Generate and save the HTML benchmark report.

        Transforms benchmark data into camelCase JSON format, injects it into the
        HTML template, and writes the resulting report to the output path. Creates
        parent directories if they don't exist.

        :param report: Completed benchmark report containing all results
        :return: Path to the saved HTML report file
        """
        output_path = self.output_path
        if output_path.is_dir():
            output_path = output_path / self.DEFAULT_FILE
        output_path.parent.mkdir(parents=True, exist_ok=True)

        data = _build_ui_data(report.benchmarks, report.config)
        camel_data = recursive_key_update(deepcopy(data), camelize_str)

        ui_api_data = {
            f"window.{key} = {{}};": f"window.{key} = {json.dumps(value, indent=2)};\n"
            for key, value in camel_data.items()
        }

        _create_html_report(ui_api_data, output_path)

        return output_path

finalize(report) async

Generate and save the HTML benchmark report.

Transforms benchmark data into camelCase JSON format, injects it into the HTML template, and writes the resulting report to the output path. Creates parent directories if they don't exist.

Parameters:

Name Type Description Default
report GenerativeBenchmarksReport

Completed benchmark report containing all results

required

Returns:

Type Description
Path

Path to the saved HTML report file

Source code in src/guidellm/benchmark/outputs/html.py
async def finalize(self, report: GenerativeBenchmarksReport) -> Path:
    """
    Generate and save the HTML benchmark report.

    Transforms benchmark data into camelCase JSON format, injects it into the
    HTML template, and writes the resulting report to the output path. Creates
    parent directories if they don't exist.

    :param report: Completed benchmark report containing all results
    :return: Path to the saved HTML report file
    """
    output_path = self.output_path
    if output_path.is_dir():
        output_path = output_path / self.DEFAULT_FILE
    output_path.parent.mkdir(parents=True, exist_ok=True)

    data = _build_ui_data(report.benchmarks, report.config)
    camel_data = recursive_key_update(deepcopy(data), camelize_str)

    ui_api_data = {
        f"window.{key} = {{}};": f"window.{key} = {json.dumps(value, indent=2)};\n"
        for key, value in camel_data.items()
    }

    _create_html_report(ui_api_data, output_path)

    return output_path

from_args(args) classmethod

Create an HTML output formatter from output arguments.

Parameters:

Name Type Description Default
args BenchmarkOutputArgs

Output configuration with path

required

Returns:

Type Description
GenerativeBenchmarkerHTML

Configured HTML output formatter

Source code in src/guidellm/benchmark/outputs/html.py
@classmethod
def from_args(cls, args: BenchmarkOutputArgs) -> GenerativeBenchmarkerHTML:
    """
    Create an HTML output formatter from output arguments.

    :param args: Output configuration with path
    :return: Configured HTML output formatter
    """
    if not isinstance(args, HTMLBenchmarkOutputArgs):
        raise TypeError(f"Expected HTMLBenchmarkOutputArgs, got {type(args)}")

    return cls(output_path=args.path)

HTMLBenchmarkOutputArgs

Bases: BenchmarkOutputArgs

Model for HTML benchmark output arguments.

Source code in src/guidellm/benchmark/outputs/html.py
@BenchmarkOutputArgs.register("html")
class HTMLBenchmarkOutputArgs(BenchmarkOutputArgs):
    """Model for HTML benchmark output arguments."""

    kind: Literal["html"] = Field(
        default="html",
        description="The kind of output.",
    )
    path: Path = Field(
        default_factory=lambda: settings.default_results_dir / "benchmarks.html",
        description="The file to save the output to.",
    )