[英]Why Anaconda has separate packages for Tensorflow with and without GPU, and should I use conda or pip?
Anaconda has different packages for Tensorflow with and without GPU support. Anaconda为 Tensorflow 提供了不同的包,有和没有 GPU 支持。
In particular, to install Tensorflow with GPU, you should run:特别是,要使用 GPU 安装 Tensorflow,您应该运行:
conda install tensorflow-gpu
While for the non-GPU version, you should install:对于非 GPU 版本,您应该安装:
conda install tensorflow
By checking the version of the installed package, conda installs Tensorflow version 2.1.通过检查安装包的版本,conda 安装了 Tensorflow 2.1 版。
But as of today the latest version of Tensorflow is 2.3.但截至今天,Tensorflow 的最新版本是 2.3。 Furthermore, as can be seen in the Tensorflow officla documentation , the latest version can be installed with此外,正如在Tensorflow 官方文档中所见,最新版本可以安装
pip install tensorflow
This package is said in the documentation to be good both for CPU and GPU versions of Tensorflow.文档中说这个包对 Tensorflow 的 CPU 和 GPU 版本都很好。 Moreover, the documentation states that the packages for CPU and GPU were different for "for releases 1.15 and older".此外,文档指出 CPU 和 GPU 的包对于“1.15 及更早版本”是不同的。
Why Anaconda provides 2.1 in two different packages, given that the package should be the same for any version > 1.15?为什么 Anaconda 在两个不同的包中提供 2.1,因为对于任何大于 1.15 的版本,包都应该是相同的?
Which one should I install, the pip version or the conda version?我应该安装哪一个,pip 版本还是 conda 版本? 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) Anaconda 博客中的一篇文章指出 conda 提供的版本更快,但文章较旧(2018 年),并引用了旧版本的 Tensorflow(1.10)
By checking the version of the installed package, conda installs Tensorflow version 2.1.通过检查安装包的版本,conda 安装了 Tensorflow 2.1 版。 But as of today the latest version of Tensorflow is 2.3.但截至今天,Tensorflow 的最新版本是 2.3。 Furthermore此外
That is only because you are (probably?) on windows.那只是因为您(可能?)在 Windows 上。 As you can see here tensorflow
is available as 2.3 from conda
default channels, but currently only on linux.正如您在此处看到的, tensorflow
可从conda
默认通道以 2.3 的形式使用,但目前仅在 linux 上可用。
The reason is also stated on the website you have linked (emphasis mine):您链接的网站上也说明了原因(重点是我的):
Anaconda is proud of our efforts to deliver a simpler, faster experience using the excellent TensorFlow library. Anaconda 为我们努力使用出色的 TensorFlow 库提供更简单、更快的体验而感到自豪。 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 .因此,我们的 TensorFlow 软件包可能无法与官方 TensorFlow 轮子同时使用。 We are, however, committed to maintaining our TensorFlow packages, and work to have updates available as soon as we can.但是,我们致力于维护我们的 TensorFlow 软件包,并努力尽快提供更新。
In short: The Anaconda team is creating custom builds of tf against the intel mkl library to speed up calculations on the CPU.简而言之:Anaconda 团队正在针对 intel mkl 库创建 tf 的自定义构建,以加快 CPU 上的计算。 Earlier on the same website they also mention that they create builds for different cuda versions.早些时候在同一网站上,他们还提到他们为不同的 cuda 版本创建了构建。
Why Anaconda provides 2.1 in two different packages, given that the package should be the same for any version > 1.15?为什么 Anaconda 在两个不同的包中提供 2.1,因为对于任何大于 1.15 的版本,包都应该是相同的?
The tensorflow-gpu
package is only a meta-package, ie it is only used to install a different build of tensorflow
with different dependencies (also enabling you to install for different cuda versions). tensorflow-gpu
包只是一个元包,即它仅用于安装具有不同依赖项的不同构建的tensorflow
(也使您能够安装不同的 cuda 版本)。 The official releases only allow for combinations of tensorflow version and cuda.官方版本只允许 tensorflow 版本和 cuda 的组合。
Which one should I install, the pip version or the conda version?我应该安装哪一个,pip 版本还是 conda 版本? 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) Anaconda 博客中的一篇文章指出 conda 提供的版本更快,但文章较旧(2018 年),并引用了旧版本的 Tensorflow(1.10)
Reading said article, the speed up is linked to building against the intel mkl library, which speeds up calculations on the CPU.阅读上述文章,加速与针对 intel mkl 库的构建有关,该库可加速 CPU 上的计算。 Given that for your setup, you can only get tensorflow
2.1 installed when using conda
, you will need to ask yourself if you rely on the newest tensorflow
version and if you don't need the accelerated cpu code.鉴于您的设置,你只能得到tensorflow
使用时安装2.1 conda
,你需要问自己,如果你依靠最新tensorflow
版本,如果你不需要加速CPU代码。 There is usually nothing wrong with installing the newest tensorflow using pip
.使用pip
安装最新的 tensorflow 通常没有问题。 Just make sure that you create a new environment for said tensorflow version and only install/update tensorflow or any of its dependencies using pip
in that environment.只需确保为所述 tensorflow 版本创建一个新环境,并且仅在该环境中使用pip
安装/更新 tensorflow 或其任何依赖项。 There is general advice to not mix conda
and pip
installations too much, since one could break the other (since they are using different ways to resolve dependencies), but you should be fine when using a seperate env 一般建议不要过多地混合conda
和pip
安装,因为一个可能会破坏另一个(因为它们使用不同的方法来解决依赖关系),但是使用单独的 env 时应该没问题
If you are using Anaconda then you can use conda to install tensorflow.如果您使用的是 Anaconda,那么您可以使用 conda 来安装 tensorflow。 For the cpu version enter对于 cpu 版本,输入
conda install tensorflow
for the gpu version enter
conda install tensorflow-gpu.
If you are using Windows it will install version 2.1.0, the cuda toolkit version 10.1.243 and cudnn version 7.6.5.如果您使用的是 Windows,它将安装 2.1.0 版、cuda 工具包 10.1.243 版和 cudnn 7.6.5 版。 Note conda can only install tensorflow up to version 2.1.0 on Windows operating system.注意 conda 只能在 Windows 操作系统上安装最高版本 2.1.0 的 tensorflow。 If you want tensorflow 2.2.0 or 2.3.0 install it with pip using pip after you have installed 2.1.如果您想要 tensorflow 2.2.0 或 2.3.0,请在安装 2.1 后使用 pip 使用 pip 安装它。 The cuda toolkit and cudnn work with version 2.2 and 2.3. cuda 工具包和 cudnn 适用于 2.2 和 2.3 版。 One other thing.另一件事。 Use python3.7 not 3.8.使用 python3.7 而不是 3.8。 Apparently when you install tensorflow with conda it will not work with 3.8.显然,当您使用 conda 安装 tensorflow 时,它不适用于 3.8。 If you use pip to install tensorflow 2.1 or higher it includes both the cpu and gpu versions however you have to go through a manual processes to install the Cuda Toolkit and cudnn.如果您使用 pip 安装 tensorflow 2.1 或更高版本,它包括 cpu 和 gpu 版本,但是您必须通过手动过程来安装 Cuda Toolkit 和 cudnn。 This includes downloading the files from NVIDIA .这包括从 NVIDIA 下载文件。 You also have to change your PATH environmental variable.您还必须更改 PATH 环境变量。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.