From 1a779ad7ecb9e5215b6bd1cfa0153469d37e4274 Mon Sep 17 00:00:00 2001 From: Jared T Nielsen Date: Mon, 24 Aug 2020 04:27:58 -0700 Subject: [PATCH] Specify config filename (#6626) --- src/transformers/hf_argparser.py | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/src/transformers/hf_argparser.py b/src/transformers/hf_argparser.py index af350c1128..f1b4f31526 100644 --- a/src/transformers/hf_argparser.py +++ b/src/transformers/hf_argparser.py @@ -88,7 +88,7 @@ class HfArgumentParser(ArgumentParser): self.add_argument(field_name, **kwargs) def parse_args_into_dataclasses( - self, args=None, return_remaining_strings=False, look_for_args_file=True + self, args=None, return_remaining_strings=False, look_for_args_file=True, args_filename=None ) -> Tuple[DataClass, ...]: """ Parse command-line args into instances of the specified dataclass types. @@ -107,6 +107,9 @@ class HfArgumentParser(ArgumentParser): If true, will look for a ".args" file with the same base name as the entry point script for this process, and will append its potential content to the command line args. + args_filename: + If not None, will uses this file instead of the ".args" file + specified in the previous argument. Returns: Tuple consisting of: @@ -118,8 +121,12 @@ class HfArgumentParser(ArgumentParser): - The potential list of remaining argument strings. (same as argparse.ArgumentParser.parse_known_args) """ - if look_for_args_file and len(sys.argv): - args_file = Path(sys.argv[0]).with_suffix(".args") + if args_filename or (look_for_args_file and len(sys.argv)): + if args_filename: + args_file = Path(args_filename) + else: + args_file = Path(sys.argv[0]).with_suffix(".args") + if args_file.exists(): fargs = args_file.read_text().split() args = fargs + args if args is not None else fargs + sys.argv[1:]