Skip to content

Commit

Permalink
Raise error when using save_only_model with `load_best_model_at_end…
Browse files Browse the repository at this point in the history
…` for DeepSpeed/FSDP (#28866)

* Raise error when using `save_only_model` with `load_best_model_at_end` for DeepSpeed/FSDP

* Update trainer.py
  • Loading branch information
pacman100 authored and Ita Zaporozhets committed May 14, 2024
1 parent f13750c commit c185d1c
Showing 1 changed file with 9 additions and 0 deletions.
9 changes: 9 additions & 0 deletions src/transformers/trainer.py
Original file line number Diff line number Diff line change
Expand Up @@ -4054,6 +4054,15 @@ def create_accelerator_and_postprocess(self):
if self.is_deepspeed_enabled and getattr(self.args, "hf_deepspeed_config", None) is None:
self.propagate_args_to_deepspeed()

# `save_only_model` can't be used with DeepSpeed/FSDP along with `load_best_model_at_end`
if (
self.args.save_only_model
and (self.is_deepspeed_enabled or self.is_fsdp_enabled)
and self.args.load_best_model_at_end
):
wrapper = "DeepSpeed" if self.is_deepspeed_enabled else "FSDP"
raise ValueError(f"{wrapper} can't be used with `save_only_model` along with `load_best_model_at_end`.")

def propagate_args_to_deepspeed(self, auto_find_batch_size=False):
"""
Sets values in the deepspeed plugin based on the Trainer args
Expand Down

0 comments on commit c185d1c

Please sign in to comment.