#287: PyTorch With GPU Support
Last week we noticed that Coqui did not run on our GPU. If you have a dedicated graphics card, that is not what you want. While CPUs are getting faster and faster, they are usually much slower than what we could get out of our graphics card. Let us see how we can activate GPU support for PyTorch.
Install the right PyTorch packages
The get started guide for PyTorch offers us a small wizard where we can select the installation options:

Before you run the command, check the prerequisites that are listed on the same page. You can save yourself a lot of extra work if you go through the list step by step and recheck that your machine fulfils the requirements.
For my settings I got this command to install PyTorch (with a small modification to use uv):
This command fetched 3GB of packages and took a while to finish, but otherwise the installation was without any surprises.
Test the Cuda support
We can run the Python REPL with the python command and then enter these two lines:
If we get a True back, PyTorch is correctly installed and can find Cuda. If we get a false, we need to go back to the guide and check if we missed any of the prerequisites.
Coqui with GPU support
Now that we have PyTorch with GPU support, it should be a small thing to run Coqui on our GPU. Unfortunately, that does not work. Instead of a faster running script, we get this error:
ImportError: cannot import name 'io' from 'torchvision'
The reason for that is an incorrect version dependency. In the demanded version 0.2 of torchvision the io module does not exist. Luckily for us, we can update torchvision with this command without running into other dependency issues:
If we now run our text-to-speech script from last week, it takes the GPU and not the CPU. Unfortunately, I could not detect an improvement for the time it took to generate the audio file. I may later come back to this problem, but for now I want to go on.
Next
With the instructions in this post, you should be able to get the GPU support working for PyTorch. Even when the improvement for this first case was not noticeable, for other problems the GPU support may be of great help.
Next week we explore five helpful tricks for uv that makes it an even more useful tool.