本文最后更新于:2023年12月5日 下午

准备尝试升级TensorFlow 1.14 到2.2,需要同时升级本地和服务器的环境,本文记录主要过程。

环境需求

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

官网下载 :https://developer.nvidia.com/

显卡驱动需要满足CUDA版本要求

CUDA与显卡驱动:https://docs.nvidia.com/cuda/cuda-toolkit-release-notes/index.html

TensorFlow-GPU与CUDA cudnn Python版本关系:https://tensorflow.google.cn/install/source_windows?hl=en#gpu

Linux

  • 下载 cuda_10.1.243_418.87.00_linux.run 并安装(之前装过并运行过TensorFlow,相关库不过时的话可以不特意去装 cudnn)

过程中不需要安装驱动

将 /usr/local/cuda 软链接 指向 cuda-10.1

在 ~/.bashrc 中添加环境变量:

1
2
3
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安装

1
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安装

1
pip install tensorflow-gpu

会自动安装最新版 2.2.0 版本tf

测试

  • python 环境下测试
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
>>> 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请查看错误信息。



文章链接:
https://www.zywvvd.com/notes/environment/cuda/Linux-tensorflow-2-2-install/Linux-tensorflow-2-2-install/


“觉得不错的话,给点打赏吧 ୧(๑•̀⌄•́๑)૭”

微信二维码

微信支付

支付宝二维码

支付宝支付

Linux & Windows TensorFlow 1.14 升级 2.2
https://www.zywvvd.com/notes/environment/cuda/Linux-tensorflow-2-2-install/Linux-tensorflow-2-2-install/
作者
Yiwei Zhang
发布于
2020年6月18日
许可协议