PyTorch is a well-established development framework for Machine Learning, especially at the academic level. In this article we will see how to install PyTorch in Windows and prepare an environment to develop our neural networks.
As the framework supports the use of GPUs, we will also see how to configure it to take advantage of the parallel computing power of our graphics card.
Development Environment Setup
To begin with, it is necessary to use a development IDE that facilitates the installation of the necessary packages. We download Anaconda from the official website and run the installation.
Once the process is complete, we need to find out if our computer has a GPU that can be exploited to accelerate performance. PyTorch uses NVIDIA’s CUDA platform.
From the Windows Start menu type the command Run and in the window that opens run the following command:
The window that opens shows all the devices installed on our computer.
We are interested in finding out the exact model of our graphics card, if we have one installed. Look for the Display Adapters entry and expand it. If you have an NVIDIA graphics card, check that the model shown is included in this list.
If the answer to the previous step is yes, we continue downloading CUDA from the NVIDIA website and installing it. This way we have the framework ready to accelerate the neural networks we are going to create with PyTorch.
Installing PyTorch on Windows
We now go to the PyTorch site and select the best configuration for our computer.
If you have a graphics card, select the Compute Platform CUDA configuration. If you do not have a dedicated GPU, select Compute Platform CPU.
Keep Conda as your Package Manager.
Once you have completed the various selections, copy the command that can be found under Run this command.
From the Windows menu, run Anaconda Navigator and then launch the CMD.exe Prompt.
In the window that opens, paste the command copied earlier and execute it. This will start the installation of PyTorch in our environment.
Before concluding this article, let’s check that the setup was successful. In particular, at the prompt used to install PyTorch, run the python command.
At this point, we execute the following instructions:
I recommend that you run one command at a time.
After importing the PyTorch library in the first line, we print out the installed version. Next, we check whether CUDA support is correctly configured.
Obviously, if you don’t have a dedicated GPU, and therefore skipped the steps described in the Setup section of the Development Environment, you will get a False value in the output. On the other hand, you will get True, and at the next command you will also be able to print the version of CUDA that is currently present.
PyTorch is a Python framework that is widely used in machine learning. In this article we have seen how to install PyTorch in Windows to start developing your own neural networks. As PyTorch supports the use of GPUs, we have also described the steps required to activate this support in order to achieve the best computational performance our computer can offer.