Google致力於提高黑人社區的種族平等。 怎麼看。

GPU 支援

TensorFlow GPU 支援需要各種驅動程式和程式庫。為簡化安裝作業並避免發生程式庫衝突,建議你使用支援 GPU 的 TensorFlow Docker 映像檔 (僅限 Linux)。這項設定只需要 NVIDIA® GPU 驅動程式

這些安裝指示適用於最新版本的 TensorFlow。請參閱 CUDA 和 CuDNN 版本經過測試的建構設定,瞭解如何與舊版 TensorFlow 搭配使用。

Pip 套件

請參閱 pip 安裝指南以瞭解適用的套件、系統需求和相關指示。如要 pip 安裝支援 GPU 的 TensorFlow 套件,請選擇穩定版套件或開發版套件:

pip install tensorflow  # stable

pip install tf-nightly  # preview

舊版 TensorFlow

1.15 以下版本的 CPU 和 GPU 套件各自獨立:

pip install tensorflow==1.15      # CPU
pip install tensorflow-gpu==1.15  # GPU

硬體需求

支援採用以下 GPU 的裝置:

軟體需求

你的系統上必須安裝下列 NVIDIA® 軟體:

Linux 設定

下方的 apt 指示能讓你以最簡單的方式在 Ubuntu 上安裝必要的 NVIDIA 軟體。不過,如果你是從原始碼開始建構 TensorFlow,請手動安裝上述所需軟體,並考慮使用 -devel TensorFlow Docker 映像檔做為基礎。

安裝 CUDA® Toolkit 隨附的 CUPTI,並將其安裝目錄附加到 $LD_LIBRARY_PATH 環境變數中:

export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/usr/local/cuda/extras/CUPTI/lib64

請參閱從原始碼開始建構 (適用於 Linux) 指南,瞭解搭載 CUDA Compute Capability 3.0 或不同版本 NVIDIA 程式庫的 GPU。

使用 apt 安裝 CUDA

本節說明如何為 Ubuntu 16.04 和 18.04 安裝 CUDA 10 (TensorFlow 1.13.0 以上版本) 和 CUDA 9。以下指示可能也適用於其他以 Debian 為基礎的發行版本。

Ubuntu 18.04 (CUDA 10.1)

# Add NVIDIA package repositories
wget https://developer.download.nvidia.com/compute/cuda/repos/ubuntu1804/x86_64/cuda-repo-ubuntu1804_10.1.243-1_amd64.deb
sudo apt-key adv --fetch-keys https://developer.download.nvidia.com/compute/cuda/repos/ubuntu1804/x86_64/7fa2af80.pub
sudo dpkg -i cuda-repo-ubuntu1804_10.1.243-1_amd64.deb
sudo apt-get update
wget http://developer.download.nvidia.com/compute/machine-learning/repos/ubuntu1804/x86_64/nvidia-machine-learning-repo-ubuntu1804_1.0.0-1_amd64.deb
sudo apt install ./nvidia-machine-learning-repo-ubuntu1804_1.0.0-1_amd64.deb
sudo apt-get update

# Install NVIDIA driver
sudo apt-get install --no-install-recommends nvidia-driver-430
# Reboot. Check that GPUs are visible using the command: nvidia-smi

# Install development and runtime libraries (~4GB)
sudo apt-get install --no-install-recommends \
    cuda-10-1 \
    libcudnn7=7.6.4.38-1+cuda10.1  \
    libcudnn7-dev=7.6.4.38-1+cuda10.1


# Install TensorRT. Requires that libcudnn7 is installed above.
sudo apt-get install -y --no-install-recommends libnvinfer6=6.0.1-1+cuda10.1 \
    libnvinfer-dev=6.0.1-1+cuda10.1 \
    libnvinfer-plugin6=6.0.1-1+cuda10.1

Ubuntu 16.04 (CUDA 10.1)

