From cf2c5be5deb7a6bec4080f1e0c2cc30c88e3402d Mon Sep 17 00:00:00 2001 From: greycooker <526929599@qq.com> Date: Wed, 15 May 2024 12:25:06 +0000 Subject: [PATCH] support json parameter --- paddlenlp/trainer/argparser.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/paddlenlp/trainer/argparser.py b/paddlenlp/trainer/argparser.py index 48a664682089..58bbe45dc5f5 100644 --- a/paddlenlp/trainer/argparser.py +++ b/paddlenlp/trainer/argparser.py @@ -136,7 +136,7 @@ def _parse_dataclass_field(parser: ArgumentParser, field: dataclasses.Field): elif field.default is dataclasses.MISSING: kwargs["required"] = True else: - kwargs["type"] = field.type + kwargs["type"] = json.loads if field.type is dict else field.type if field.default is not dataclasses.MISSING: kwargs["default"] = field.default elif field.default_factory is not dataclasses.MISSING: @@ -246,6 +246,8 @@ def read_json(self, json_file: str) -> list: for key, value in data.items(): if isinstance(value, list): json_args.extend([f"--{key}", *[str(v) for v in value]]) + elif isinstance(value, dict): + json_args.extend([f"--{key}", json.dumps(value)]) else: json_args.extend([f"--{key}", str(value)]) return json_args