Can't set weights_only=True if the device is GPU

I first get a future warning telling me to set weights_only to True for security puporses, but when I do, it says I can’t use weights_only = True. I get the below error.

state_dict = torch.load(path_to_state_dict, map_location="gpu",weights_only=True)

torch\serialization.py", line 1096, in load
raise pickle.UnpicklingError(_get_wo_message(str(e))) from None
_pickle.UnpicklingError: Weights only load failed. Re-running torch.load with weights_only set to False will likely succeed, but it can result in arbitrary code execution. Do
it only if you got the file from a trusted source.
Please file an issue with the following so that we can make weights_only=True compatible with your use case: WeightsUnpickler error: don’t know how to restore data location of t
orch.storage.UntypedStorage (tagged with gpu)
Check the documentation of torch.load to learn more about types accepted by default with weights_only torch.load — PyTorch 2.4 documentation.

No problem if I use weights_only=True if the map_location is ‘cpu’.

Hi,

The error message here mentions: “don’t know how to restore data location of t
orch.storage.UntypedStorage (tagged with gpu)”
Indeed, “gpu” is not a valid device in PyTorch, I guess you meant “cuda” ?

1 Like

Thanks, you were exactly right. Legend :+1: