logo

Installing TensorFlow GPU on Windows with Python 📂Programing

Installing TensorFlow GPU on Windows with Python

Guide

Installing TensorFlow GPU isn’t as straightforward as installing regular programs with just an installer. If there are various issues, it might be more convenient to wipe your computer and start from scratch, and if it’s your first time, be prepared to do so about ten times.


Step 1. NVIDIA GPU Driver Installation

1

Check your graphics specifications in the NVIDIA control panel and select the appropriate driver. Although setting the language to Korean should be fine, it’s usually better to choose English for such installation tasks.

2

Run the installer. If in doubt, just go with the default settings.

3


Step 2. tensorflow package installation through pip

pip3 install tensorflow-GPU

From the powershell console, issue the command as shown above to install tensorflow.

Once the installation is complete, run Python and try the following command.

import tensorflow as tf

4

Although not an error, the following warning might appear. There is no problem with TensorFlow itself, but there might be an issue with using the GPU. Let’s move on for now.

2021-04-27 13:47:26.034931: W tensorflow/stream_executor/platform/default/dso_loader.cc:60] Could not load dynamic library 'cudart64_110.dll'; dlerror: cudart64_110.dll not found
2021-04-27 13:47:26.035108: I tensorflow/stream_executor/cuda/cudart_stub.cc:29] Ignore above cudart dlerror if you do not have a GPU set up on your machine.
INFO:tensorflow:Enabling eager execution
INFO:tensorflow:Enabling v2 tensorshape
INFO:tensorflow:Enabling resource variables
INFO:tensorflow:Enabling tensor equality
INFO:tensorflow:Enabling control flow v2

Step 3. CUDA Toolkit Installation

Back to powershell, enter nvidia-smi. The following will be displayed on the top right, indicating which CUDA version to use.

5

https://developer.nvidia.com/cuda-toolkit-archive

6

From the page above, install the CUDA Toolkit corresponding to your operating system. In this case, version 11.3 released in April 2021 was downloaded.

7


Step 4. cuDNN Installation

https://developer.nvidia.com/cudnn

Unzip the downloaded cuDNN SDK and manually paste it into the folder. Note, this step requires an NVIDIA account.

8

Unzipping the downloaded file cudnn-11.3-windows-x64-v8.2.0.53.zip will create the following cuda folder.

9

C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA

The path above has the installed CUDA versions separated by version. In this post, since the CUDA version was continuously 11.3, let’s go into the 11.3 folder.

10

The bin, include, lib folders seen when the cuDNN SDK was unzipped are visible. Copy and paste them to overwrite.

11


Step 5. Verification

import tensorflow as tf

Run Python again and call up Python with the above command. Unlike in Step 2, you can see it running smoothly as follows.

12

2021-04-27 14:18:51.570857: I tensorflow/stream_executor/platform/default/dso_loader.cc:49] Successfully opened dynamic library cudart64_110.dll
INFO:tensorflow:Enabling eager execution
INFO:tensorflow:Enabling v2 tensorshape
INFO:tensorflow:Enabling resource variables
INFO:tensorflow:Enabling tensor equality
INFO:tensorflow:Enabling control flow v2

Environment

  • OS: Windows
  • Python: 3.9.4
  • tensorflow-gpu: 2.5.0rc1
  • CUDA Toolkit: 11.3