@@ -152,9 +152,17 @@ def is_online_quantization(quantization: Any) -> bool:
152
152
return quantization in ["inc" ]
153
153
154
154
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
+
155
162
@functools .lru_cache (maxsize = 30 )
156
163
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 {}
158
166
kwargs = {}
159
167
for field in fields (cls ):
160
168
# Get the set of possible types for the field
@@ -172,7 +180,7 @@ def _compute_kwargs(cls: ConfigType) -> dict[str, Any]:
172
180
173
181
# Get the help text for the field
174
182
name = field .name
175
- help = cls_docs [ name ] .strip ()
183
+ help = cls_docs . get ( name , "" ) .strip ()
176
184
# Escape % for argparse
177
185
help = help .replace ("%" , "%%" )
178
186
@@ -254,6 +262,9 @@ def parse_dataclass(val: str, cls=dataclass_cls) -> Any:
254
262
def get_kwargs (cls : ConfigType ) -> dict [str , Any ]:
255
263
"""Return argparse kwargs for the given Config dataclass.
256
264
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
+
257
268
The heavy computation is cached via functools.lru_cache, and a deep copy
258
269
is returned so callers can mutate the dictionary without affecting the
259
270
cached version.
0 commit comments