Invalid device string: 'cuda:cpu' error: bug in model.py
karen-pal opened this issue · 1 comments
karen-pal commented
Hey, thanks for your sharing your work. It is very appreciated!
After a clean installation I wasn't able to run the example code provided. I tried digging around the code to see if I could fix it for you.
The error I kept getting was
RuntimeError: Invalid device string: 'cuda:cpu'
This code is the problem:
and I got it working
Here is the code.
def change_device(self, device=None):
"""
Change the device and load the model onto the new device.
Parameters
----------
device : string or None, optional (default None)
Device to load model onto
"""
if device is None:
# If the function is called without a device, use the current device
device = self.device
elif not torch.cuda.is_available():
device = torch.device('cpu')
else:
# Create the appropriate device object
device = torch.device(f'cuda:{device}')
# Change device field
self.device = device
# Load the transcription model onto the device
self.to(self.device)
I could clean the code a little and open a pull request with this change, if you are open to that. In any case, maybe this issue will help others to make your great project work on their computer.
Cheers.