From ed85c066f0ba47c58b250ad971839d4ed56a5665 Mon Sep 17 00:00:00 2001 From: Zach Mueller Date: Wed, 6 Sep 2023 12:04:57 -0400 Subject: [PATCH] Better error --- src/accelerate/commands/config/config_args.py | 10 ++++++---- tests/test_cli.py | 3 ++- 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/src/accelerate/commands/config/config_args.py b/src/accelerate/commands/config/config_args.py index 196ae4b7da5..8483c8b6ea3 100644 --- a/src/accelerate/commands/config/config_args.py +++ b/src/accelerate/commands/config/config_args.py @@ -110,10 +110,11 @@ def from_json_file(cls, json_file=None): config_dict["use_cpu"] = False if "debug" not in config_dict: config_dict["debug"] = False - extra_keys = set(config_dict.keys()) - set(cls.__dataclass_fields__.keys()) + extra_keys = sorted(set(config_dict.keys()) - set(cls.__dataclass_fields__.keys())) if len(extra_keys) > 0: raise ValueError( - f"Unknown keys in the config file: {list(extra_keys)}, please try upgrading your `accelerate` version or remove them." + f"The config file at {json_file} had unknown keys ({extra_keys}), please try upgrading your `accelerate`" + " version or fix (and potentially remove) these keys from your config file." ) return cls(**config_dict) @@ -143,10 +144,11 @@ def from_yaml_file(cls, yaml_file=None): config_dict["use_cpu"] = False if "debug" not in config_dict: config_dict["debug"] = False - extra_keys = set(config_dict.keys()) - set(cls.__dataclass_fields__.keys()) + extra_keys = sorted(set(config_dict.keys()) - set(cls.__dataclass_fields__.keys())) if len(extra_keys) > 0: raise ValueError( - f"Unknown keys in the config file: {list(extra_keys)}, please try upgrading your `accelerate` version or remove them." + f"The config file at {yaml_file} had unknown keys ({extra_keys}), please try upgrading your `accelerate`" + " version or fix (and potentially remove) these keys from your config file." ) return cls(**config_dict) diff --git a/tests/test_cli.py b/tests/test_cli.py index 11303c727f6..3c4c4963f63 100644 --- a/tests/test_cli.py +++ b/tests/test_cli.py @@ -75,7 +75,8 @@ def test_config_compatibility(self): def test_invalid_keys(self): with self.assertRaises( - RuntimeError, msg="Unknown keys in the config file: ['another_invalid_key', 'invalid_key']" + RuntimeError, + msg="The config file at 'invalid_keys.yaml' had unknown keys ('another_invalid_key', 'invalid_key')", ): execute_subprocess_async( self.base_cmd