Skip to content

Commit

Permalink
Rewrite TF GPU installation instructions to use [and-cuda] instead of…
Browse files Browse the repository at this point in the history
… conda

TF 2.14 supports `pip install
tensorflow[and-cuda]`, which should totally remove the need for miniconda in
the installation process.

The Miniconda instructions provided:

1. The CUDA libraries
2. A virtual Python environment

These new instructions _only_ provide the CUDA libraries, not a virtual
environment. This is consistent with the CPU installation methods.

PiperOrigin-RevId: 569336143
  • Loading branch information
angerson authored and copybara-github committed Sep 29, 2023
1 parent bf28fbd commit 7442d72
Showing 1 changed file with 28 additions and 233 deletions.
261 changes: 28 additions & 233 deletions site/en/install/pip.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# Install TensorFlow with pip

# Install TensorFlow with pip
<!-- mdformat global-off -->

This guide is for the latest stable version of TensorFlow. For the
Expand All @@ -26,13 +26,8 @@ step-by-step instructions.
for more information about this collaboration.

```bash
conda install -c conda-forge cudatoolkit=11.8.0
python3 -m pip install nvidia-cudnn-cu11==8.6.0.163 tensorflow==2.13.*
mkdir -p $CONDA_PREFIX/etc/conda/activate.d
echo 'CUDNN_PATH=$(dirname $(python -c "import nvidia.cudnn;print(nvidia.cudnn.__file__)"))' >> $CONDA_PREFIX/etc/conda/activate.d/env_vars.sh
echo 'export LD_LIBRARY_PATH=$CUDNN_PATH/lib:$CONDA_PREFIX/lib/:$LD_LIBRARY_PATH' >> $CONDA_PREFIX/etc/conda/activate.d/env_vars.sh
source $CONDA_PREFIX/etc/conda/activate.d/env_vars.sh
# Verify install:
python3 -m pip install tensorflow[and-cuda]
# Verify the installation:
python3 -c "import tensorflow as tf; print(tf.config.list_physical_devices('GPU'))"
```

Expand All @@ -41,7 +36,7 @@ step-by-step instructions.
```bash
# There is currently no official GPU support for MacOS.
python3 -m pip install tensorflow
# Verify install:
# Verify the installation:
python3 -c "import tensorflow as tf; print(tf.reduce_sum(tf.random.normal([1000, 1000])))"
```

Expand All @@ -58,7 +53,7 @@ step-by-step instructions.
conda install -c conda-forge cudatoolkit=11.2 cudnn=8.1.0
# Anything above 2.10 is not supported on the GPU on Windows Native
python -m pip install "tensorflow<2.11"
# Verify install:
# Verify the installation:
python -c "import tensorflow as tf; print(tf.config.list_physical_devices('GPU'))"
```

Expand All @@ -75,13 +70,8 @@ step-by-step instructions.
for CUDA in WSL.

```bash
conda install -c conda-forge cudatoolkit=11.8.0
python3 -m pip install nvidia-cudnn-cu11==8.6.0.163 tensorflow==2.13.*
mkdir -p $CONDA_PREFIX/etc/conda/activate.d
echo 'CUDNN_PATH=$(dirname $(python -c "import nvidia.cudnn;print(nvidia.cudnn.__file__)"))' >> $CONDA_PREFIX/etc/conda/activate.d/env_vars.sh
echo 'export LD_LIBRARY_PATH=$CUDNN_PATH/lib:$CONDA_PREFIX/lib/:$LD_LIBRARY_PATH' >> $CONDA_PREFIX/etc/conda/activate.d/env_vars.sh
source $CONDA_PREFIX/etc/conda/activate.d/env_vars.sh
# Verify install:
python3 -m pip install tensorflow[and-cuda]
# Verify the installation:
python3 -c "import tensorflow as tf; print(tf.config.list_physical_devices('GPU'))"
```

Expand All @@ -103,15 +93,15 @@ step-by-step instructions.
```bash
python3 -m pip install tensorflow
# Verify install:
# Verify the installation:
python3 -c "import tensorflow as tf; print(tf.reduce_sum(tf.random.normal([1000, 1000])))"
```
* {Nightly}
```bash
python3 -m pip install tf-nightly
# Verify install:
# Verify the installation:
python3 -c "import tensorflow as tf; print(tf.reduce_sum(tf.random.normal([1000, 1000])))"
```
Expand Down Expand Up @@ -190,47 +180,11 @@ The following NVIDIA® software are only required for GPU support.
[this blog post](https://blog.tensorflow.org/2022/09/announcing-tensorflow-official-build-collaborators.html)
for more information about this collaboration.

### 2. 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.

You can use the following command to install Miniconda. During installation,
you may need to press enter and type "yes".

```bash
curl https://repo.anaconda.com/miniconda/Miniconda3-latest-Linux-x86_64.sh -o Miniconda3-latest-Linux-x86_64.sh
bash Miniconda3-latest-Linux-x86_64.sh
```

You may need to restart your terminal or `source ~/.bashrc` to enable the
`conda` command. Use `conda -V` to test if it is installed successfully.

### 3. Create a conda environment

Create a new conda environment named `tf` with the following command.

```bash
conda create --name tf python=3.9
```

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.

### 4. GPU setup
### 2. GPU setup

You can skip this section if you only run TensorFlow on the CPU.

First install the
Install the
[NVIDIA GPU driver](https://www.nvidia.com/Download/index.aspx){:.external}
if you have not. You can use the following command to verify it is
installed.
Expand All @@ -239,32 +193,7 @@ The following NVIDIA® software are only required for GPU support.
nvidia-smi
```

