mjhydri/BeatNet

Invalid device string: 'cuda:cpu' error: bug in model.py

karen-pal opened this issue · 1 comments

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:

image

I changed it to this:
image

and I got it working

image

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.

#2

Hey, Thank you so much for opening this issue and for your contribution. Your change will be reviewed at the soonest available time and merged to the source code!

Best,