# Add NVIDIA package repositories
# Add HTTPS support for apt-key
sudo apt-get install gnupg-curl
wget https://developer.download.nvidia.com/compute/cuda/repos/ubuntu1604/x86_64/cuda-repo-ubuntu1604_10.1.243-1_amd64.deb
sudo apt-key adv --fetch-keys https://developer.download.nvidia.com/compute/cuda/repos/ubuntu1604/x86_64/7fa2af80.pub
sudo dpkg -i cuda-repo-ubuntu1604_10.1.243-1_amd64.deb
sudo apt-get update
wget http://developer.download.nvidia.com/compute/machine-learning/repos/ubuntu1604/x86_64/nvidia-machine-learning-repo-ubuntu1604_1.0.0-1_amd64.deb
sudo apt install ./nvidia-machine-learning-repo-ubuntu1604_1.0.0-1_amd64.deb
sudo apt-get update

# Install NVIDIA driver
# Issue with driver install requires creating /usr/lib/nvidia
sudo mkdir /usr/lib/nvidia
sudo apt-get install --no-install-recommends nvidia-418
# Reboot. Check that GPUs are visible using the command: nvidia-smi

# Install development and runtime libraries (~4GB)
sudo apt-get install --no-install-recommends \
    cuda-10-1 \
    libcudnn7=7.6.4.38-1+cuda10.1  \
    libcudnn7-dev=7.6.4.38-1+cuda10.1


# Install TensorRT. Requires that libcudnn7 is installed above.
sudo apt-get install -y --no-install-recommends \
    libnvinfer6=6.0.1-1+cuda10.1 \
    libnvinfer-dev=6.0.1-1+cuda10.1 \
    libnvinfer-plugin6=6.0.1-1+cuda10.1

Ubuntu 16.04 (TensorFlow 1.13.0 以下版本的 CUDA 9.0)

# Add NVIDIA package repository
sudo apt-key adv --fetch-keys http://developer.download.nvidia.com/compute/cuda/repos/ubuntu1604/x86_64/7fa2af80.pub
wget http://developer.download.nvidia.com/compute/cuda/repos/ubuntu1604/x86_64/cuda-repo-ubuntu1604_9.1.85-1_amd64.deb
sudo apt install ./cuda-repo-ubuntu1604_9.1.85-1_amd64.deb
wget http://developer.download.nvidia.com/compute/machine-learning/repos/ubuntu1604/x86_64/nvidia-machine-learning-repo-ubuntu1604_1.0.0-1_amd64.deb
sudo apt install ./nvidia-machine-learning-repo-ubuntu1604_1.0.0-1_amd64.deb
sudo apt update

# Install the NVIDIA driver
# Issue with driver install requires creating /usr/lib/nvidia
sudo mkdir /usr/lib/nvidia
sudo apt-get install --no-install-recommends nvidia-410
# Reboot. Check that GPUs are visible using the command: nvidia-smi

# Install CUDA and tools. Include optional NCCL 2.x
sudo apt install cuda9.0 cuda-cublas-9-0 cuda-cufft-9-0 cuda-curand-9-0 \
    cuda-cusolver-9-0 cuda-cusparse-9-0 libcudnn7=7.2.1.38-1+cuda9.0 \
    libnccl2=2.2.13-1+cuda9.0 cuda-command-line-tools-9-0

# Optional: Install the TensorRT runtime (must be after CUDA install)
sudo apt update
sudo apt install libnvinfer4=4.1.2-1+cuda9.0

Windows 設定

請參閱上述硬體需求軟體需求,以及適用於 Windows 的 CUDA® 安裝指南

確認你已安裝符合上述版本的 NVIDIA 軟體套件。請特別注意,如果沒有 cuDNN64_7.dll 檔案,TensorFlow 就不會載入。如要使用其他版本,請參閱從原始碼開始建構 (適用於 Windows) 指南。

請將 CUDA、CUPTI 和 cuDNN 安裝目錄新增至 %PATH% 環境變數中。舉例來說,如果 CUDA Toolkit 已安裝至 C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v10.1,且 cuDNN 已安裝至 C:\tools\cuda,請根據這些安裝目錄來更新 %PATH%

SET PATH=C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v10.1\bin;%PATH%
SET PATH=C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v10.1\extras\CUPTI\libx64;%PATH%
SET PATH=C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v10.1\include;%PATH%
SET PATH=C:\tools\cuda\bin;%PATH%