From b497e0362814cd6e95d691dc53f6d3ceeeab0da6 Mon Sep 17 00:00:00 2001 From: Younes Belkada <49240599+younesbelkada@users.noreply.github.com> Date: Mon, 17 Jun 2024 14:55:17 +0200 Subject: [PATCH] add ignore extra args option --- trl/commands/cli_utils.py | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/trl/commands/cli_utils.py b/trl/commands/cli_utils.py index 7cd9258fcb..586d8a0dd6 100644 --- a/trl/commands/cli_utils.py +++ b/trl/commands/cli_utils.py @@ -184,7 +184,7 @@ class ChatArguments: class TrlParser(HfArgumentParser): - def __init__(self, parsers): + def __init__(self, parsers, ignore_extra_args=False): """ The TRL parser parses a list of parsers (TrainingArguments, trl.ModelConfig, etc.), creates a config parsers for users that pass a valid `config` field and merge the values that are set in the config @@ -193,6 +193,9 @@ def __init__(self, parsers): Args: parsers (`List[argparse.ArgumentParser`]): List of parsers. + ignore_extra_args (`bool`): + Whether to ignore extra arguments passed by the config + and not raise errors. """ super().__init__(parsers) self.yaml_parser = YamlConfigParser() @@ -245,7 +248,7 @@ def parse_args_and_config(self, return_remaining_strings=False): return outputs[:-2], remaining_strings else: # outputs[-1] is either remaining yaml config as Namespace or parsed config as Dataclass - if isinstance(outputs[-1], Namespace): + if isinstance(outputs[-1], Namespace) and not self.ignore_extra_args: remaining_args = vars(outputs[-1]) raise ValueError(f"Some specified config arguments are not used by the TrlParser: {remaining_args}")