Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
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
5 changes: 4 additions & 1 deletion paddlenlp/trainer/argparser.py
Original file line number Diff line number Diff line change
Expand Up @@ -269,7 +269,10 @@ def parse_json_file_and_cmd_lines(self) -> Tuple[DataClass, ...]:
data = json.load(file)
json_args = []
for key, value in data.items():
json_args.extend([f"--{key}", str(value)])
if isinstance(value, list):
json_args.extend([f"--{key}", *[str(v) for v in value]])
else:
json_args.extend([f"--{key}", str(value)])
else:
raise FileNotFoundError(f"The argument file {json_file} does not exist.")
# In case of conflict, command line arguments take precedence
Expand Down
11 changes: 9 additions & 2 deletions tests/trainer/test_argparser.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ class ArgparserTest(unittest.TestCase):
"amp_master_grad": False,
"adam_beta1": 0.9,
"adam_beta2": 0.999,
"amp_custom_black_list": ["reduce_sum", "sin", "cos"],
"adam_epsilon": 1e-08,
"bf16": False,
"enable_linear_fused_grad_add": False,
Expand All @@ -68,7 +69,10 @@ class ArgparserTest(unittest.TestCase):
def test_parse_cmd_lines(self):
cmd_line_args = [ArgparserTest.script_name]
for key, value in ArgparserTest.args_dict.items():
cmd_line_args.extend([f"--{key}", str(value)])
if isinstance(value, list):
cmd_line_args.extend([f"--{key}", *[str(v) for v in value]])
else:
cmd_line_args.extend([f"--{key}", str(value)])
with patch("sys.argv", cmd_line_args):
model_args = vars(parse_args()[0])
for key, value in ArgparserTest.args_dict.items():
Expand All @@ -93,7 +97,10 @@ def test_parse_json_file_and_cmd_lines(self):
tmpfile_path = tmpfile.name
cmd_line_args = [ArgparserTest.script_name, tmpfile_path]
for key, value in cmd_line_part.items():
cmd_line_args.extend([f"--{key}", str(value)])
if isinstance(value, list):
cmd_line_args.extend([f"--{key}", *[str(v) for v in value]])
else:
cmd_line_args.extend([f"--{key}", str(value)])
with patch("sys.argv", cmd_line_args):
model_args = vars(parse_args()[0])
for key, value in ArgparserTest.args_dict.items():
Expand Down