Skip to content

Commit a5cb05d

Browse files
committed
Documentation pass
1 parent 2ce5d8c commit a5cb05d

File tree

3 files changed

+31
-8
lines changed

3 files changed

+31
-8
lines changed

src/guidellm/__main__.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,11 @@ def cli():
3939
click.Choice(get_builtin_scenarios()),
4040
),
4141
default=None,
42-
help=("TODO: A scenario or path to config"),
42+
help=(
43+
"The name of a builtin scenario or path to a config file. "
44+
"Missing values from the config will use defaults. "
45+
"Options specified on the commandline will override the scenario."
46+
),
4347
)
4448
@click.option(
4549
"--target",
@@ -277,9 +281,10 @@ def benchmark(
277281
_scenario = GenerativeTextScenario.model_validate(overrides)
278282
elif isinstance(scenario, Path):
279283
_scenario = GenerativeTextScenario.from_file(scenario, overrides)
280-
else:
284+
else: # Only builtins can make it here; click will catch anything else
281285
_scenario = GenerativeTextScenario.from_builtin(scenario, overrides)
282286
except ValidationError as e:
287+
# Translate pydantic valdation error to click argument error
283288
errs = e.errors(include_url=False, include_context=True, include_input=True)
284289
param_name = "--" + str(errs[0]["loc"][0]).replace("_", "-")
285290
raise click.BadParameter(

src/guidellm/benchmark/scenario.py

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,16 @@
2121

2222
@cache
2323
def get_builtin_scenarios() -> list[str]:
24+
"""Returns list of builtin scenario names."""
2425
return [p.stem for p in SCENARIO_DIR.glob("*.json")]
2526

2627

2728
def parse_float_list(value: Union[str, float, list[float]]) -> list[float]:
29+
"""
30+
Parse a comma separated string to a list of float
31+
or convert single float list of one or pass float
32+
list through.
33+
"""
2834
if isinstance(value, (int, float)):
2935
return [value]
3036
elif isinstance(value, list):
@@ -44,21 +50,30 @@ def parse_float_list(value: Union[str, float, list[float]]) -> list[float]:
4450

4551

4652
class Scenario(StandardBaseModel):
53+
"""
54+
Parent Scenario class with common options for all benchmarking types.
55+
"""
56+
4757
target: str
4858

4959
@classmethod
5060
def from_builtin(cls: type[T], name: str, overrides: Optional[dict] = None) -> T:
5161
filename = SCENARIO_DIR / f"{name}.json"
5262

5363
if not filename.is_file():
54-
raise ValueError(f"{name} is not a vaild builtin scenario")
64+
raise ValueError(f"{name} is not a valid builtin scenario")
5565

5666
return cls.from_file(filename, overrides)
5767

5868

5969
class GenerativeTextScenario(Scenario):
60-
# FIXME: This solves an issue with Pydantic and class types
70+
"""
71+
Scenario class for generative text benchmarks.
72+
"""
73+
6174
class Config:
75+
# NOTE: This prevents errors due to unvalidatable
76+
# types like PreTrainedTokenizerBase
6277
arbitrary_types_allowed = True
6378

6479
backend_type: BackendType = "openai_http"

src/guidellm/objects/pydantic.py

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010

1111
T = TypeVar("T", bound="StandardBaseModel")
1212

13+
1314
class StandardBaseModel(BaseModel):
1415
"""
1516
A base class for Pydantic models throughout GuideLLM enabling standard
@@ -37,9 +38,11 @@ def get_default(cls: type[T], field: str) -> Any:
3738
return cls.model_fields[field].default
3839

3940
@classmethod
40-
def from_file(
41-
cls: type[T], filename: Path, overrides: Optional[dict] = None
42-
) -> T:
41+
def from_file(cls: type[T], filename: Path, overrides: Optional[dict] = None) -> T:
42+
"""
43+
Attempt to create a new instance of the model using
44+
data loaded from json or yaml file.
45+
"""
4346
try:
4447
with filename.open() as f:
4548
if str(filename).endswith((".yaml", ".yml")):
@@ -48,7 +51,7 @@ def from_file(
4851
data = json.load(f)
4952
except (json.JSONDecodeError, yaml.YAMLError) as e:
5053
logger.error(f"Failed to parse {filename} as type {cls.__name__}")
51-
raise e
54+
raise ValueError(f"Error when parsing file: {filename}") from e
5255

5356
data.update(overrides)
5457
return cls.model_validate(data)

0 commit comments

Comments
 (0)