11# SPDX-License-Identifier: Apache-2.0
22# SPDX-FileCopyrightText: Copyright contributors to the vLLM project
33
4- import argparse
54import asyncio
65import dataclasses
76import functools
87import os
9- import subprocess
10- import sys
8+ from argparse import Namespace
119from typing import Any , Optional , Union
1210
1311from fastapi import Request
2523logger = init_logger (__name__ )
2624
2725VLLM_SUBCMD_PARSER_EPILOG = (
28- "Tip: Use `vllm [serve|run-batch|bench <bench_type>] "
29- "--help=<keyword>` to explore arguments from help.\n "
30- " - To view a argument group: --help=ModelConfig\n "
31- " - To view a single argument: --help=max-num-seqs\n "
32- " - To search by keyword: --help=max\n "
33- " - To list all groups: --help=listgroup\n "
34- " - To view help with pager: --help=page" )
26+ "For full list: vllm {subcmd} --help=all\n "
27+ "For a section: vllm {subcmd} --help=ModelConfig (case-insensitive)\n " # noqa: E501
28+ "For a flag: vllm {subcmd} --help=max-model-len (_ or - accepted)\n " # noqa: E501
29+ "Documentation: https://docs.vllm.ai\n " )
3530
3631
3732async def listen_for_disconnect (request : Request ) -> None :
@@ -196,96 +191,6 @@ def _validate_truncation_size(
196191 return truncate_prompt_tokens
197192
198193
199- def _output_with_pager (text : str ):
200- """Output text using scrolling view if available and appropriate."""
201-
202- pagers = ['less -R' , 'more' ]
203- for pager_cmd in pagers :
204- try :
205- proc = subprocess .Popen (pager_cmd .split (),
206- stdin = subprocess .PIPE ,
207- text = True )
208- proc .communicate (input = text )
209- return
210- except (subprocess .SubprocessError , OSError , FileNotFoundError ):
211- continue
212-
213- # No pager worked, fall back to normal print
214- print (text )
215-
216-
217- def show_filtered_argument_or_group_from_help (parser : argparse .ArgumentParser ,
218- subcommand_name : list [str ]):
219-
220- # Only handle --help=<keyword> for the current subcommand.
221- # Since subparser_init() runs for all subcommands during CLI setup,
222- # we skip processing if the subcommand name is not in sys.argv.
223- # sys.argv[0] is the program name. The subcommand follows.
224- # e.g., for `vllm bench latency`,
225- # sys.argv is `['vllm', 'bench', 'latency', ...]`
226- # and subcommand_name is "bench latency".
227- if len (sys .argv ) <= len (subcommand_name ) or sys .argv [
228- 1 :1 + len (subcommand_name )] != subcommand_name :
229- return
230-
231- for arg in sys .argv :
232- if arg .startswith ('--help=' ):
233- search_keyword = arg .split ('=' , 1 )[1 ]
234-
235- # Enable paged view for full help
236- if search_keyword == 'page' :
237- help_text = parser .format_help ()
238- _output_with_pager (help_text )
239- sys .exit (0 )
240-
241- # List available groups
242- if search_keyword == 'listgroup' :
243- output_lines = ["\n Available argument groups:" ]
244- for group in parser ._action_groups :
245- if group .title and not group .title .startswith (
246- "positional arguments" ):
247- output_lines .append (f" - { group .title } " )
248- if group .description :
249- output_lines .append (" " +
250- group .description .strip ())
251- output_lines .append ("" )
252- _output_with_pager ("\n " .join (output_lines ))
253- sys .exit (0 )
254-
255- # For group search
256- formatter = parser ._get_formatter ()
257- for group in parser ._action_groups :
258- if group .title and group .title .lower () == search_keyword .lower (
259- ):
260- formatter .start_section (group .title )
261- formatter .add_text (group .description )
262- formatter .add_arguments (group ._group_actions )
263- formatter .end_section ()
264- _output_with_pager (formatter .format_help ())
265- sys .exit (0 )
266-
267- # For single arg
268- matched_actions = []
269-
270- for group in parser ._action_groups :
271- for action in group ._group_actions :
272- # search option name
273- if any (search_keyword .lower () in opt .lower ()
274- for opt in action .option_strings ):
275- matched_actions .append (action )
276-
277- if matched_actions :
278- header = f"\n Parameters matching '{ search_keyword } ':\n "
279- formatter = parser ._get_formatter ()
280- formatter .add_arguments (matched_actions )
281- _output_with_pager (header + formatter .format_help ())
282- sys .exit (0 )
283-
284- print (f"\n No group or parameter matching '{ search_keyword } '" )
285- print ("Tip: use `--help=listgroup` to view all groups." )
286- sys .exit (1 )
287-
288-
289194def get_max_tokens (max_model_len : int , request : Union [ChatCompletionRequest ,
290195 CompletionRequest ],
291196 input_length : int , default_sampling_params : dict ) -> int :
@@ -301,11 +206,11 @@ def get_max_tokens(max_model_len: int, request: Union[ChatCompletionRequest,
301206 if val is not None )
302207
303208
304- def log_non_default_args (args : Union [argparse . Namespace , EngineArgs ]):
209+ def log_non_default_args (args : Union [Namespace , EngineArgs ]):
305210 non_default_args = {}
306211
307- # Handle argparse. Namespace
308- if isinstance (args , argparse . Namespace ):
212+ # Handle Namespace
213+ if isinstance (args , Namespace ):
309214 parser = make_arg_parser (FlexibleArgumentParser ())
310215 for arg , default in vars (parser .parse_args ([])).items ():
311216 if default != getattr (args , arg ):
@@ -323,6 +228,6 @@ def log_non_default_args(args: Union[argparse.Namespace, EngineArgs]):
323228 non_default_args ["model" ] = default_args .model
324229 else :
325230 raise TypeError ("Unsupported argument type. " \
326- "Must be argparse. Namespace or EngineArgs instance." )
231+ "Must be Namespace or EngineArgs instance." )
327232
328233 logger .info ("non-default args: %s" , non_default_args )
0 commit comments