From 93dee88f6b0ff28c2e8b79d638b4e56d58128927 Mon Sep 17 00:00:00 2001 From: Chauncey Date: Tue, 5 Nov 2024 18:59:56 +0800 Subject: [PATCH] [Misc] vllm CLI flags should be ordered for better user readability (#10017) Signed-off-by: chaunceyjiang --- vllm/utils.py | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/vllm/utils.py b/vllm/utils.py index a742ec8d..0b75e876 100644 --- a/vllm/utils.py +++ b/vllm/utils.py @@ -1148,9 +1148,23 @@ class StoreBoolean(argparse.Action): "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:]