Jared AI Hub
Published on

How to setup Tensorflow and Pytorch for your local machine in Windows 11 with a GPU

Authors
  • avatar
    Name
    Jared Chung
    Twitter

The focus of this blog is provide the instructions to install pytorch and tensorflow on your local windows 11 computer.

Make sure you have a compatible GPU and the necessary drivers installed. TensorFlow and PyTorch support a variety of GPUs, but you'll need to install the appropriate drivers for your GPU in order to use it with these libraries. You can check the official documentation for TensorFlow and PyTorch for more information on compatible GPUs and how to install the necessary drivers.

  1. The first step is to Install Cuda Toolkit
  2. Then install Cudnn which is a specialised library for deep learning. Alternate way to install Cudnn is running command sudo apt install nvidia-cudnn if you are installing on Ubuntu 22.04 operating system (i.e WSL)

Ensure you select the correct toolkit which is based on the pytorch you are installing, for example in this blog i'm using 11.6.

To install pytorch, the best way is to use the official documentation. The documentation provides different ways to install. I prefer to install using pip but you can also use Conda as an installation method.

python -m pip install torch torchvision torchaudio --extra-index-url https://download.pytorch.org/whl/cu116
conda install pytorch torchvision torchaudio pytorch-cuda=11.6 -c pytorch -c nvidia

Now you can install TensorFlow packages using pip. Open a terminal or command prompt and enter the following commands:

pip install tensorflow-gpu
This will install the GPU versions of TensorFlow on your machine.

Test your installation by running a simple script. Open a Python interpreter and enter the following code:

```python
import tensorflow as tf
import torch

print(tf.test.is_gpu_available())
print(torch.cuda.is_available())
```

If the output shows that the GPU is available and can be used with TensorFlow and PyTorch, then your installation was successful.

Note: If you encounter any issues while installing TensorFlow or PyTorch, you may want to check the official documentation for each library for troubleshooting tips. The TensorFlow documentation can be found at https://www.tensorflow.org/install, and the PyTorch documentation can be found at https://pytorch.org/get-started/locally/.