Linux & Windows TensorFlow 1.14 升級 2.2

準備嘗試升級TensorFlow 1.14 到2.2,需要同時升級本地和服務器的環境,本文記錄主要過程。

環境需求

當前TensorFlow最高版本 2.2.+ ,需要CUDA 10.1,cudnn 7.6

官網下載 :https://developer.nvidia.com/

顯卡驅動需要滿足CUDA版本要求

Linux

  • 下載 cuda_10.1.243_418.87.00_linux.run 並安裝(之前裝過並運行過TensorFlow,相關庫不過時的話可以不特意去裝 cudnn)

過程中不需要安裝驅動

將 /usr/local/cuda 軟鏈接 指向 cuda-10.1

在 ~/.bashrc 中添加環境變量:

export PATH="$PATH:/usr/local/cuda/bin"
export LD_LIBRARY_PATH="$LD_LIBRARY_PATH:/usr/local/cuda/lib64/"
export LIBRARY_PATH="$LIBRARY_PATH:/usr/local/cuda/lib64"  
  • 下載 TensorFlow :tensorflow_gpu-2.2.0-cp37-cp37m-manylinux2010_x86_64.whl

或使用pip安裝

pip install tensorflow-gpu

會自動安裝最新版 2.2.0 版本tf

Windows

  • 下載 cuda_10.1.243_426.00_win10.exe 並安裝(之前裝過並運行過TensorFlow,相關庫不過時的話可以不特意去裝 cudnn)

我之前安裝了CUDA10.0,不需要卸載原始版本,直接使用默認配置安裝新版CUDA即可

  • 下載 TensorFlow :tensorflow_gpu-2.2.0-cp37-cp37m-win_amd64.whl

或使用pip安裝

pip install tensorflow-gpu

會自動安裝最新版 2.2.0 版本tf

測試

  • python 環境下測試
>>> import tensorflow as tf
>>> tf.__version__
'2.2.0'
>>> tf.test.is_gpu_available()
WARNING:tensorflow:From <stdin>:1: is_gpu_available (from tensorflow.python.framework.test_util) is deprecated and will be removed in a future version.
Instructions for updating:
Use `tf.config.list_physical_devices('GPU')` instead.
2020-06-18 04:15:11.406300: I tensorflow/core/platform/cpu_feature_guard.cc:143] Your CPU supports instructions that this TensorFlow binary was not compiled to use: AVX2 FMA
2020-06-18 04:15:11.416107: I tensorflow/core/platform/profile_utils/cpu_utils.cc:102] CPU Frequency: 2498530000 Hz
2020-06-18 04:15:11.417069: I tensorflow/compiler/xla/service/service.cc:168] XLA service 0x55e39cc09290 initialized for platform Host (this does not guarantee that XLA will be used). Devices:
2020-06-18 04:15:11.417085: I tensorflow/compiler/xla/service/service.cc:176]   StreamExecutor device (0): Host, Default Version
2020-06-18 04:15:11.420284: I tensorflow/stream_executor/platform/default/dso_loader.cc:44] Successfully opened dynamic library libcuda.so.1
2020-06-18 04:15:11.593401: I tensorflow/compiler/xla/service/service.cc:168] XLA service 0x55e39ccc83a0 initialized for platform CUDA (this does not guarantee that XLA will be used). Devices:
2020-06-18 04:15:11.593427: I tensorflow/compiler/xla/service/service.cc:176]   StreamExecutor device (0): GeForce RTX 2080 Ti, Compute Capability 7.5
2020-06-18 04:15:11.594463: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1561] Found device 0 with properties: 
pciBusID: 0000:0a:00.0 name: GeForce RTX 2080 Ti computeCapability: 7.5
coreClock: 1.545GHz coreCount: 68 deviceMemorySize: 10.76GiB deviceMemoryBandwidth: 573.69GiB/s
2020-06-18 04:15:11.594765: I tensorflow/stream_executor/platform/default/dso_loader.cc:44] Successfully opened dynamic library libcudart.so.10.1
2020-06-18 04:15:11.596879: I tensorflow/stream_executor/platform/default/dso_loader.cc:44] Successfully opened dynamic library libcublas.so.10
2020-06-18 04:15:11.598737: I tensorflow/stream_executor/platform/default/dso_loader.cc:44] Successfully opened dynamic library libcufft.so.10
2020-06-18 04:15:11.599064: I tensorflow/stream_executor/platform/default/dso_loader.cc:44] Successfully opened dynamic library libcurand.so.10
2020-06-18 04:15:11.601174: I tensorflow/stream_executor/platform/default/dso_loader.cc:44] Successfully opened dynamic library libcusolver.so.10
2020-06-18 04:15:11.602319: I tensorflow/stream_executor/platform/default/dso_loader.cc:44] Successfully opened dynamic library libcusparse.so.10
2020-06-18 04:15:11.606633: I tensorflow/stream_executor/platform/default/dso_loader.cc:44] Successfully opened dynamic library libcudnn.so.7
2020-06-18 04:15:11.608814: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1703] Adding visible gpu devices: 0
2020-06-18 04:15:11.608929: I tensorflow/stream_executor/platform/default/dso_loader.cc:44] Successfully opened dynamic library libcudart.so.10.1
2020-06-18 04:15:11.610584: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1102] Device interconnect StreamExecutor with strength 1 edge matrix:
2020-06-18 04:15:11.610608: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1108]      0 
2020-06-18 04:15:11.610618: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1121] 0:   N 
2020-06-18 04:15:11.612706: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1247] Created TensorFlow device (/device:GPU:0 with 1958 MB memory) -> physical GPU (device: 0, name: GeForce RTX 2080 Ti, pci bus id: 0000:0a:00.0, compute capability: 7.5)
True

當最後一行輸出True表示GPU可用,如果是False請查看錯誤信息。

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章