Skip to content

Commit

Permalink
add ignore extra args option
Browse files Browse the repository at this point in the history
  • Loading branch information
younesbelkada authored Jun 17, 2024
1 parent 3d04496 commit b497e03
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions trl/commands/cli_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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()
Expand Down Expand Up @@ -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}")

Expand Down

0 comments on commit b497e03

Please sign in to comment.