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
40 changes: 13 additions & 27 deletions src/guidellm/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,45 +3,31 @@
evaluating and benchmarking large language models (LLMs).
"""

import contextlib
import logging
import os
import asyncio
import warnings

from datasets import config
# Configure uvloop if available
try:
import uvloop

with (
open(os.devnull, "w") as devnull, # noqa: PTH123
contextlib.redirect_stderr(devnull),
contextlib.redirect_stdout(devnull),
):
from transformers.utils import logging as hf_logging # type: ignore[import]

# Set the log level for the transformers library to ERROR
# to ignore None of PyTorch, TensorFlow found
os.environ["TOKENIZERS_PARALLELISM"] = "false" # Silence warnings for tokenizers
hf_logging.set_verbosity_error()
logging.getLogger("transformers").setLevel(logging.ERROR)
config.USE_AUDIO_DECODE = False
asyncio.set_event_loop_policy(uvloop.EventLoopPolicy())
except ImportError:
warnings.warn(
"uvloop is not installed. For improved performance, "
"consider installing the guidellm[perf] extras group.",
category=UserWarning,
stacklevel=2,
)

from .logger import configure_logger, logger
from .settings import (
DatasetSettings,
Environment,
LoggingSettings,
Settings,
print_config,
reload_settings,
settings,
)

__all__ = [
"DatasetSettings",
"Environment",
"LoggingSettings",
"Settings",
"configure_logger",
"logger",
"print_config",
"reload_settings",
"settings",
]
9 changes: 1 addition & 8 deletions src/guidellm/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,7 @@
import click
from pydantic import ValidationError

from guidellm.data import ShortPromptStrategy, process_dataset

try:
import uvloop
except ImportError:
uvloop = None # type: ignore[assignment] # Optional dependency
from guidellm.data import ShortPromptStrategy, process_dataset # isort: skip

import guidellm.utils.cli as cli_tools
from guidellm.backends import Backend, BackendType
Expand Down Expand Up @@ -497,8 +492,6 @@ def run(**kwargs): # noqa: C901
errs[0]["msg"], ctx=click.get_current_context(), param_hint=param_name
) from err

if uvloop is not None:
asyncio.set_event_loop_policy(uvloop.EventLoopPolicy())
asyncio.run(
benchmark_generative_text(
args=args,
Expand Down
33 changes: 2 additions & 31 deletions src/guidellm/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,13 @@

import json
from collections.abc import Sequence
from enum import Enum
from typing import Literal

from pydantic import BaseModel, Field, model_validator
from pydantic import BaseModel, Field
from pydantic_settings import BaseSettings, SettingsConfigDict

__all__ = [
"DatasetSettings",
"Environment",
"LoggingSettings",
"Settings",
"print_config",
Expand All @@ -19,25 +17,6 @@
]


class Environment(str, Enum):
"""
Enum for the supported environments
"""

LOCAL = "local"
DEV = "dev"
STAGING = "staging"
PROD = "prod"


ENV_REPORT_MAPPING = {
Environment.PROD: "https://raw.githubusercontent.com/vllm-project/guidellm/refs/heads/gh-pages/ui/v0.5.4/index.html",
Environment.STAGING: "https://raw.githubusercontent.com/vllm-project/guidellm/refs/heads/gh-pages/ui/release/v0.4.0/index.html",
Environment.DEV: "https://raw.githubusercontent.com/vllm-project/guidellm/refs/heads/gh-pages/ui/dev/index.html",
Environment.LOCAL: "http://localhost:3000/index.html",
}


class LoggingSettings(BaseModel):
"""
Logging settings for the application
Expand Down Expand Up @@ -79,7 +58,7 @@ class ReportGenerationSettings(BaseModel):
Report generation settings for the application
"""

source: str = ""
source: str = "https://raw.githubusercontent.com/vllm-project/guidellm/refs/heads/gh-pages/ui/v0.5.4/index.html"


class Settings(BaseSettings):
Expand All @@ -103,7 +82,6 @@ class Settings(BaseSettings):
)

# general settings
env: Environment = Environment.PROD
default_async_loop_sleep: float = 10e-5
logging: LoggingSettings = LoggingSettings()
default_sweep_number: int = 10
Expand Down Expand Up @@ -138,13 +116,6 @@ class Settings(BaseSettings):
table_headers_border_char: str = "-"
table_column_separator_char: str = "|"

@model_validator(mode="after")
@classmethod
def set_default_source(cls, values):
if not values.report_generation.source:
values.report_generation.source = ENV_REPORT_MAPPING.get(values.env)
return values

def generate_env_file(self) -> str:
"""
Generate the .env file from the current settings
Expand Down
24 changes: 0 additions & 24 deletions tests/unit/test_settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

from guidellm.settings import (
DatasetSettings,
Environment,
LoggingSettings,
ReportGenerationSettings,
Settings,
Expand All @@ -19,7 +18,6 @@
@pytest.mark.smoke
def test_default_settings():
settings = Settings()
assert settings.env == Environment.PROD
assert settings.logging == LoggingSettings()
assert settings.report_generation.source.startswith(BASE_URL)

Expand All @@ -29,36 +27,16 @@ def test_settings_from_env_variables(mocker):
mocker.patch.dict(
"os.environ",
{
"GUIDELLM__env": "dev",
"GUIDELLM__logging__disabled": "true",
"GUIDELLM__REPORT_GENERATION__SOURCE": "http://custom.url",
},
)

settings = Settings()
assert settings.env == Environment.DEV
assert settings.logging.disabled is True
assert settings.report_generation.source == "http://custom.url"


@pytest.mark.smoke
def test_report_generation_default_source():
settings = Settings(env=Environment.LOCAL)
assert settings.report_generation.source == "http://localhost:3000/index.html"

settings = Settings(env=Environment.DEV)
assert (
settings.report_generation.source
== "https://raw.githubusercontent.com/vllm-project/guidellm/refs/heads/gh-pages/ui/dev/index.html"
)

settings = Settings(env=Environment.STAGING)
assert settings.report_generation.source.startswith(BASE_URL)

settings = Settings(env=Environment.PROD)
assert settings.report_generation.source.startswith(BASE_URL)


@pytest.mark.sanity
def test_logging_settings():
logging_settings = LoggingSettings(
Expand Down Expand Up @@ -90,12 +68,10 @@ def test_reload_settings(mocker):
mocker.patch.dict(
"os.environ",
{
"GUIDELLM__env": "staging",
"GUIDELLM__logging__disabled": "false",
},
)
reload_settings()
assert settings.env == Environment.STAGING
assert settings.logging.disabled is False


Expand Down
Loading