Skip to content

Commit

Permalink
fix_trainer_argparser (#7860)
Browse files Browse the repository at this point in the history
  • Loading branch information
greycooker authored and JunnYu committed Jan 22, 2024
1 parent b583f11 commit fff730e
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 3 deletions.
11 changes: 9 additions & 2 deletions llm/llama/tests/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
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

0 comments on commit fff730e

Please sign in to comment.