为什么Anaconda有单独的Tensorflow软件包,有GPU和没有GPU,我应该使用conda还是pip?

2024-09-30 10:28:14 发布

您现在位置:Python中文网/ 问答频道 /正文

Anaconda有不同的Tensorflow包,有GPU支持和没有GPU支持

特别是,要使用GPU安装Tensorflow,您应该运行:

conda install tensorflow-gpu

对于非GPU版本,您应安装:

conda install tensorflow

通过检查已安装软件包的版本,conda将安装Tensorflow 2.1版

但到今天为止,Tensorflow的最新版本是2.3。此外,正如在Tensorflow officla documentation中所看到的,最新版本可以安装在

pip install tensorflow

文档中说这个包对于Tensorflow的CPU和GPU版本都很好。此外,文档中还指出,CPU和GPU的软件包在“1.15及更高版本”中有所不同

  1. 为什么Anaconda在两个不同的包中提供2.1,因为任何版本的包都应该相同>;1.15?

  2. 我应该安装哪一个,pip版本还是conda版本?Anaconda blog中的一篇文章指出,与conda一起提供的版本更快,但这篇文章是旧的(2018),并且引用了Tensorflow的旧版本(1.10)


Tags: installpip文档gt版本gputensorflowdocumentation
2条回答

By checking the version of the installed package, conda installs Tensorflow version 2.1. But as of today the latest version of Tensorflow is 2.3. Furthermore

那只是因为你(可能?)在windows上。正如您所看到的,heretensorflow作为2.3从conda默认通道中可用,但目前仅在linux上可用

你的网站上也说明了原因linked(我的重点):

Anaconda is proud of our efforts to deliver a simpler, faster experience using the excellent TensorFlow library. It takes significant time and effort to add support for the many platforms used in production, and to ensure that the accelerated code is still stable and mathematically correct. As a result, our TensorFlow packages may not be available concurrently with the official TensorFlow wheels. We are, however, committed to maintaining our TensorFlow packages, and work to have updates available as soon as we can.

简而言之:Anaconda团队正在针对intel mkl库创建自定义tf版本,以加快CPU上的计算速度。早些时候在同一个网站上,他们还提到他们为不同的cuda版本创建版本

Why Anaconda provides 2.1 in two different packages, given that the package should be the same for any version > 1.15?

tensorflow-gpu软件包只是一个元软件包,也就是说,它只用于安装具有不同依赖项的不同版本的tensorflow(也使您能够安装不同的cuda版本)。官方版本只允许combinations的tensorflow版本和cuda

Which one should I install, the pip version or the conda version? An article in Anaconda blog specifies that the version provided with conda is faster, but the article is old (2018) and refers to an old version of Tensorflow (1.10)

在阅读上述文章时,这种加速与针对英特尔mkl库的构建有关,后者可以加速CPU上的计算。考虑到您的设置,在使用conda时只能安装tensorflow2.1,您需要问问自己是否依赖最新的tensorflow版本,以及是否不需要加速的cpu代码。使用pip安装最新的tensorflow通常没有问题。只需确保您为上述tensorflow版本创建了一个新环境,并且仅在该环境中使用pip安装/更新tensorflow或其任何依赖项即可。有general advice到不混合condapip安装太多,因为一个安装可能会破坏另一个安装(因为它们使用不同的方法来解决依赖关系),但使用单独的env时应该很好

如果您使用的是Anaconda,则可以使用conda安装tensorflow。对于cpu版本,输入

conda install tensorflow
for the gpu version enter
conda install tensorflow-gpu.

如果您使用的是Windows,它将安装版本2.1.0、cuda工具包版本10.1.243和cudnn版本7.6.5。注意:conda只能在Windows操作系统上安装tensorflow版本2.1.0。如果需要tensorflow 2.2.0或2.3.0,请在安装2.1后使用pip使用pip安装它。cuda工具包和cudnn使用2.2和2.3版。还有一件事。使用python3.7而不是3.8。显然,当你用conda安装tensorflow时,它不能与3.8兼容。 如果您使用pip安装tensorflow 2.1或更高版本,它包括cpu和gpu版本,但是您必须通过手动过程来安装Cuda Toolkit和cudnn。这包括从NVIDIA下载文件。您还必须更改PATH环境变量

相关问题 更多 >

    热门问题