Skip to content

Commit 2ce5d8c

Browse files
committed
Add builtin scenarios
1 parent bcbaca9 commit 2ce5d8c

File tree

3 files changed

+25
-6
lines changed

3 files changed

+25
-6
lines changed

src/guidellm/__main__.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
from guidellm.backend import BackendType
99
from guidellm.benchmark import ProfileType
1010
from guidellm.benchmark.entrypoints import benchmark_with_scenario
11-
from guidellm.benchmark.scenario import GenerativeTextScenario
11+
from guidellm.benchmark.scenario import GenerativeTextScenario, get_builtin_scenarios
1212
from guidellm.config import print_config
1313
from guidellm.scheduler import StrategyType
1414
from guidellm.utils import cli as cli_tools
@@ -36,7 +36,7 @@ def cli():
3636
dir_okay=False,
3737
path_type=Path, # type: ignore[type-var]
3838
),
39-
click.STRING
39+
click.Choice(get_builtin_scenarios()),
4040
),
4141
default=None,
4242
help=("TODO: A scenario or path to config"),
@@ -278,8 +278,7 @@ def benchmark(
278278
elif isinstance(scenario, Path):
279279
_scenario = GenerativeTextScenario.from_file(scenario, overrides)
280280
else:
281-
# TODO: Add support for builtin scenarios
282-
raise NotImplementedError
281+
_scenario = GenerativeTextScenario.from_builtin(scenario, overrides)
283282
except ValidationError as e:
284283
errs = e.errors(include_url=False, include_context=True, include_input=True)
285284
param_name = "--" + str(errs[0]["loc"][0]).replace("_", "-")

src/guidellm/benchmark/scenario.py

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
from collections.abc import Iterable
2+
from functools import cache
23
from pathlib import Path
3-
from typing import Annotated, Any, Literal, Optional, Union
4+
from typing import Annotated, Any, Literal, Optional, TypeVar, Union
45

56
from datasets import Dataset, DatasetDict, IterableDataset, IterableDatasetDict
67
from pydantic import BeforeValidator, Field, NonNegativeInt, PositiveFloat, PositiveInt
@@ -13,7 +14,14 @@
1314
from guidellm.objects.pydantic import StandardBaseModel
1415
from guidellm.scheduler.strategy import StrategyType
1516

16-
__ALL__ = ["Scenario", "GenerativeTextScenario"]
17+
__ALL__ = ["Scenario", "GenerativeTextScenario", "get_builtin_scenarios"]
18+
19+
SCENARIO_DIR = Path(__file__).parent / "scenarios/"
20+
21+
22+
@cache
23+
def get_builtin_scenarios() -> list[str]:
24+
return [p.stem for p in SCENARIO_DIR.glob("*.json")]
1725

1826

1927
def parse_float_list(value: Union[str, float, list[float]]) -> list[float]:
@@ -32,9 +40,21 @@ def parse_float_list(value: Union[str, float, list[float]]) -> list[float]:
3240
) from err
3341

3442

43+
T = TypeVar("T", bound="Scenario")
44+
45+
3546
class Scenario(StandardBaseModel):
3647
target: str
3748

49+
@classmethod
50+
def from_builtin(cls: type[T], name: str, overrides: Optional[dict] = None) -> T:
51+
filename = SCENARIO_DIR / f"{name}.json"
52+
53+
if not filename.is_file():
54+
raise ValueError(f"{name} is not a vaild builtin scenario")
55+
56+
return cls.from_file(filename, overrides)
57+
3858

3959
class GenerativeTextScenario(Scenario):
4060
# FIXME: This solves an issue with Pydantic and class types

src/guidellm/benchmark/scenarios/__init__.py

Whitespace-only changes.

0 commit comments

Comments
 (0)