Then install CUDA and cuDNN with conda and pip.

```bash
conda install -c conda-forge cudatoolkit=11.8.0
pip install nvidia-cudnn-cu11==8.6.0.163
```

Configure the system paths. You can do it with the following command every time
you start a new terminal after activating your conda environment.

```bash
CUDNN_PATH=$(dirname $(python -c "import nvidia.cudnn;print(nvidia.cudnn.__file__)"))
export LD_LIBRARY_PATH=$CUDNN_PATH/lib:$CONDA_PREFIX/lib/:$LD_LIBRARY_PATH
```

For your convenience it is recommended that you automate it with the following
commands. The system paths will be automatically configured when you
activate this conda environment.

```bash
mkdir -p $CONDA_PREFIX/etc/conda/activate.d
echo 'CUDNN_PATH=$(dirname $(python -c "import nvidia.cudnn;print(nvidia.cudnn.__file__)"))' >> $CONDA_PREFIX/etc/conda/activate.d/env_vars.sh
echo 'export LD_LIBRARY_PATH=$CUDNN_PATH/lib:$CONDA_PREFIX/lib/:$LD_LIBRARY_PATH' >> $CONDA_PREFIX/etc/conda/activate.d/env_vars.sh
```

### 5. Install TensorFlow
### 3. Install TensorFlow

