internetarchive / internetarchive/tarb_soft404
RuntimeError on Model Load: CUDA Device Not Available in CPU-Only Environment
- Dominant language
- Jupyter Notebook
- Stars
- 2
- Forks
- 1
- PR merge metrics
- No merged PRs in 30d
Description
Environment Details:
- Python Version: 3.9
- PyTorch Version: 2.0.1
- Operating System: macOS Ventura
Issue Description:
When attempting to load a PyTorch model using `torch.load` in a CPU-only environment, a RuntimeError is encountered.
Error Message:
```
% python bert.py http://mail.rubikon.net.pl/
Traceback (most recent call last):
File "/Users/kritikagarg/tarb_soft404/Inference/bert.py", line 19, in
model = torch.load("bert_model1")
File "/Users/kritikagarg/opt/anaconda3/lib/python3.9/site-packages/torch/serialization.py", line 809, in load
return _load(opened_zipfile, map_location, pickle_module, **pickle_load_args)
File "/Users/kritikagarg/opt/anaconda3/lib/python3.9/site-packages/torch/serialization.py", line 1172, in _load
result = unpickler.load()
File "/Users/kritikagarg/opt/anaconda3/lib/python3.9/site-packages/torch/serialization.py", line 1142, in persistent_load
typed_storage = load_tensor(dtype, nbytes, key, _maybe_decode_ascii(location))
File "/Users/kritikagarg/opt/anaconda3/lib/python3.9/site-packages/torch/serialization.py", line 1116, in load_tensor
wrap_storage=restore_location(storage, location),
File "/Users/kritikagarg/opt/anaconda3/lib/python3.9/site-packages/torch/serialization.py", line 217, in default_restore_location
result = fn(storage, location)
File "/Users/kritikagarg/opt/anaconda3/lib/python3.9/site-packages/torch/serialization.py", line 182, in _cuda_deserialize
device = validate_cuda_device(location)
File "/Users/kritikagarg/opt/anaconda3/lib/python3.9/site-packages/torch/serialization.py", line 166, in validate_cuda_device
raise RuntimeError('Attempting to deserialize object on a CUDA '
RuntimeError: Attempting to deserialize object on a CUDA device but torch.cuda.is_available() is False. If you are running on a CPU-only machine, please use torch.load with map_location=torch.device('cpu') to map your storages to the CPU.
```
Contributor guide
No contributing guide indexed for this repository
Research direction
Start in Inference/bert.py at line 19, where the model is loaded with torch.load, and review the CPU-only deserialization error. Verify the load behavior in the reported Python, PyTorch, and macOS environment; done means the model loads without the CUDA-device RuntimeError on a CPU-only machine.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python, pytorch
- Domain
- machine-learning
- Issue type
- Bug
- Difficulty
- 1/5
- Estimated time
- Under an hour
- Activity status
- Stale
- Clarity
- Clearly specified
- Newbie friendliness
- 48/100