Skip to content

Commit

Permalink
check for tpu availability in save_pretrained (huggingface#7699)
Browse files Browse the repository at this point in the history
Added is_torch_tpu_available() to the condition
for saving a model as xla model. "xla_device"
property of config can also be True on a non-xla
device, when loading a checkpointthat was trained
on xla before.

Resolves huggingface#7695
  • Loading branch information
fteufel authored Oct 12, 2020
1 parent 13c1857 commit 2f34bcf
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion src/transformers/modeling_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -716,7 +716,7 @@ def save_pretrained(self, save_directory):
# If we save using the predefined names, we can load using `from_pretrained`
output_model_file = os.path.join(save_directory, WEIGHTS_NAME)

if getattr(self.config, "xla_device", False):
if getattr(self.config, "xla_device", False) and is_torch_tpu_available():
import torch_xla.core.xla_model as xm

if xm.is_master_ordinal():
Expand Down

0 comments on commit 2f34bcf

Please sign in to comment.