Skip to content

Commit 513c1fe

Browse files
authored
Only run get_attr_docs if generating help text (vllm-project#23723)
Signed-off-by: Harry Mellor <[email protected]>
1 parent fe8d7b6 commit 513c1fe

File tree

1 file changed

+13
-2
lines changed

1 file changed

+13
-2
lines changed

vllm/engine/arg_utils.py

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -152,9 +152,17 @@ def is_online_quantization(quantization: Any) -> bool:
152152
return quantization in ["inc"]
153153

154154

155+
NEEDS_HELP = (
156+
"--help" in (argv := sys.argv) # vllm SUBCOMMAND --help
157+
or (argv0 := argv[0]).endswith("mkdocs") # mkdocs SUBCOMMAND
158+
or argv0.endswith("mkdocs/__main__.py") # python -m mkdocs SUBCOMMAND
159+
)
160+
161+
155162
@functools.lru_cache(maxsize=30)
156163
def _compute_kwargs(cls: ConfigType) -> dict[str, Any]:
157-
cls_docs = get_attr_docs(cls)
164+
# Save time only getting attr docs if we're generating help text
165+
cls_docs = get_attr_docs(cls) if NEEDS_HELP else {}
158166
kwargs = {}
159167
for field in fields(cls):
160168
# Get the set of possible types for the field
@@ -172,7 +180,7 @@ def _compute_kwargs(cls: ConfigType) -> dict[str, Any]:
172180

173181
# Get the help text for the field
174182
name = field.name
175-
help = cls_docs[name].strip()
183+
help = cls_docs.get(name, "").strip()
176184
# Escape % for argparse
177185
help = help.replace("%", "%%")
178186

@@ -254,6 +262,9 @@ def parse_dataclass(val: str, cls=dataclass_cls) -> Any:
254262
def get_kwargs(cls: ConfigType) -> dict[str, Any]:
255263
"""Return argparse kwargs for the given Config dataclass.
256264
265+
If `--help` or `mkdocs` are not present in the command line command, the
266+
attribute documentation will not be included in the help output.
267+
257268
The heavy computation is cached via functools.lru_cache, and a deep copy
258269
is returned so callers can mutate the dictionary without affecting the
259270
cached version.

0 commit comments

Comments
 (0)