From daa4841e867fe54495559e8259f4c9f6922d6a89 Mon Sep 17 00:00:00 2001 From: YAMY <74099316+YAMY1234@users.noreply.github.com> Date: Thu, 15 Jan 2026 23:32:42 -0800 Subject: [PATCH] [ConfigArgumentMerger] Improve ConfigArgumentMerger compatibility with external callers (#17051) --- .../sglang/srt/server_args_config_parser.py | 46 ++++++++++++------- 1 file changed, 29 insertions(+), 17 deletions(-) diff --git a/python/sglang/srt/server_args_config_parser.py b/python/sglang/srt/server_args_config_parser.py index 0d063b65f..24de2e967 100644 --- a/python/sglang/srt/server_args_config_parser.py +++ b/python/sglang/srt/server_args_config_parser.py @@ -16,25 +16,37 @@ logger = logging.getLogger(__name__) class ConfigArgumentMerger: """Handles merging of configuration file arguments with command-line arguments.""" - def __init__(self, parser: argparse.ArgumentParser): + def __init__( + self, + parser: argparse.ArgumentParser = None, + boolean_actions: List[str] = None, + ): """Initialize with list of store_true action names.""" # NOTE: The current code does not support actions other than "store_true" and "store". - self.parser = parser - self.store_true_actions = [ - action.dest - for action in parser._actions - if isinstance(action, argparse._StoreTrueAction) - ] - self.unsupported_actions = { - a.dest: a - for a in parser._actions - if a.option_strings - and not isinstance(a, argparse._StoreTrueAction) - and not isinstance(a, argparse._StoreAction) - and "--config" not in a.option_strings - and "--help" not in a.option_strings - and "-h" not in a.option_strings - } + if parser is not None: + self.parser = parser + self.store_true_actions = [ + action.dest + for action in parser._actions + if isinstance(action, argparse._StoreTrueAction) + ] + self.unsupported_actions = { + a.dest: a + for a in parser._actions + if a.option_strings + and not isinstance(a, argparse._StoreTrueAction) + and not isinstance(a, argparse._StoreAction) + and "--config" not in a.option_strings + and "--help" not in a.option_strings + and "-h" not in a.option_strings + } + elif boolean_actions is not None: + # Legacy interface for compatibility + self.store_true_actions = boolean_actions + self.unsupported_actions = {} + else: + self.store_true_actions = [] + self.unsupported_actions = {} def merge_config_with_args(self, cli_args: List[str]) -> List[str]: """