PyTorch is a deep learning package for machine learning, or deep learning in particular for a neural network model. To install PyTorch onto your Windows operating system, first goes to the official website for PyTorch: www.pytorch.org, and the information associated with Windows and Cuda version should be highlighted on this page.

PyTorch Installation information

Before we will run the statement for the PyTorch installation in a prompt window, e.g. Anaconda prompt windows, Cuda Toolkit must be installed on your computer. The link for Cuda Toolkit download can be found in the following link : https://developer.nvidia.com/cuda-12-6-0-download-archive?target_os=Windows , or you can just google ‘install cuda‘.

Cuda Toolkit Installation

Cuda Toolkit helps the usage of GPU in your computer to perform deep learning model much quicker than using CPU. Next, download the exe file for Cuda Toolkit.

However, before you can install and use Cuda on Windows, you must have Visual Studio installed first. Again, we can search ‘Visual Studio download‘ and easily find the the latest version of Visual Studio Community, which is totally free. Next, install both Visual Studio and Cuda Toolkit.

Visual Studio Community Download

You can print the following statement to confirm Cuda Toolkit is correctly installed: nvcc –version

So after both Visual Studio and Cuda Toolkit are successfully installed on your Windows operating system (My computer just have an older version of Cuda) , we can run the statement for PyTorch installation in Anaconda prompt window.

pip3 install torch torchvision --index-url https://download.pytorch.org/whl/cu126

After a while, the package for PyTorch and torchvision are installed, and you can use the following command in Anaconda prompt windows to check if it is correctly installed, pytorch can be successfully imported in Python, and the Cuda Toolkit can be used in PyTorch.

(base) C:\Users\Wilso>python
Python 3.12.4 | packaged by Anaconda, Inc. | (main, Jun 18 2024, 15:03:56) [MSC v.1929 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import torch
>>> torch.cuda.is_available()
True
>>>

Having got such message, then you can start using PyTorch in Python for deep learning now !

You can also watch video for PyTorch installation from our channel in YouTube.


0 Comments

Leave a Reply

Avatar placeholder