WmZilla - Webmaster and Marketplace

The Next Generation Webmaster and Trade Forum

Guide to running TensorFlow with GPU

thiccboygamerTTV

New member

0

0%

Status

Offline

Posts

40

Likes

0

Rep

0

Bits

210

3

Months of Service

0%
Hello.

Download Miniconda or Anaconda and open the prompt (command line).

Create a new Conda environment with the following command. Our Python version should be 3.10/3.9/3.8. I have tried 3.10 and 3.8, and we will continue with 3.10 in this guide. I recommend continuing with 3.10 to avoid Numpy compatibility issues.
conda create -n gpu python=3.10
We have created a new Conda environment named GPU.

Enter this environment by using the command conda activate gpu.

Install the necessary packages/libraries to use Nvidia CUDA with the command conda install -c conda-forge cudatoolkit=11.2 cudnn=8.1.0.

Upgrade pip with the command pip install --upgrade pip.

Install the latest supported version of TensorFlow for Python 3.10 with the command pip install tensorflow.

Download the prerelease version of TensorFlow with pip install tf-nightly. I'm not certain if this is necessary, but I recommend installing it.

Install DirectML plugins with the command pip install tensorflow-directml-plugin. A brief description of what it is: a hardware accelerator package that enables GPU recognition.

To check if the GPU is detected, you can use the following command. The output should look like this:
python -c "import tensorflow as tf; print(tf.config.list_physical_devices('GPU'))"


I recommend having a good internet connection, as TensorFlow is quite large in size.

I also installed PyTorch on the same environment. The installation command is as follows:
conda install pytorch torchvision torchaudio cudatoolkit=11.3 -c pytorch
At the moment, both are working and detecting the GPU.

I mostly use PyTorch, and it is compatible with Py 3.12. Therefore, I have separate environments for TensorFlow and Torch, and I switch between them depending on which one I am using.

If you're using PyCharm, you need to select this environment as the new interpreter.

Wishing you abundant neurons.
 

249

6,622

6,642

Top