Skip to content

Commit

Permalink
Fix trainer saving safetensors: metadata is None (huggingface#28219)
Browse files Browse the repository at this point in the history
* Update trainer.py

* format
  • Loading branch information
hiyouga authored and Saibo-creator committed Jan 4, 2024
1 parent 8d85c88 commit 62911a3
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 additions & 1 deletion src/transformers/trainer.py
Original file line number Diff line number Diff line change
Expand Up @@ -2908,7 +2908,9 @@ def _save(self, output_dir: Optional[str] = None, state_dict=None):
else:
logger.info("Trainer.model is not a `PreTrainedModel`, only saving its state dict.")
if self.args.save_safetensors:
safetensors.torch.save_file(state_dict, os.path.join(output_dir, SAFE_WEIGHTS_NAME))
safetensors.torch.save_file(
state_dict, os.path.join(output_dir, SAFE_WEIGHTS_NAME), metadata={"format": "pt"}
)
else:
torch.save(state_dict, os.path.join(output_dir, WEIGHTS_NAME))
else:
Expand Down

0 comments on commit 62911a3

Please sign in to comment.