TensorFlow requires a recent version of pip, so upgrade your pip
installation to be sure you're running the latest version.
Expand All @@ -275,15 +204,14 @@ The following NVIDIA® software are only required for GPU support.
Then, install TensorFlow with pip.
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.
```bash
pip install tensorflow==2.13.*
# For GPU users
pip install tensorflow[and-cuda]
# For CPU users
pip install tensorflow
```
### 6. Verify install
### 4. Verify the installation
Verify the CPU setup:
Expand All @@ -302,32 +230,6 @@ The following NVIDIA® software are only required for GPU support.
If a list of GPU devices is returned, you've installed TensorFlow
successfully.
### Ubuntu 22.04
In Ubuntu 22.04, you may encounter the following error:
```
Can't find libdevice directory ${CUDA_DIR}/nvvm/libdevice.
...
Couldn't invoke ptxas --version
...
InternalError: libdevice not found at ./libdevice.10.bc [Op:__some_op]
```
To fix this error, you will need to run the following commands.
```bash
# Install NVCC
conda install -c nvidia cuda-nvcc=11.3.58
# Configure the XLA cuda directory
mkdir -p $CONDA_PREFIX/etc/conda/activate.d
printf 'export XLA_FLAGS=--xla_gpu_cuda_data_dir=$CONDA_PREFIX/lib/\n' >> $CONDA_PREFIX/etc/conda/activate.d/env_vars.sh
source $CONDA_PREFIX/etc/conda/activate.d/env_vars.sh
# Copy libdevice file to the required path
mkdir -p $CONDA_PREFIX/lib/nvvm/libdevice
cp $CONDA_PREFIX/lib/libdevice.10.bc $CONDA_PREFIX/lib/nvvm/libdevice/
```
* {MacOS}
### 1. System requirements
Expand Down Expand Up @@ -355,48 +257,7 @@ The following NVIDIA® software are only required for GPU support.
python3 -m pip --version
```

### 3. Install Miniconda

[Miniconda](https://docs.conda.io/en/latest/miniconda.html){:.external}
is the recommended approach for installing TensorFlow.
It creates a separate environment to avoid changing any installed
software in your system.

Note: Miniconda is not a requirement for running TensorFlow on CPU. If you'd
prefer to create a virtual environment using
[venv](https://docs.python.org/3/library/venv.html) or
[Virtualenv](https://virtualenv.pypa.io/en/latest/), you can do so. Just
adjust the installation steps accordingly, and then follow the instructions
to install TensorFlow using pip.
Install Miniconda:
```bash
curl https://repo.anaconda.com/miniconda/Miniconda3-latest-MacOSX-x86_64.sh -o Miniconda3-latest-MacOSX-x86_64.sh
bash Miniconda3-latest-MacOSX-x86_64.sh
```
You may need to restart your terminal or `source ~/.bashrc` to enable the
`conda` command. Use `conda -V` to test if it is installed successfully.
### 4. Create a conda environment
Create a new conda environment named `tf` with the following command.
```bash
conda create --name tf python=3.9
```
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
### 3. Install TensorFlow

TensorFlow requires a recent version of pip, so upgrade your pip
installation to be sure you're running the latest version.
Expand All @@ -407,15 +268,11 @@ The following NVIDIA® software are only required for GPU support.
Then, install TensorFlow with pip.
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.

```bash
pip install tensorflow
```
### 6. Verify install
### 4. Verify the installation
```bash
python3 -c "import tensorflow as tf; print(tf.reduce_sum(tf.random.normal([1000, 1000])))"
Expand Down Expand Up @@ -531,7 +388,7 @@ The following NVIDIA® software are only required for GPU support.
pip install "tensorflow<2.11"
```

### 7. Verify install
### 7. Verify the installation

Verify the CPU setup:

Expand Down Expand Up @@ -563,47 +420,11 @@ The following NVIDIA® software are only required for GPU support.
* [Install WSL2](https://docs.microsoft.com/windows/wsl/install){:.external}
* [Setup NVIDIA® GPU support in WSL2](https://docs.nvidia.com/cuda/wsl-user-guide/index.html){:.external}

### 2. 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.
You can use the following command to install Miniconda. During installation,
you may need to press enter and type "yes".
```bash
curl https://repo.anaconda.com/miniconda/Miniconda3-latest-Linux-x86_64.sh -o Miniconda3-latest-Linux-x86_64.sh
bash Miniconda3-latest-Linux-x86_64.sh
```
You may need to restart your terminal or `source ~/.bashrc` to enable the
`conda` command. Use `conda -V` to test if it is installed successfully.
### 3. Create a conda environment
Create a new conda environment named <a href="https://www.tensorflow.org/api_docs/python/tf"><code>tf</code></a> with the following command.
```bash
conda create --name tf python=3.9
```
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.
### 4. GPU setup
### 2. GPU setup

You can skip this section if you only run TensorFlow on the CPU.

First install the
Install the
[NVIDIA GPU driver](https://www.nvidia.com/Download/index.aspx){:.external}
if you have not. You can use the following command to verify it is
installed.
Expand All @@ -612,32 +433,7 @@ The following NVIDIA® software are only required for GPU support.
nvidia-smi
```

Then install CUDA and cuDNN with conda and pip.
```bash
conda install -c conda-forge cudatoolkit=11.8.0
pip install nvidia-cudnn-cu11==8.6.0.163
```
Configure the system paths. You can do it with following command everytime
your start a new terminal after activating your conda environment.
```bash
CUDNN_PATH=$(dirname $(python -c "import nvidia.cudnn;print(nvidia.cudnn.__file__)"))
export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:$CUDNN_PATH/lib:$CONDA_PREFIX/lib/
```
For your convenience it is recommended that you automate it with the following
commands. The system paths will be automatically configured when you
activate this conda environment.
```bash
mkdir -p $CONDA_PREFIX/etc/conda/activate.d
echo 'CUDNN_PATH=$(dirname $(python -c "import nvidia.cudnn;print(nvidia.cudnn.__file__)"))' >> $CONDA_PREFIX/etc/conda/activate.d/env_vars.sh
echo 'export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:$CUDNN_PATH/lib:$CONDA_PREFIX/lib/' >> $CONDA_PREFIX/etc/conda/activate.d/env_vars.sh
```
### 5. Install TensorFlow
### 3. Install TensorFlow

TensorFlow requires a recent version of pip, so upgrade your pip
installation to be sure you're running the latest version.
Expand All @@ -648,15 +444,14 @@ The following NVIDIA® software are only required for GPU support.
Then, install TensorFlow with pip.
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.

```bash
pip install tensorflow==2.13.*
# For GPU users
pip install tensorflow[and-cuda]
# For CPU users
pip install tensorflow
```
### 6. Verify install
### 4. Verify the installation
Verify the CPU setup:
Expand Down

0 comments on commit 7442d72

Please sign in to comment.