Skip to content

Instantly share code, notes, and snippets.

@ayoubbensakhria
Last active December 20, 2022 01:47
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ayoubbensakhria/b279c8585bc8fbfc76fd2d2be019e371 to your computer and use it in GitHub Desktop.
Save ayoubbensakhria/b279c8585bc8fbfc76fd2d2be019e371 to your computer and use it in GitHub Desktop.
Install Tensorflow-GPU *(for NVIDIA GPUs)* for use in JupyterLab using Anaconda

Install Tensorflow-GPU (for NVIDIA GPUs) for use in JupyterLab using Anaconda

This tutorial is for computers with NVIDIA GPUs installed.

Tensorflow for GPU significantly reduces the time taken by Deep Neural Networks (like CNNs, LSTMs, etc) to complete each Epoch (compute cycle) by utilizing the CUDA cores present in the GPU for parallel processing.

The following steps are to be followed:

  1. Make sure that you have installed the latest drivers of your NVIDIA GPU for your OS.

  2. Install Anaconda Distribution (Individual Edition) suitable for your OS.

    Download URL: https://www.anaconda.com/products/individual

  3. Open the Terminal of your OS in Superuser Mode.

    For Example:

    • Windows Users have to open Command Prompt as Administrator.

    • Linux / macOS users have to open Terminal and log in as root user.

  4. Check Compatible Versions of Python, cuDNN and CUDA for TensorFlow-GPU.

    URL:

    For Windows: https://www.tensorflow.org/install/source_windows#gpu

    For Linux / macOS: https://www.tensorflow.org/install/source#gpu

    It is advised that you use the latest version of Tensorflow and its compatible Python, cuDNN and CUDA versions (usually displayed at the first row of the list)

    In this example, we will use TensorFlow version 2.4.1 [Latest as on 06 April 2021] for which the Python Version to be used is 3.6 to 3.8 (3.8 recommended), cuDNN version to be used is 8.0, and CUDA Toolkit version to be used is 11.0

  5. Create a Virtual Environment in Anaconda using the following command:

    conda create -n tf_gpu python==3.8

    Here, tf_gpu is the name of the virtual environment in which the Python 3.8 is to be installed.

  6. Activate the Virtual Environment using the following command:

    conda activate tf_gpu
  7. Install cuDNN and CUDA Toolkit from Conda-Forge Repo Source using the following command:

    conda install cudatoolkit=11.0 cudnn=8.0 -c=conda-forge
  8. Install TensorFlow for GPU using the following command:

    pip install --upgrade tensorflow-gpu==2.4.1

    At this point, the TensorFlow library is ready to be used. You can check if your GPU is detected by TensorFlow using the following python code in a python shell of the Virtual Environment:

    >>> import tensorflow as tf
    >>> tf.test.is_gpu_available()
  9. Install iPython Kernel for using in JupyterLab using the following command:

    pip install ipykernel

    Don't conda install ipykernel as it may downgrade your TensorFlow installation.

  10. Register the iPython Kernel for selection within JupyterLab using the following command:

    python -m ipykernel install --user --name tf_gpu --display-name "TensorFlowGPU"
  11. Install JupyterLab using the following command:

    conda install jupyterlab
  12. Also install Keras library to prevent the occurrence of any runtime errors, by using the following command:

    pip install keras

    Don't conda install keras as it may downgrade your TensorFlow installation.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment