diff --git a/vllm/utils.py b/vllm/utils.py index a742ec8d76908..0b75e8761c916 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:]