1.15 之后的 Tensorflow - 无需安装 tensorflow-gpu 包 [英] Tensorflow after 1.15 - No need to install tensorflow-gpu package

查看:133
本文介绍了1.15 之后的 Tensorflow - 无需安装 tensorflow-gpu 包的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

请确认在 TensorFlow1.15 之后要同时使用 CPU 和 GPU,安装 tensorflow 包就足够了,tensorflow-gpu 就不用了需要.

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.0张量流的 PyPi 存储库-gpu 包 与最新的 tensorflow-gpu 2.4.1 一起使用.

Still see articles stating to install tensorflow-gpu e.g. pip install tensorflow-gpu==2.2.0 and the PyPi repository for tensorflow-gpu package is active with the latest tensorflow-gpu 2.4.1.

Annaconda 文档还引用了 tensorflow-gpu 包.

The Annaconda document also refers to tensorflow-gpu package still.

TensorFlow 是一个通用的机器学习库,但最常用于深度学习应用.Anaconda 中支持三种 tensorflow 包变体,其中之一是 NVIDIA GPU 版本.这是通过安装元包tensorflow-gpu来选择的:

TensorFlow is a general machine learning library, but most popular for deep learning applications. There are three supported variants of the tensorflow package in Anaconda, one of which is the NVIDIA GPU version. This is selected by installing the meta-package tensorflow-gpu:

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

However, according to the TensorFlow v2.4.1 (as of Apr 2021) Core document GPU support - Older versions of TensorFlow

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

For releases 1.15 and older, CPU and GPU packages are separate:

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

根据 TensorFlow 核心指南使用 GPU.

According to the TensorFlow Core Guide Use a GPU.

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

TensorFlow code, and tf.keras models will transparently run on a single GPU with no code changes required.

根据TensorFlow GPU 与 CPU 安装库的区别.

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

Just a quick (unnecessary?) note... from TensorFlow 2.0 onwards these are not separated, and you simply install tensorflow (as this includes GPU support if you have an appropriate card/CUDA installed).

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

Hence would like to have a definite confirmation that the tensorflow-gpu package would be for convenience (legacy script which has specified tensorflow-gpu, etc) only and no more required. There is no difference between tensorflow and tensorflow-gpu packages now.

推荐答案

在这里对包命名感到困惑是合理的.然而,这是我的理解.对于 tf 1.15旧版CPUGPU 包是分开的:

It's reasonable to get confused here about the package naming. However, here is my understanding. For tf 1.15 or older, the CPU and GPU packages are separate:

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

因此,如果我想完全在 tfCPU 版本上工作,我会使用第一个命令,否则,如果我想完全在GPU 版本的 tf,我会使用第二个命令.

So, if I want to work entirely on the CPU version of tf, I would go with the first command and otherwise, if I want to work entirely on the GPU version of tf, I would go with the second command.

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

Now, in tf 2.0 or above, we only need one command that will conveniently work on both hardware. So, in the CPU and GPU based system, we need the same command to install tf, and that is:

pip install tensorflow

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

Now, we can test it on a CPU based system ( no 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 的系统上进行测试(with GPU)

or also test it on a CPU based system ( with 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 分别.

So, as you can see this is just a single command for both CPU and GPU cases. Hope it's clear now more. But until now (in tf > = 2) we can also use -gpu / -cpu postfix while installing tf that delicately use for GPU / CPU respectively.

!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

这篇关于1.15 之后的 Tensorflow - 无需安装 tensorflow-gpu 包的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