adding option to load on cpu

This commit is contained in:
thomwolf
2019-02-08 10:37:40 +01:00
parent 777459b471
commit 5ee4f17234

View File

@@ -580,7 +580,7 @@ class BertPreTrainedModel(nn.Module):
model = cls(config, *inputs, **kwargs)
if state_dict is None and not from_tf:
weights_path = os.path.join(serialization_dir, WEIGHTS_NAME)
state_dict = torch.load(weights_path)
state_dict = torch.load(weights_path, map_location='cpu' if not torch.cuda.is_available() else None)
if tempdir:
# Clean up temp dir
shutil.rmtree(tempdir)