From c494be58cfbf44b5882a02ec54814a52da01ec41 Mon Sep 17 00:00:00 2001 From: Sotiris Gkouzias <82544018+sgkouzias@users.noreply.github.com> Date: Mon, 8 Apr 2024 14:20:57 +0300 Subject: [PATCH 01/15] Update pip.md Specify additional steps to utilize GPU for Linux users --- site/en/install/pip.md | 62 ++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 60 insertions(+), 2 deletions(-) diff --git a/site/en/install/pip.md b/site/en/install/pip.md index 4add60b11d7..c6168e0536f 100644 --- a/site/en/install/pip.md +++ b/site/en/install/pip.md @@ -193,7 +193,35 @@ The following NVIDIA® software are only required for GPU support. nvidia-smi ``` - ### 3. Install TensorFlow + ### 3. Install Miniconda + + [Miniconda](https://docs.conda.io/en/latest/miniconda.html){:.external} + is the recommended approach for installing TensorFlow with GPU support. + It creates a separate environment to avoid changing any installed + software in your system. This is also the easiest way to install the + required software especially for the GPU setup. + + Follow the instuctions of the conda user guide to install miniconda + [Miniconda Installation Guide](https://conda.io/projects/conda/en/latest/user-guide/install/linux.html){:.external}. + + ### 4. Create a conda environment + + Create a new conda environment named `tf` with the following command. + + ```bash + conda create --name tf python=3.11 + ``` + + You can deactivate and activate it with the following commands. + + ```bash + conda deactivate + conda activate tf + ``` + + Make sure it is activated for the rest of the installation. + + ### 5. Install TensorFlow TensorFlow requires a recent version of pip, so upgrade your pip installation to be sure you're running the latest version. @@ -211,7 +239,37 @@ The following NVIDIA® software are only required for GPU support. pip install tensorflow ``` - ### 4. Verify the installation + ### 6. Set environment variables + Locate the directory for the conda environment in your terminal window by running in the terminal: + `echo $CONDA_PREFIX` + + Enter that directory and create these subdirectories and files: + + ```bash + cd $CONDA_PREFIX + mkdir -p ./etc/conda/activate.d + mkdir -p ./etc/conda/deactivate.d + touch ./etc/conda/activate.d/env_vars.sh + touch ./etc/conda/deactivate.d/env_vars.sh + ``` + Edit `./etc/conda/activate.d/env_vars.sh` as follows: + + ```bash + #!/bin/sh + + export NVIDIA_DIR=$(dirname $(dirname $(python -c "import nvidia.cudnn;print(nvidia.cudnn.__file__)"))) + export LD_LIBRARY_PATH=$(echo ${NVIDIA_DIR}/*/lib/ | sed -r 's/\s+/:/g')${LD_LIBRARY_PATH:+:${LD_LIBRARY_PATH}} + ``` + Edit `./etc/conda/deactivate.d/env_vars.sh` as follows: + + ```bash + #!/bin/sh + + unset NVIDIA_DIR + unset LD_LIBRARY_PATH + ``` + + ### 7. Verify the installation Verify the CPU setup: From 40824e44a075ccd1d5f54f2fd5500ceeae871297 Mon Sep 17 00:00:00 2001 From: Sotiris Gkouzias <82544018+sgkouzias@users.noreply.github.com> Date: Mon, 8 Apr 2024 22:44:48 +0300 Subject: [PATCH 02/15] Update pip.md Advice to skip additional step 6 if using CPU. --- site/en/install/pip.md | 3 +++ 1 file changed, 3 insertions(+) diff --git a/site/en/install/pip.md b/site/en/install/pip.md index c6168e0536f..c1d86f2573a 100644 --- a/site/en/install/pip.md +++ b/site/en/install/pip.md @@ -240,6 +240,9 @@ The following NVIDIA® software are only required for GPU support. ``` ### 6. Set environment variables + + You can skip this section if you only run TensorFlow on the CPU. + Locate the directory for the conda environment in your terminal window by running in the terminal: `echo $CONDA_PREFIX` From 840fec9c3183a5555e24feee14ddd63cd182991a Mon Sep 17 00:00:00 2001 From: Sotiris Gkouzias <82544018+sgkouzias@users.noreply.github.com> Date: Tue, 9 Apr 2024 21:58:38 +0300 Subject: [PATCH 03/15] Update pip.md Added second option to create virtual env via Python's built in venv module for Linux users with CUDA-enabled GPUs --- site/en/install/pip.md | 44 +++++++++++++++++++++++++++++++++++++----- 1 file changed, 39 insertions(+), 5 deletions(-) diff --git a/site/en/install/pip.md b/site/en/install/pip.md index c1d86f2573a..93cae82503a 100644 --- a/site/en/install/pip.md +++ b/site/en/install/pip.md @@ -195,6 +195,8 @@ The following NVIDIA® software are only required for GPU support. ### 3. Install Miniconda + You can skip this section if you prefer to use Python’s built in venv module instead of Miniconda. + [Miniconda](https://docs.conda.io/en/latest/miniconda.html){:.external} is the recommended approach for installing TensorFlow with GPU support. It creates a separate environment to avoid changing any installed @@ -204,22 +206,30 @@ The following NVIDIA® software are only required for GPU support. Follow the instuctions of the conda user guide to install miniconda [Miniconda Installation Guide](https://conda.io/projects/conda/en/latest/user-guide/install/linux.html){:.external}. - ### 4. Create a conda environment + ### 4. Create a virtual environment + + #### First option: Miniconda Create a new conda environment named `tf` with the following command. ```bash conda create --name tf python=3.11 ``` + #### Second option: [venv](https://docs.python.org/3/library/venv.html){:.external} - You can deactivate and activate it with the following commands. + Navigate to your desired virtual environments' directory and create a new venv environment named `tf` with the following command. ```bash - conda deactivate - conda activate tf + python3 -m venv tf ``` - Make sure it is activated for the rest of the installation. + You can activate it with the following command. + + ```bash + source tf/bin/activate + ``` + + Make sure that the virtual environment you just created is activated for the rest of the installation. ### 5. Install TensorFlow @@ -243,6 +253,8 @@ The following NVIDIA® software are only required for GPU support. You can skip this section if you only run TensorFlow on the CPU. + #### First option: Miniconda + Locate the directory for the conda environment in your terminal window by running in the terminal: `echo $CONDA_PREFIX` @@ -271,6 +283,28 @@ The following NVIDIA® software are only required for GPU support. unset NVIDIA_DIR unset LD_LIBRARY_PATH ``` + #### Second option: venv + + Locate the directory for the venv environment in your terminal window by running in the terminal: + `echo $VIRTUAL_ENV` + + Enter that directory and add the following lines at the end of the activate script `./bin/activate` as follows: + + ```bash + # Set environment variables for TensorFlow + export NVIDIA_DIR=$(dirname $(dirname $(python -c "import nvidia.cudnn;print(nvidia.cudnn.__file__)"))) + export LD_LIBRARY_PATH=$(echo ${NVIDIA_DIR}/*/lib/ | sed -r 's/\s+/:/g')${LD_LIBRARY_PATH:+:${LD_LIBRARY_PATH}} + ``` + + Add the following lines at the end of `deactivate` block: + + ```bash + deactivate () { + # ... + unset NVIDIA_DIR + unset LD_LIBRARY_PATH + } + ``` ### 7. Verify the installation From 5448363ce65bcec0c0320a4fb2add79edd3f3f76 Mon Sep 17 00:00:00 2001 From: Sotiris Gkouzias <82544018+sgkouzias@users.noreply.github.com> Date: Wed, 10 Apr 2024 08:17:34 +0300 Subject: [PATCH 04/15] Update pip.md Added virtual envs activation/deactivation commands and changed wording for editing the deactivate block in the activate script of the venv virtual env. --- site/en/install/pip.md | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/site/en/install/pip.md b/site/en/install/pip.md index 93cae82503a..27c9e278ab4 100644 --- a/site/en/install/pip.md +++ b/site/en/install/pip.md @@ -215,6 +215,13 @@ The following NVIDIA® software are only required for GPU support. ```bash conda create --name tf python=3.11 ``` + You can activate and deactivate it with the following commands. + + ```bash + conda activate tf + conda deactivate + ``` + #### Second option: [venv](https://docs.python.org/3/library/venv.html){:.external} Navigate to your desired virtual environments' directory and create a new venv environment named `tf` with the following command. @@ -223,13 +230,14 @@ The following NVIDIA® software are only required for GPU support. python3 -m venv tf ``` - You can activate it with the following command. + You can activate and deactivate it with the following commands. ```bash source tf/bin/activate + deactivate ``` - Make sure that the virtual environment you just created is activated for the rest of the installation. + Make sure that the virtual environment is activated for the rest of the installation. ### 5. Install TensorFlow @@ -296,7 +304,7 @@ The following NVIDIA® software are only required for GPU support. export LD_LIBRARY_PATH=$(echo ${NVIDIA_DIR}/*/lib/ | sed -r 's/\s+/:/g')${LD_LIBRARY_PATH:+:${LD_LIBRARY_PATH}} ``` - Add the following lines at the end of `deactivate` block: + Add the following lines at the end of `deactivate` block in the activate script to ensure that the necessary CUDA environment variables are set only while the virtual environment is active: ```bash deactivate () { From c7518a2d0e0099c28aed404117bf202e8ca453c4 Mon Sep 17 00:00:00 2001 From: Sotiris Gkouzias <82544018+sgkouzias@users.noreply.github.com> Date: Wed, 10 Apr 2024 22:07:20 +0300 Subject: [PATCH 05/15] Update pip.md Added instructions to resolve the ptxas issue. --- site/en/install/pip.md | 58 +++++++++++++++++++++++++++++++++++------- 1 file changed, 49 insertions(+), 9 deletions(-) diff --git a/site/en/install/pip.md b/site/en/install/pip.md index 27c9e278ab4..b62f341088f 100644 --- a/site/en/install/pip.md +++ b/site/en/install/pip.md @@ -280,16 +280,32 @@ The following NVIDIA® software are only required for GPU support. ```bash #!/bin/sh - export NVIDIA_DIR=$(dirname $(dirname $(python -c "import nvidia.cudnn;print(nvidia.cudnn.__file__)"))) - export LD_LIBRARY_PATH=$(echo ${NVIDIA_DIR}/*/lib/ | sed -r 's/\s+/:/g')${LD_LIBRARY_PATH:+:${LD_LIBRARY_PATH}} + # Store original LD_LIBRARY_PATH + export ORIGINAL_LD_LIBRARY_PATH="${LD_LIBRARY_PATH}" + + # Get the directory of CUDA libraries + CUDA_DIR=$(dirname $(dirname $(python -c "import nvidia.cuda_nvcc; print(nvidia.cuda_nvcc.__file__)"))) + + # Set LD_LIBRARY_PATH to include all directories containing CUDA libraries + export LD_LIBRARY_PATH=$(find ${CUDA_DIR}/*/lib/ -type d -printf "%p:")${LD_LIBRARY_PATH:+:${LD_LIBRARY_PATH}} + + # Get the directory of NVCC binaries + NVCC_DIR=$(dirname $(dirname $(python -c "import nvidia.cuda_nvcc; print(nvidia.cuda_nvcc.__file__)"))) + + # Set PATH to include all directories containing NVCC binaries + export PATH=$(find ${NVCC_DIR}/*/bin/ -type d -printf "%p:")${PATH:+:${PATH}} ``` Edit `./etc/conda/deactivate.d/env_vars.sh` as follows: ```bash #!/bin/sh + + # Restore original LD_LIBRARY_PATH + export LD_LIBRARY_PATH="${ORIGINAL_LD_LIBRARY_PATH}" - unset NVIDIA_DIR - unset LD_LIBRARY_PATH + # Unset environment variables + unset CUDA_DIR + unset NVCC_DIR ``` #### Second option: venv @@ -299,9 +315,20 @@ The following NVIDIA® software are only required for GPU support. Enter that directory and add the following lines at the end of the activate script `./bin/activate` as follows: ```bash - # Set environment variables for TensorFlow - export NVIDIA_DIR=$(dirname $(dirname $(python -c "import nvidia.cudnn;print(nvidia.cudnn.__file__)"))) - export LD_LIBRARY_PATH=$(echo ${NVIDIA_DIR}/*/lib/ | sed -r 's/\s+/:/g')${LD_LIBRARY_PATH:+:${LD_LIBRARY_PATH}} + # Store the original LD_LIBRARY_PATH + export ORIGINAL_LD_LIBRARY_PATH=$LD_LIBRARY_PATH + + # Get the directory of CUDA libraries + CUDA_DIR=$(dirname $(dirname $(python -c "import nvidia.cuda_nvcc; print(nvidia.cuda_nvcc.__file__)"))) + + # Set LD_LIBRARY_PATH to include all directories containing CUDA libraries + export LD_LIBRARY_PATH=$(find ${CUDA_DIR}/*/lib/ -type d -printf "%p:")${LD_LIBRARY_PATH:+:${LD_LIBRARY_PATH}} + + # Get the directory of NVCC binaries + NVCC_DIR=$(dirname $(dirname $(python -c "import nvidia.cuda_nvcc; print(nvidia.cuda_nvcc.__file__)"))) + + # Set PATH to include all directories containing NVCC binaries + export PATH=$(find ${NVCC_DIR}/*/bin/ -type d -printf "%p:")${PATH:+:${PATH}} ``` Add the following lines at the end of `deactivate` block in the activate script to ensure that the necessary CUDA environment variables are set only while the virtual environment is active: @@ -309,8 +336,21 @@ The following NVIDIA® software are only required for GPU support. ```bash deactivate () { # ... - unset NVIDIA_DIR - unset LD_LIBRARY_PATH + # Unset the added path to PATH if within a virtual environment + if [ -n "$VIRTUAL_ENV" ]; then + # Remove the path from PATH + PATH=$(echo $PATH | sed -e "s|${NVCC_DIR}/*/bin/:||g") + fi + + # Restore the original LD_LIBRARY_PATH + if [ -n "$ORIGINAL_LD_LIBRARY_PATH" ]; then + export LD_LIBRARY_PATH=$ORIGINAL_LD_LIBRARY_PATH + unset ORIGINAL_LD_LIBRARY_PATH + fi + + # Unset environment variables + unset CUDA_DIR + unset NVCC_DIR } ``` From 6a40fe47c629737803bbdbb171e5b4c45fd93e57 Mon Sep 17 00:00:00 2001 From: Sotiris Gkouzias <82544018+sgkouzias@users.noreply.github.com> Date: Wed, 10 Apr 2024 23:28:32 +0300 Subject: [PATCH 06/15] Update pip.md Revised CUDNN_DIR definition --- site/en/install/pip.md | 54 +++++++++++++++++++++--------------------- 1 file changed, 27 insertions(+), 27 deletions(-) diff --git a/site/en/install/pip.md b/site/en/install/pip.md index b62f341088f..75f2229a002 100644 --- a/site/en/install/pip.md +++ b/site/en/install/pip.md @@ -283,10 +283,10 @@ The following NVIDIA® software are only required for GPU support. # Store original LD_LIBRARY_PATH export ORIGINAL_LD_LIBRARY_PATH="${LD_LIBRARY_PATH}" - # Get the directory of CUDA libraries - CUDA_DIR=$(dirname $(dirname $(python -c "import nvidia.cuda_nvcc; print(nvidia.cuda_nvcc.__file__)"))) + # Get the CUDNN directory + CUDNN_DIR=$(dirname $(dirname $(python -c "import nvidia.cudnn; print(nvidia.cudnn.__file__)"))) - # Set LD_LIBRARY_PATH to include all directories containing CUDA libraries + # Set LD_LIBRARY_PATH to include CUDNN directory export LD_LIBRARY_PATH=$(find ${CUDA_DIR}/*/lib/ -type d -printf "%p:")${LD_LIBRARY_PATH:+:${LD_LIBRARY_PATH}} # Get the directory of NVCC binaries @@ -304,7 +304,7 @@ The following NVIDIA® software are only required for GPU support. export LD_LIBRARY_PATH="${ORIGINAL_LD_LIBRARY_PATH}" # Unset environment variables - unset CUDA_DIR + unset CUDNN_DIR unset NVCC_DIR ``` #### Second option: venv @@ -315,14 +315,14 @@ The following NVIDIA® software are only required for GPU support. Enter that directory and add the following lines at the end of the activate script `./bin/activate` as follows: ```bash - # Store the original LD_LIBRARY_PATH + # Store original LD_LIBRARY_PATH export ORIGINAL_LD_LIBRARY_PATH=$LD_LIBRARY_PATH - # Get the directory of CUDA libraries - CUDA_DIR=$(dirname $(dirname $(python -c "import nvidia.cuda_nvcc; print(nvidia.cuda_nvcc.__file__)"))) + # Get the CUDNN directory + CUDNN_DIR=$(dirname $(dirname $(python -c "import nvidia.cudnn; print(nvidia.cudnn.__file__)"))) - # Set LD_LIBRARY_PATH to include all directories containing CUDA libraries - export LD_LIBRARY_PATH=$(find ${CUDA_DIR}/*/lib/ -type d -printf "%p:")${LD_LIBRARY_PATH:+:${LD_LIBRARY_PATH}} + # Set LD_LIBRARY_PATH to include CUDNN directory + export LD_LIBRARY_PATH=$(find ${CUDNN_DIR}/*/lib/ -type d -printf "%p:")${LD_LIBRARY_PATH:+:${LD_LIBRARY_PATH}} # Get the directory of NVCC binaries NVCC_DIR=$(dirname $(dirname $(python -c "import nvidia.cuda_nvcc; print(nvidia.cuda_nvcc.__file__)"))) @@ -331,26 +331,26 @@ The following NVIDIA® software are only required for GPU support. export PATH=$(find ${NVCC_DIR}/*/bin/ -type d -printf "%p:")${PATH:+:${PATH}} ``` - Add the following lines at the end of `deactivate` block in the activate script to ensure that the necessary CUDA environment variables are set only while the virtual environment is active: - + Add the following lines at the end of `deactivate` block in the activate script to ensure that the necessary NVIDIA environment variables are set only while the virtual environment is active: + ```bash deactivate () { - # ... - # Unset the added path to PATH if within a virtual environment - if [ -n "$VIRTUAL_ENV" ]; then - # Remove the path from PATH - PATH=$(echo $PATH | sed -e "s|${NVCC_DIR}/*/bin/:||g") - fi - - # Restore the original LD_LIBRARY_PATH - if [ -n "$ORIGINAL_LD_LIBRARY_PATH" ]; then - export LD_LIBRARY_PATH=$ORIGINAL_LD_LIBRARY_PATH - unset ORIGINAL_LD_LIBRARY_PATH - fi - - # Unset environment variables - unset CUDA_DIR - unset NVCC_DIR + # ... + # Unset the added path to PATH if within a virtual environment + if [ -n "$VIRTUAL_ENV" ]; then + # Remove the path from PATH + PATH=$(echo $PATH | sed -e "s|${NVCC_DIR}/*/bin/:||g") + fi + + # Restore original LD_LIBRARY_PATH + if [ -n "$ORIGINAL_LD_LIBRARY_PATH" ]; then + export LD_LIBRARY_PATH=$ORIGINAL_LD_LIBRARY_PATH + unset ORIGINAL_LD_LIBRARY_PATH + fi + + # Unset environment variables + unset CUDNN_DIR + unset NVCC_DIR } ``` From 82713bffccf5c16293cd70b140729d4a77e2a8a5 Mon Sep 17 00:00:00 2001 From: Sotiris Gkouzias <82544018+sgkouzias@users.noreply.github.com> Date: Wed, 10 Apr 2024 23:45:13 +0300 Subject: [PATCH 07/15] Update pip.md Corrected LD_LIBRARY_PATH definition in conda environment instructions --- site/en/install/pip.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/site/en/install/pip.md b/site/en/install/pip.md index 75f2229a002..7c4a63bb9dd 100644 --- a/site/en/install/pip.md +++ b/site/en/install/pip.md @@ -287,7 +287,7 @@ The following NVIDIA® software are only required for GPU support. CUDNN_DIR=$(dirname $(dirname $(python -c "import nvidia.cudnn; print(nvidia.cudnn.__file__)"))) # Set LD_LIBRARY_PATH to include CUDNN directory - export LD_LIBRARY_PATH=$(find ${CUDA_DIR}/*/lib/ -type d -printf "%p:")${LD_LIBRARY_PATH:+:${LD_LIBRARY_PATH}} + export LD_LIBRARY_PATH=$(find ${CUDNN_DIR}/*/lib/ -type d -printf "%p:")${LD_LIBRARY_PATH:+:${LD_LIBRARY_PATH}} # Get the directory of NVCC binaries NVCC_DIR=$(dirname $(dirname $(python -c "import nvidia.cuda_nvcc; print(nvidia.cuda_nvcc.__file__)"))) From b81e4f2eb80eb29911cc2723c9b2bdcaa3460c20 Mon Sep 17 00:00:00 2001 From: Sotiris Gkouzias <82544018+sgkouzias@users.noreply.github.com> Date: Fri, 12 Apr 2024 10:04:18 +0300 Subject: [PATCH 08/15] Update pip.md Rename environment variable to PTXAS_DIR and package manager options. --- site/en/install/pip.md | 40 +++++++++++++++++++++------------------- 1 file changed, 21 insertions(+), 19 deletions(-) diff --git a/site/en/install/pip.md b/site/en/install/pip.md index 7c4a63bb9dd..572a081430a 100644 --- a/site/en/install/pip.md +++ b/site/en/install/pip.md @@ -195,7 +195,7 @@ The following NVIDIA® software are only required for GPU support. ### 3. Install Miniconda - You can skip this section if you prefer to use Python’s built in venv module instead of Miniconda. + You can skip this section if you have already installed `Miniconda` (referred as *option #1* in the next steps) or you prefer to use Python’s built-in `venv` module (referred as *option #2* in the next steps) instead. [Miniconda](https://docs.conda.io/en/latest/miniconda.html){:.external} is the recommended approach for installing TensorFlow with GPU support. @@ -208,7 +208,7 @@ The following NVIDIA® software are only required for GPU support. ### 4. Create a virtual environment - #### First option: Miniconda + * ***Option #1: Miniconda*** Create a new conda environment named `tf` with the following command. @@ -222,9 +222,11 @@ The following NVIDIA® software are only required for GPU support. conda deactivate ``` - #### Second option: [venv](https://docs.python.org/3/library/venv.html){:.external} - - Navigate to your desired virtual environments' directory and create a new venv environment named `tf` with the following command. + * ***Option #2: venv*** + + The [venv](https://docs.python.org/3/library/venv.html){:.external} module supports creating lightweight “virtual environments”, each with their own independent set of Python packages installed in their site directories. + + Navigate to your desired virtual environments directory and create a new venv environment named `tf` with the following command. ```bash python3 -m venv tf @@ -261,7 +263,7 @@ The following NVIDIA® software are only required for GPU support. You can skip this section if you only run TensorFlow on the CPU. - #### First option: Miniconda + * ***Option #1: Miniconda*** Locate the directory for the conda environment in your terminal window by running in the terminal: `echo $CONDA_PREFIX` @@ -289,11 +291,11 @@ The following NVIDIA® software are only required for GPU support. # Set LD_LIBRARY_PATH to include CUDNN directory export LD_LIBRARY_PATH=$(find ${CUDNN_DIR}/*/lib/ -type d -printf "%p:")${LD_LIBRARY_PATH:+:${LD_LIBRARY_PATH}} - # Get the directory of NVCC binaries - NVCC_DIR=$(dirname $(dirname $(python -c "import nvidia.cuda_nvcc; print(nvidia.cuda_nvcc.__file__)"))) + # Get the ptxas directory + PTXAS_DIR=$(dirname $(dirname $(python -c "import nvidia.cuda_nvcc; print(nvidia.cuda_nvcc.__file__)"))) - # Set PATH to include all directories containing NVCC binaries - export PATH=$(find ${NVCC_DIR}/*/bin/ -type d -printf "%p:")${PATH:+:${PATH}} + # Set PATH to include the directory containing ptxas + export PATH=$(find ${PTXAS_DIR}/*/bin/ -type d -printf "%p:")${PATH:+:${PATH}} ``` Edit `./etc/conda/deactivate.d/env_vars.sh` as follows: @@ -305,9 +307,9 @@ The following NVIDIA® software are only required for GPU support. # Unset environment variables unset CUDNN_DIR - unset NVCC_DIR + unset PTXAS_DIR ``` - #### Second option: venv + * ***Option #2: venv*** Locate the directory for the venv environment in your terminal window by running in the terminal: `echo $VIRTUAL_ENV` @@ -324,11 +326,11 @@ The following NVIDIA® software are only required for GPU support. # Set LD_LIBRARY_PATH to include CUDNN directory export LD_LIBRARY_PATH=$(find ${CUDNN_DIR}/*/lib/ -type d -printf "%p:")${LD_LIBRARY_PATH:+:${LD_LIBRARY_PATH}} - # Get the directory of NVCC binaries - NVCC_DIR=$(dirname $(dirname $(python -c "import nvidia.cuda_nvcc; print(nvidia.cuda_nvcc.__file__)"))) + # Get the ptxas directory + PTXAS_DIR=$(dirname $(dirname $(python -c "import nvidia.cuda_nvcc; print(nvidia.cuda_nvcc.__file__)"))) - # Set PATH to include all directories containing NVCC binaries - export PATH=$(find ${NVCC_DIR}/*/bin/ -type d -printf "%p:")${PATH:+:${PATH}} + # Set PATH to include the directory containing ptxas + export PATH=$(find ${PTXAS_DIR}/*/bin/ -type d -printf "%p:")${PATH:+:${PATH}} ``` Add the following lines at the end of `deactivate` block in the activate script to ensure that the necessary NVIDIA environment variables are set only while the virtual environment is active: @@ -336,10 +338,10 @@ The following NVIDIA® software are only required for GPU support. ```bash deactivate () { # ... - # Unset the added path to PATH if within a virtual environment + # Unset the added path to PATH if within the virtual environment if [ -n "$VIRTUAL_ENV" ]; then # Remove the path from PATH - PATH=$(echo $PATH | sed -e "s|${NVCC_DIR}/*/bin/:||g") + PATH=$(echo $PATH | sed -e "s|${PTXAS_DIR}/*/bin/:||g") fi # Restore original LD_LIBRARY_PATH @@ -350,7 +352,7 @@ The following NVIDIA® software are only required for GPU support. # Unset environment variables unset CUDNN_DIR - unset NVCC_DIR + unset PTXAS_DIR } ``` From aebf305d3401691d83a44179bdbf60363012cf49 Mon Sep 17 00:00:00 2001 From: Sotiris Gkouzias <82544018+sgkouzias@users.noreply.github.com> Date: Fri, 12 Apr 2024 10:13:49 +0300 Subject: [PATCH 09/15] Update pip.md Added note to use pip instead of conda to install TensorFlow. --- site/en/install/pip.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/site/en/install/pip.md b/site/en/install/pip.md index 572a081430a..4b428467732 100644 --- a/site/en/install/pip.md +++ b/site/en/install/pip.md @@ -259,6 +259,8 @@ The following NVIDIA® software are only required for GPU support. pip install tensorflow ``` + Note: Do not install TensorFlow with `conda`. It may not have the latest stable version. `pip` is recommended since TensorFlow is only officially released to PyPI. + ### 6. Set environment variables You can skip this section if you only run TensorFlow on the CPU. From 146bbebfdd8138f2317781761162b928871721be Mon Sep 17 00:00:00 2001 From: Sotiris Gkouzias <82544018+sgkouzias@users.noreply.github.com> Date: Mon, 17 Jun 2024 22:28:15 +0300 Subject: [PATCH 10/15] Simplify procedure by removing option to install with conda virtual env. Removed option to install within conda virtual environment. Recommendation to install in venv environment. --- site/en/install/pip.md | 87 +++--------------------------------------- 1 file changed, 5 insertions(+), 82 deletions(-) diff --git a/site/en/install/pip.md b/site/en/install/pip.md index 4b428467732..ce0cd95503f 100644 --- a/site/en/install/pip.md +++ b/site/en/install/pip.md @@ -193,38 +193,9 @@ The following NVIDIA® software are only required for GPU support. nvidia-smi ``` - ### 3. Install Miniconda - - You can skip this section if you have already installed `Miniconda` (referred as *option #1* in the next steps) or you prefer to use Python’s built-in `venv` module (referred as *option #2* in the next steps) instead. - - [Miniconda](https://docs.conda.io/en/latest/miniconda.html){:.external} - is the recommended approach for installing TensorFlow with GPU support. - It creates a separate environment to avoid changing any installed - software in your system. This is also the easiest way to install the - required software especially for the GPU setup. - - Follow the instuctions of the conda user guide to install miniconda - [Miniconda Installation Guide](https://conda.io/projects/conda/en/latest/user-guide/install/linux.html){:.external}. - - ### 4. Create a virtual environment - - * ***Option #1: Miniconda*** - - Create a new conda environment named `tf` with the following command. - - ```bash - conda create --name tf python=3.11 - ``` - You can activate and deactivate it with the following commands. - - ```bash - conda activate tf - conda deactivate - ``` - - * ***Option #2: venv*** + ### 3. Create a virtual environment with [venv](https://docs.python.org/3/library/venv.html){:.external} - The [venv](https://docs.python.org/3/library/venv.html){:.external} module supports creating lightweight “virtual environments”, each with their own independent set of Python packages installed in their site directories. + The venv module is part of Python’s standard library and is the officially recommended way to create virtual environments. Navigate to your desired virtual environments directory and create a new venv environment named `tf` with the following command. @@ -241,7 +212,7 @@ The following NVIDIA® software are only required for GPU support. Make sure that the virtual environment is activated for the rest of the installation. - ### 5. Install TensorFlow + ### 4. Install TensorFlow TensorFlow requires a recent version of pip, so upgrade your pip installation to be sure you're running the latest version. @@ -261,58 +232,10 @@ The following NVIDIA® software are only required for GPU support. Note: Do not install TensorFlow with `conda`. It may not have the latest stable version. `pip` is recommended since TensorFlow is only officially released to PyPI. - ### 6. Set environment variables + ### 5. Set environment variables You can skip this section if you only run TensorFlow on the CPU. - * ***Option #1: Miniconda*** - - Locate the directory for the conda environment in your terminal window by running in the terminal: - `echo $CONDA_PREFIX` - - Enter that directory and create these subdirectories and files: - - ```bash - cd $CONDA_PREFIX - mkdir -p ./etc/conda/activate.d - mkdir -p ./etc/conda/deactivate.d - touch ./etc/conda/activate.d/env_vars.sh - touch ./etc/conda/deactivate.d/env_vars.sh - ``` - Edit `./etc/conda/activate.d/env_vars.sh` as follows: - - ```bash - #!/bin/sh - - # Store original LD_LIBRARY_PATH - export ORIGINAL_LD_LIBRARY_PATH="${LD_LIBRARY_PATH}" - - # Get the CUDNN directory - CUDNN_DIR=$(dirname $(dirname $(python -c "import nvidia.cudnn; print(nvidia.cudnn.__file__)"))) - - # Set LD_LIBRARY_PATH to include CUDNN directory - export LD_LIBRARY_PATH=$(find ${CUDNN_DIR}/*/lib/ -type d -printf "%p:")${LD_LIBRARY_PATH:+:${LD_LIBRARY_PATH}} - - # Get the ptxas directory - PTXAS_DIR=$(dirname $(dirname $(python -c "import nvidia.cuda_nvcc; print(nvidia.cuda_nvcc.__file__)"))) - - # Set PATH to include the directory containing ptxas - export PATH=$(find ${PTXAS_DIR}/*/bin/ -type d -printf "%p:")${PATH:+:${PATH}} - ``` - Edit `./etc/conda/deactivate.d/env_vars.sh` as follows: - - ```bash - #!/bin/sh - - # Restore original LD_LIBRARY_PATH - export LD_LIBRARY_PATH="${ORIGINAL_LD_LIBRARY_PATH}" - - # Unset environment variables - unset CUDNN_DIR - unset PTXAS_DIR - ``` - * ***Option #2: venv*** - Locate the directory for the venv environment in your terminal window by running in the terminal: `echo $VIRTUAL_ENV` @@ -358,7 +281,7 @@ The following NVIDIA® software are only required for GPU support. } ``` - ### 7. Verify the installation + ### 6. Verify the installation Verify the CPU setup: From 7cf1c57de806b1527e53385ff5af0d56f5bd4caa Mon Sep 17 00:00:00 2001 From: Sotiris Gkouzias <82544018+sgkouzias@users.noreply.github.com> Date: Tue, 18 Jun 2024 19:09:02 +0300 Subject: [PATCH 11/15] Instructions to create symlinks to NVIDIA shared libraries and ptxas. Replaced instructions to modify default activate/deactivate scripts with instructions to create symlinks to NVIDIA shared libraries and ptxas. --- site/en/install/pip.md | 46 ++++++++---------------------------------- 1 file changed, 8 insertions(+), 38 deletions(-) diff --git a/site/en/install/pip.md b/site/en/install/pip.md index ce0cd95503f..2b4558a523c 100644 --- a/site/en/install/pip.md +++ b/site/en/install/pip.md @@ -232,53 +232,23 @@ The following NVIDIA® software are only required for GPU support. Note: Do not install TensorFlow with `conda`. It may not have the latest stable version. `pip` is recommended since TensorFlow is only officially released to PyPI. - ### 5. Set environment variables + ### 5. Virtual environment configuration You can skip this section if you only run TensorFlow on the CPU. - Locate the directory for the venv environment in your terminal window by running in the terminal: - `echo $VIRTUAL_ENV` - - Enter that directory and add the following lines at the end of the activate script `./bin/activate` as follows: + * Create symbolic links to NVIDIA shared libraries: ```bash - # Store original LD_LIBRARY_PATH - export ORIGINAL_LD_LIBRARY_PATH=$LD_LIBRARY_PATH - - # Get the CUDNN directory - CUDNN_DIR=$(dirname $(dirname $(python -c "import nvidia.cudnn; print(nvidia.cudnn.__file__)"))) - - # Set LD_LIBRARY_PATH to include CUDNN directory - export LD_LIBRARY_PATH=$(find ${CUDNN_DIR}/*/lib/ -type d -printf "%p:")${LD_LIBRARY_PATH:+:${LD_LIBRARY_PATH}} - - # Get the ptxas directory - PTXAS_DIR=$(dirname $(dirname $(python -c "import nvidia.cuda_nvcc; print(nvidia.cuda_nvcc.__file__)"))) - - # Set PATH to include the directory containing ptxas - export PATH=$(find ${PTXAS_DIR}/*/bin/ -type d -printf "%p:")${PATH:+:${PATH}} + pushd $(dirname $(python -c 'print(__import__("tensorflow").__file__)')) + ln -svf ../nvidia/*/lib/*.so* . + popd ``` - Add the following lines at the end of `deactivate` block in the activate script to ensure that the necessary NVIDIA environment variables are set only while the virtual environment is active: + * Create a symbolic link to ptxas: ```bash - deactivate () { - # ... - # Unset the added path to PATH if within the virtual environment - if [ -n "$VIRTUAL_ENV" ]; then - # Remove the path from PATH - PATH=$(echo $PATH | sed -e "s|${PTXAS_DIR}/*/bin/:||g") - fi - - # Restore original LD_LIBRARY_PATH - if [ -n "$ORIGINAL_LD_LIBRARY_PATH" ]; then - export LD_LIBRARY_PATH=$ORIGINAL_LD_LIBRARY_PATH - unset ORIGINAL_LD_LIBRARY_PATH - fi - - # Unset environment variables - unset CUDNN_DIR - unset PTXAS_DIR - } + ln -sf $(find $(dirname $(dirname $(python -c "import nvidia.cuda_nvcc; + print(nvidia.cuda_nvcc.__file__)"))/*/bin/) -name ptxas -print -quit) $VIRTUAL_ENV/bin/ptxas ``` ### 6. Verify the installation From 3046cdc2390e13acf1817661072c61e0dfa0b5b2 Mon Sep 17 00:00:00 2001 From: Sotiris Gkouzias <82544018+sgkouzias@users.noreply.github.com> Date: Wed, 19 Jun 2024 21:19:17 +0300 Subject: [PATCH 12/15] Removed deactivate command. --- site/en/install/pip.md | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/site/en/install/pip.md b/site/en/install/pip.md index 2b4558a523c..19d7b6469a2 100644 --- a/site/en/install/pip.md +++ b/site/en/install/pip.md @@ -203,11 +203,10 @@ The following NVIDIA® software are only required for GPU support. python3 -m venv tf ``` - You can activate and deactivate it with the following commands. + You can activate it with the following command. ```bash - source tf/bin/activate - deactivate + source tf/bin/activate ``` Make sure that the virtual environment is activated for the rest of the installation. From 7f5cce6e97b740b7d0dcb79edcd00c54d3db6ec2 Mon Sep 17 00:00:00 2001 From: Sotiris Gkouzias <82544018+sgkouzias@users.noreply.github.com> Date: Tue, 2 Jul 2024 19:42:14 +0300 Subject: [PATCH 13/15] Instructions to create symlinks in case the intended way doesn't work. Revised the step with instructions to configure the virtual environment variables for GPU users by adding a disclaimer. --- site/en/install/pip.md | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/site/en/install/pip.md b/site/en/install/pip.md index 19d7b6469a2..28e5360e38f 100644 --- a/site/en/install/pip.md +++ b/site/en/install/pip.md @@ -229,7 +229,7 @@ The following NVIDIA® software are only required for GPU support. pip install tensorflow ``` - Note: Do not install TensorFlow with `conda`. It may not have the latest stable version. `pip` is recommended since TensorFlow is only officially released to PyPI. + **Note:** Do not install TensorFlow with `conda`. It may not have the latest stable version. `pip` is recommended since TensorFlow is only officially released to PyPI. ### 5. Virtual environment configuration @@ -249,6 +249,10 @@ The following NVIDIA® software are only required for GPU support. ln -sf $(find $(dirname $(dirname $(python -c "import nvidia.cuda_nvcc; print(nvidia.cuda_nvcc.__file__)"))/*/bin/) -name ptxas -print -quit) $VIRTUAL_ENV/bin/ptxas ``` + *️⃣ **Disclaimer** + + Symbolic links are only necessary in case the intended way doesn't work, i.e. the components aren't being + detected, and/or conflict with the existing system CUDA installation. ### 6. Verify the installation From 64e7c5097ad570ac825ff4d3e203e81e6020dcd2 Mon Sep 17 00:00:00 2001 From: Sotiris Gkouzias <82544018+sgkouzias@users.noreply.github.com> Date: Wed, 3 Jul 2024 09:01:17 +0300 Subject: [PATCH 14/15] Reformat disclaimer on environment configuration step. Deleted asterisk emoji and placed disclaimer note before respective instructions. --- site/en/install/pip.md | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/site/en/install/pip.md b/site/en/install/pip.md index 28e5360e38f..f96d743e395 100644 --- a/site/en/install/pip.md +++ b/site/en/install/pip.md @@ -234,6 +234,9 @@ The following NVIDIA® software are only required for GPU support. ### 5. Virtual environment configuration You can skip this section if you only run TensorFlow on the CPU. + + Note: Symbolic links are only necessary in case the intended way doesn't work, i.e. the components aren't being + detected, and/or conflict with the existing system CUDA installation. * Create symbolic links to NVIDIA shared libraries: @@ -249,11 +252,7 @@ The following NVIDIA® software are only required for GPU support. ln -sf $(find $(dirname $(dirname $(python -c "import nvidia.cuda_nvcc; print(nvidia.cuda_nvcc.__file__)"))/*/bin/) -name ptxas -print -quit) $VIRTUAL_ENV/bin/ptxas ``` - *️⃣ **Disclaimer** - - Symbolic links are only necessary in case the intended way doesn't work, i.e. the components aren't being - detected, and/or conflict with the existing system CUDA installation. - + ### 6. Verify the installation Verify the CPU setup: From 06798ba3737d595e8c5a7880b0f3fdc63053d0ff Mon Sep 17 00:00:00 2001 From: Mark Daoust Date: Wed, 4 Sep 2024 14:38:58 -0700 Subject: [PATCH 15/15] Move the GPU debugging step to after the "Test the installation" step. --- site/en/install/pip.md | 41 ++++++++++++++++++++++++----------------- 1 file changed, 24 insertions(+), 17 deletions(-) diff --git a/site/en/install/pip.md b/site/en/install/pip.md index f96d743e395..670f54b874e 100644 --- a/site/en/install/pip.md +++ b/site/en/install/pip.md @@ -231,12 +231,29 @@ The following NVIDIA® software are only required for GPU support. **Note:** Do not install TensorFlow with `conda`. It may not have the latest stable version. `pip` is recommended since TensorFlow is only officially released to PyPI. - ### 5. Virtual environment configuration + ### 6. Verify the installation - You can skip this section if you only run TensorFlow on the CPU. - - Note: Symbolic links are only necessary in case the intended way doesn't work, i.e. the components aren't being - detected, and/or conflict with the existing system CUDA installation. + Verify the CPU setup: + + ```bash + python3 -c "import tensorflow as tf; print(tf.reduce_sum(tf.random.normal([1000, 1000])))" + ``` + + If a tensor is returned, you've installed TensorFlow successfully. + + Verify the GPU setup: + + ```bash + python3 -c "import tensorflow as tf; print(tf.config.list_physical_devices('GPU'))" + ``` + + If a list of GPU devices is returned, you've installed TensorFlow + successfully. **If not continue to the next step**. + + ### 6. [GPU only] Virtual environment configuration + + If the GPU test in the last section was unsuccessful, the most likely cause is that components aren't being detected, + and/or conflict with the existing system CUDA installation. So you need to add some symbolic links to fix this. * Create symbolic links to NVIDIA shared libraries: @@ -252,16 +269,6 @@ The following NVIDIA® software are only required for GPU support. ln -sf $(find $(dirname $(dirname $(python -c "import nvidia.cuda_nvcc; print(nvidia.cuda_nvcc.__file__)"))/*/bin/) -name ptxas -print -quit) $VIRTUAL_ENV/bin/ptxas ``` - - ### 6. Verify the installation - - Verify the CPU setup: - - ```bash - python3 -c "import tensorflow as tf; print(tf.reduce_sum(tf.random.normal([1000, 1000])))" - ``` - - If a tensor is returned, you've installed TensorFlow successfully. Verify the GPU setup: @@ -269,8 +276,8 @@ The following NVIDIA® software are only required for GPU support. python3 -c "import tensorflow as tf; print(tf.config.list_physical_devices('GPU'))" ``` - If a list of GPU devices is returned, you've installed TensorFlow - successfully. + + * {MacOS}