Skip to content

Commit 2af12ab

Browse files
authored
Cleanup __init__ (#647)
## Summary Clean up some `__init__` package code and move uvloop config to `__init__`. ## Details This clean up was originally a part of #641 but as that PR is blocked I decided to split it out. Removing the transformers logging config does not seem to have any real affect; I do not get logs either way. Importing any huggingface libraries incurs a significant time cost so this is a prereq to improving CLI responsiveness. Additionally uvloop should be configured as early as possible so moved the setup to `__init__`. --- - [x] "I certify that all code in this PR is my own, except as noted below." ## Use of AI - [ ] Includes AI-assisted code completion - [ ] Includes code generated by an AI application - [ ] Includes AI-generated tests (NOTE: AI written tests should have a docstring that includes `## WRITTEN BY AI ##`)
2 parents 4585257 + 8782b26 commit 2af12ab

File tree

4 files changed

+16
-90
lines changed

4 files changed

+16
-90
lines changed

src/guidellm/__init__.py

Lines changed: 13 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -3,45 +3,31 @@
33
evaluating and benchmarking large language models (LLMs).
44
"""
55

6-
import contextlib
7-
import logging
8-
import os
6+
import asyncio
7+
import warnings
98

10-
from datasets import config
9+
# Configure uvloop if available
10+
try:
11+
import uvloop
1112

12-
with (
13-
open(os.devnull, "w") as devnull, # noqa: PTH123
14-
contextlib.redirect_stderr(devnull),
15-
contextlib.redirect_stdout(devnull),
16-
):
17-
from transformers.utils import logging as hf_logging # type: ignore[import]
18-
19-
# Set the log level for the transformers library to ERROR
20-
# to ignore None of PyTorch, TensorFlow found
21-
os.environ["TOKENIZERS_PARALLELISM"] = "false" # Silence warnings for tokenizers
22-
hf_logging.set_verbosity_error()
23-
logging.getLogger("transformers").setLevel(logging.ERROR)
24-
config.USE_AUDIO_DECODE = False
13+
asyncio.set_event_loop_policy(uvloop.EventLoopPolicy())
14+
except ImportError:
15+
warnings.warn(
16+
"uvloop is not installed. For improved performance, "
17+
"consider installing the guidellm[perf] extras group.",
18+
category=UserWarning,
19+
stacklevel=2,
20+
)
2521

2622
from .logger import configure_logger, logger
2723
from .settings import (
28-
DatasetSettings,
29-
Environment,
30-
LoggingSettings,
31-
Settings,
32-
print_config,
3324
reload_settings,
3425
settings,
3526
)
3627

3728
__all__ = [
38-
"DatasetSettings",
39-
"Environment",
40-
"LoggingSettings",
41-
"Settings",
4229
"configure_logger",
4330
"logger",
44-
"print_config",
4531
"reload_settings",
4632
"settings",
4733
]

src/guidellm/__main__.py

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -30,12 +30,7 @@
3030
import click
3131
from pydantic import ValidationError
3232

33-
from guidellm.data import ShortPromptStrategy, process_dataset
34-
35-
try:
36-
import uvloop
37-
except ImportError:
38-
uvloop = None # type: ignore[assignment] # Optional dependency
33+
from guidellm.data import ShortPromptStrategy, process_dataset # isort: skip
3934

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

500-
if uvloop is not None:
501-
asyncio.set_event_loop_policy(uvloop.EventLoopPolicy())
502495
asyncio.run(
503496
benchmark_generative_text(
504497
args=args,

src/guidellm/settings.py

Lines changed: 2 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,13 @@
22

33
import json
44
from collections.abc import Sequence
5-
from enum import Enum
65
from typing import Literal
76

8-
from pydantic import BaseModel, Field, model_validator
7+
from pydantic import BaseModel, Field
98
from pydantic_settings import BaseSettings, SettingsConfigDict
109

1110
__all__ = [
1211
"DatasetSettings",
13-
"Environment",
1412
"LoggingSettings",
1513
"Settings",
1614
"print_config",
@@ -19,25 +17,6 @@
1917
]
2018

2119

22-
class Environment(str, Enum):
23-
"""
24-
Enum for the supported environments
25-
"""
26-
27-
LOCAL = "local"
28-
DEV = "dev"
29-
STAGING = "staging"
30-
PROD = "prod"
31-
32-
33-
ENV_REPORT_MAPPING = {
34-
Environment.PROD: "https://raw.githubusercontent.com/vllm-project/guidellm/refs/heads/gh-pages/ui/v0.5.4/index.html",
35-
Environment.STAGING: "https://raw.githubusercontent.com/vllm-project/guidellm/refs/heads/gh-pages/ui/release/v0.4.0/index.html",
36-
Environment.DEV: "https://raw.githubusercontent.com/vllm-project/guidellm/refs/heads/gh-pages/ui/dev/index.html",
37-
Environment.LOCAL: "http://localhost:3000/index.html",
38-
}
39-
40-
4120
class LoggingSettings(BaseModel):
4221
"""
4322
Logging settings for the application
@@ -79,7 +58,7 @@ class ReportGenerationSettings(BaseModel):
7958
Report generation settings for the application
8059
"""
8160

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

8463

8564
class Settings(BaseSettings):
@@ -103,7 +82,6 @@ class Settings(BaseSettings):
10382
)
10483

10584
# general settings
106-
env: Environment = Environment.PROD
10785
default_async_loop_sleep: float = 10e-5
10886
logging: LoggingSettings = LoggingSettings()
10987
default_sweep_number: int = 10
@@ -138,13 +116,6 @@ class Settings(BaseSettings):
138116
table_headers_border_char: str = "-"
139117
table_column_separator_char: str = "|"
140118

141-
@model_validator(mode="after")
142-
@classmethod
143-
def set_default_source(cls, values):
144-
if not values.report_generation.source:
145-
values.report_generation.source = ENV_REPORT_MAPPING.get(values.env)
146-
return values
147-
148119
def generate_env_file(self) -> str:
149120
"""
150121
Generate the .env file from the current settings

tests/unit/test_settings.py

Lines changed: 0 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22

33
from guidellm.settings import (
44
DatasetSettings,
5-
Environment,
65
LoggingSettings,
76
ReportGenerationSettings,
87
Settings,
@@ -19,7 +18,6 @@
1918
@pytest.mark.smoke
2019
def test_default_settings():
2120
settings = Settings()
22-
assert settings.env == Environment.PROD
2321
assert settings.logging == LoggingSettings()
2422
assert settings.report_generation.source.startswith(BASE_URL)
2523

@@ -29,36 +27,16 @@ def test_settings_from_env_variables(mocker):
2927
mocker.patch.dict(
3028
"os.environ",
3129
{
32-
"GUIDELLM__env": "dev",
3330
"GUIDELLM__logging__disabled": "true",
3431
"GUIDELLM__REPORT_GENERATION__SOURCE": "http://custom.url",
3532
},
3633
)
3734

3835
settings = Settings()
39-
assert settings.env == Environment.DEV
4036
assert settings.logging.disabled is True
4137
assert settings.report_generation.source == "http://custom.url"
4238

4339

44-
@pytest.mark.smoke
45-
def test_report_generation_default_source():
46-
settings = Settings(env=Environment.LOCAL)
47-
assert settings.report_generation.source == "http://localhost:3000/index.html"
48-
49-
settings = Settings(env=Environment.DEV)
50-
assert (
51-
settings.report_generation.source
52-
== "https://raw.githubusercontent.com/vllm-project/guidellm/refs/heads/gh-pages/ui/dev/index.html"
53-
)
54-
55-
settings = Settings(env=Environment.STAGING)
56-
assert settings.report_generation.source.startswith(BASE_URL)
57-
58-
settings = Settings(env=Environment.PROD)
59-
assert settings.report_generation.source.startswith(BASE_URL)
60-
61-
6240
@pytest.mark.sanity
6341
def test_logging_settings():
6442
logging_settings = LoggingSettings(
@@ -90,12 +68,10 @@ def test_reload_settings(mocker):
9068
mocker.patch.dict(
9169
"os.environ",
9270
{
93-
"GUIDELLM__env": "staging",
9471
"GUIDELLM__logging__disabled": "false",
9572
},
9673
)
9774
reload_settings()
98-
assert settings.env == Environment.STAGING
9975
assert settings.logging.disabled is False
10076

10177

0 commit comments

Comments
 (0)