Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TrlParser: Add ignore extra args option #1748

Merged
merged 2 commits into from
Jun 17, 2024
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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()
younesbelkada marked this conversation as resolved.
Show resolved Hide resolved
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
Loading