diff --git a/vllm/utils.py b/vllm/utils.py index a742ec8d76908..e4528a9ed203a 100644 --- a/vllm/utils.py +++ b/vllm/utils.py @@ -1148,9 +1148,23 @@ def __call__(self, parser, namespace, values, option_string=None): "Expected 'true' or 'false'.") +class SortedHelpFormatter(argparse.HelpFormatter): + """SortedHelpFormatter that sorts arguments by their option strings.""" + + def add_arguments(self, actions): + actions = sorted(actions, key=lambda x: x.option_strings) + super(SortedHelpFormatter, self).add_arguments(actions) + + class FlexibleArgumentParser(argparse.ArgumentParser): """ArgumentParser that allows both underscore and dash in names.""" + def __init__(self, *args, **kwargs): + # Set the default 'formatter_class' to SortedHelpFormatter + if 'formatter_class' not in kwargs: + kwargs['formatter_class'] = SortedHelpFormatter + super().__init__(*args, **kwargs) + def parse_args(self, args=None, namespace=None): if args is None: args = sys.argv[1:] @@ -1214,7 +1228,7 @@ def _pull_args_from_config(self, args: List[str]) -> List[str]: index = args.index('--config') if index == len(args) - 1: raise ValueError("No config file specified! \ - Please check your command-line arguments.") + Please check your command-line arguments." ) file_path = args[index + 1] @@ -1258,7 +1272,7 @@ def _load_config_file(self, file_path: str) -> List[str]: if extension not in ('yaml', 'yml'): raise ValueError( "Config file must be of a yaml/yml type.\ - %s supplied", extension) + %s supplied" , extension) # only expecting a flat dictionary of atomic types processed_args: List[str] = [] @@ -1270,7 +1284,7 @@ def _load_config_file(self, file_path: str) -> List[str]: except Exception as ex: logger.error( "Unable to read the config file at %s. \ - Make sure path is correct", file_path) + Make sure path is correct" , file_path) raise ex store_boolean_arguments = [