load all models on cpu

This commit is contained in:
thomwolf
2019-04-15 15:43:01 +02:00
parent 2499b0a5fc
commit df5d9c3551
4 changed files with 4 additions and 4 deletions

View File

@@ -594,7 +594,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, map_location='cpu' if not torch.cuda.is_available() else None)
state_dict = torch.load(weights_path, map_location='cpu')
if tempdir:
# Clean up temp dir
shutil.rmtree(tempdir)