繁体   English   中英

Tensorflow 1.15 之后 - 无需安装 tensorflow-gpu package

[英]Tensorflow after 1.15 - No need to install tensorflow-gpu package

问题

Please confirm that to use both CPU and GPU with TensorFlow after 1.15 , install tensorflow package is enough and tensorflow-gpu is no more required.

背景

仍然看到说明安装tensorflow-gpu 的文章,例如pip install tensorflow-gpu==2.2.0tensorflow-gpu package 的 PyPi 存储库在最新的tensorflow-gpu 2.4.1中处于活动状态。

Annaconda 文档还提到了 tensorflow-gpu package。

TensorFlow 是一个通用机器学习库,但在深度学习应用中最流行。 Z853F30A23CE8B86946C91D67F5C78Z 中的 tensorflow package 支持三种变体,其中之一是 NVIDIA Z52F9EC17CD329 版本。 这是通过安装元包 tensorflow-gpu 来选择的:

但是,根据 TensorFlow v2.4.1(截至 2021 年 4 月)核心文档GPU 支持 - TensorFlow 的旧版本

对于 1.15 及更早版本,CPU 和 GPU 包是分开的:

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

根据 TensorFlow 核心指南使用 GPU

TensorFlow 代码和 tf.keras 模型将透明地在单个 GPU 上运行,无需更改代码。

根据TensorFlow GPU 与 CPU 的安装库之间的差异

只是一个快速(不必要的?)注意......从 TensorFlow 2.0 开始,这些没有分开,您只需安装 tensorflow(因为这包括 GPU 支持,如果您安装了适当的卡)。

因此,希望明确确认 tensorflow-gpu package 只是为了方便(已指定 tensorflow-gpu 等的旧脚本),不再需要。 现在 tensorflow 和 tensorflow-gpu 包之间没有区别。

在这里对 package 命名感到困惑是合理的。 但是,这是我的理解。 对于tf 1.15更早版本CPUGPU包是分开的:

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

因此,如果我想完全在tfCPU版本上工作,我将使用第一个命令 go ,否则,如果我想完全在tfGPU版本上工作,我将使用第二个命令 Z34D1F91FB2E514B85BZFAB 。


现在,在tf 2.0或更高版本中,我们只需要一个可以方便地在两种硬件上运行的命令 因此,在基于CPUGPU的系统中,我们需要相同的命令来安装tf ,即:

pip install tensorflow

现在,我们可以在基于CPU的系统上测试它(没有GPU

import tensorflow as tf 
print(tf.__version__)

print('1: ', tf.config.list_physical_devices('GPU'))
print('2: ', tf.test.is_built_with_cuda)
print('3: ', tf.test.gpu_device_name())
print('4: ', tf.config.get_visible_devices())

2.4.1
1:  []
2:  <function is_built_with_cuda at 0x7f2ce91415f0>
3:  
4:  [PhysicalDevice(name='/physical_device:CPU:0', device_type='CPU')]

或者也在基于CPU的系统上进行测试(使用GPU

2.4.1
1:  [PhysicalDevice(name='/physical_device:GPU:0', device_type='GPU')]
2:  <function is_built_with_cuda at 0x7fb6affd0560>
3:  /device:GPU:0
4:  [PhysicalDevice(name='/physical_device:CPU:0', device_type='CPU'),
     PhysicalDevice(name='/physical_device:GPU:0', device_type='GPU')]

因此,正如您所见,这只是针对CPUGPU案例的单个命令。 希望现在更清楚了。 但直到现在(在tf > = 2中)我们还可以在安装tf时使用-gpu / -cpu后缀,分别用于GPU / CPU

!pip install tensorflow-gpu 
....
Installing collected packages: tensorflow-gpu
Successfully installed tensorflow-gpu-2.4.1

# -------------------------------------------------------------

!pip install tensorflow-cpu
....
Installing collected packages: tensorflow-cpu
Successfully installed tensorflow-cpu-2.4.1

检查:来自 tf-team 的类似响应

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM