mirror of
https://git.datalinker.icu/vllm-project/vllm.git
synced 2025-12-10 08:45:00 +08:00
Only run get_attr_docs if generating help text (#23723)
Signed-off-by: Harry Mellor <19981378+hmellor@users.noreply.github.com>
This commit is contained in:
parent
fe8d7b6f03
commit
513c1fe255
@ -152,9 +152,17 @@ def is_online_quantization(quantization: Any) -> bool:
|
||||
return quantization in ["inc"]
|
||||
|
||||
|
||||
NEEDS_HELP = (
|
||||
"--help" in (argv := sys.argv) # vllm SUBCOMMAND --help
|
||||
or (argv0 := argv[0]).endswith("mkdocs") # mkdocs SUBCOMMAND
|
||||
or argv0.endswith("mkdocs/__main__.py") # python -m mkdocs SUBCOMMAND
|
||||
)
|
||||
|
||||
|
||||
@functools.lru_cache(maxsize=30)
|
||||
def _compute_kwargs(cls: ConfigType) -> dict[str, Any]:
|
||||
cls_docs = get_attr_docs(cls)
|
||||
# Save time only getting attr docs if we're generating help text
|
||||
cls_docs = get_attr_docs(cls) if NEEDS_HELP else {}
|
||||
kwargs = {}
|
||||
for field in fields(cls):
|
||||
# Get the set of possible types for the field
|
||||
@ -172,7 +180,7 @@ def _compute_kwargs(cls: ConfigType) -> dict[str, Any]:
|
||||
|
||||
# Get the help text for the field
|
||||
name = field.name
|
||||
help = cls_docs[name].strip()
|
||||
help = cls_docs.get(name, "").strip()
|
||||
# Escape % for argparse
|
||||
help = help.replace("%", "%%")
|
||||
|
||||
@ -254,6 +262,9 @@ def _compute_kwargs(cls: ConfigType) -> dict[str, Any]:
|
||||
def get_kwargs(cls: ConfigType) -> dict[str, Any]:
|
||||
"""Return argparse kwargs for the given Config dataclass.
|
||||
|
||||
If `--help` or `mkdocs` are not present in the command line command, the
|
||||
attribute documentation will not be included in the help output.
|
||||
|
||||
The heavy computation is cached via functools.lru_cache, and a deep copy
|
||||
is returned so callers can mutate the dictionary without affecting the
|
||||
cached version.
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user