Skip to content

Commit a39b0a4

Browse files
chaunceyjiangweilong.yu
authored and
weilong.yu
committedDec 13, 2024
[Misc] vllm CLI flags should be ordered for better user readability (vllm-project#10017)
Signed-off-by: chaunceyjiang <chaunceyjiang@gmail.com>
1 parent 94bcba7 commit a39b0a4

File tree

1 file changed

+14
-0
lines changed

1 file changed

+14
-0
lines changed
 

‎vllm/utils.py

+14
Original file line numberDiff line numberDiff line change
@@ -1148,9 +1148,23 @@ def __call__(self, parser, namespace, values, option_string=None):
11481148
"Expected 'true' or 'false'.")
11491149

11501150

1151+
class SortedHelpFormatter(argparse.HelpFormatter):
1152+
"""SortedHelpFormatter that sorts arguments by their option strings."""
1153+
1154+
def add_arguments(self, actions):
1155+
actions = sorted(actions, key=lambda x: x.option_strings)
1156+
super(SortedHelpFormatter, self).add_arguments(actions)
1157+
1158+
11511159
class FlexibleArgumentParser(argparse.ArgumentParser):
11521160
"""ArgumentParser that allows both underscore and dash in names."""
11531161

1162+
def __init__(self, *args, **kwargs):
1163+
# Set the default 'formatter_class' to SortedHelpFormatter
1164+
if 'formatter_class' not in kwargs:
1165+
kwargs['formatter_class'] = SortedHelpFormatter
1166+
super().__init__(*args, **kwargs)
1167+
11541168
def parse_args(self, args=None, namespace=None):
11551169
if args is None:
11561170
args = sys.argv[1:]

0 commit comments

Comments
 (0)