From 49470e7449f4a1e09844cd56eaeb57b22f7344b5 Mon Sep 17 00:00:00 2001 From: Sahel Sharify Date: Fri, 1 Sep 2023 20:29:57 -0400 Subject: [PATCH] Update training_args.py to remove the runtime error This cl iterates through a list of keys rather than dict items while updating the dict elements. Fixes the following error: File "..../transformers/training_args.py", line 1544, in post_init for k, v in self.fsdp_config.items(): RuntimeError: dictionary keys changed during iteration --- src/transformers/training_args.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/transformers/training_args.py b/src/transformers/training_args.py index 68458a64b0eb..2a02d1e9a94b 100644 --- a/src/transformers/training_args.py +++ b/src/transformers/training_args.py @@ -1546,10 +1546,10 @@ def __post_init__(self): warnings.warn("`--fsdp_config` is useful only when `--fsdp` is specified.") with io.open(self.fsdp_config, "r", encoding="utf-8") as f: self.fsdp_config = json.load(f) - for k, v in self.fsdp_config.items(): + for k in list(self.fsdp_config.keys()): if k.startswith("fsdp_"): - self.fsdp_config[k.replace("fsdp_", "")] = v - del self.fsdp_config[k] + v = self.fsdp_config.pop(k) + self.fsdp_config[k[5:]] = v if self.fsdp_min_num_params > 0: warnings.warn("using `--fsdp_min_num_params` is deprecated. Use fsdp_config instead ", FutureWarning)