So as of 2022-04, the tensorflow package contains both CPU and GPU builds. To install a GPU build, search to see what's available:
λ conda search tensorflow Loading channels: done # Name Version Build Channel tensorflow 0.12.1 py35_1 conda-forge tensorflow 0.12.1 py35_2 conda-forge tensorflow 1.0.0 py35_0 conda-forge … tensorflow 2.5.0 mkl_py39h1fa1df6_0 pkgs/main tensorflow 2.6.0 eigen_py37h37bbdb1_0 pkgs/main tensorflow 2.6.0 eigen_py38h63d3545_0 pkgs/main tensorflow 2.6.0 eigen_py39h855417c_0 pkgs/main tensorflow 2.6.0 gpu_py37h3e8f0e3_0 pkgs/main tensorflow 2.6.0 gpu_py38hc0e8100_0 pkgs/main tensorflow 2.6.0 gpu_py39he88c5ba_0 pkgs/main tensorflow 2.6.0 mkl_py37h9623b36_0 pkgs/main tensorflow 2.6.0 mkl_py38hdc16138_0 pkgs/main tensorflow 2.6.0 mkl_py39h31650da_0 pkgs/main
You can see that there are builds of TF 2.6.0 that support Python 3.7, 3.8 and 3.9, and that are built for MKL (Intel CPU), Eigen, or GPU.
To narrow it down, you can use wildcards in the search. This will find any Tensorflow 2.x version that is built for GPU, for instance:
λ conda search tensorflow=2*=gpu* Loading channels: done # Name Version Build Channel tensorflow 2.0.0 gpu_py36hfdd5754_0 pkgs/main tensorflow 2.0.0 gpu_py37h57d29ca_0 pkgs/main tensorflow 2.1.0 gpu_py36h3346743_0 pkgs/main tensorflow 2.1.0 gpu_py37h7db9008_0 pkgs/main tensorflow 2.5.0 gpu_py37h23de114_0 pkgs/main tensorflow 2.5.0 gpu_py38h8e8c102_0 pkgs/main tensorflow 2.5.0 gpu_py39h7dc34a2_0 pkgs/main tensorflow 2.6.0 gpu_py37h3e8f0e3_0 pkgs/main tensorflow 2.6.0 gpu_py38hc0e8100_0 pkgs/main tensorflow 2.6.0 gpu_py39he88c5ba_0 pkgs/main
To install a specific version in an otherwise empty environment, you can use a command like:
λ conda activate tf (tf) λ conda install tensorflow=2.6.0=gpu_py39he88c5ba_0 … The following NEW packages will be INSTALLED: _tflow_select pkgs/main/win-64::_tflow_select-2.1.0-gpu … cudatoolkit pkgs/main/win-64::cudatoolkit-11.3.1-h59b6b97_2 cudnn pkgs/main/win-64::cudnn-8.2.1-cuda11.3_0 … tensorflow pkgs/main/win-64::tensorflow-2.6.0-gpu_py39he88c5ba_0 tensorflow-base pkgs/main/win-64::tensorflow-base-2.6.0-gpu_py39hb3da07e_0 …
As you can see, if you install a GPU build, it will automatically also install compatible cudatoolkit and cudnn packages. You don't need to manually check versions for compatibility, or manually download several gigabytes from Nvidia's website, or register as a developer, as it says in other answers or on the official website.
After installation, confirm that it worked and it sees the GPU by running:
λ python Python 3.9.12 (main, Apr 4 2022, 05:22:27) [MSC v.1916 64 bit (AMD64)] :: Anaconda, Inc. on win32 Type "help", "copyright", "credits" or "license" for more information. >>> import tensorflow as tf >>> tf.__version__ '2.6.0' >>> tf.config.list_physical_devices() [PhysicalDevice(name='/physical_device:CPU:0', device_type='CPU'), PhysicalDevice(name='/physical_device:GPU:0', device_type='GPU')]
Getting conda to install a GPU build and other packages you want to use is another story, however, because there are a lot of package incompatibilities for me. I think the best you can do is specify the installation criteria using wildcards and cross your fingers.
This tries to install any TF 2.x version that's built for GPU and that has dependencies compatible with Spyder and matplotlib's dependencies, for instance:
λ conda install tensorflow=2*=gpu* spyder matplotlib
For me, this ended up installing a two year old GPU version of tensorflow:
matplotlib pkgs/main/win-64::matplotlib-3.5.1-py37haa95532_1 spyder pkgs/main/win-64::spyder-5.1.5-py37haa95532_1 tensorflow pkgs/main/win-64::tensorflow-2.1.0-gpu_py37h7db9008_0
I had previously been using the tensorflow-gpu package, but that doesn't work anymore. conda typically grinds forever trying to find compatible packages to install, and even when it's installed, it doesn't actually install a gpu build of tensorflow or the CUDA dependencies:
λ conda list … cookiecutter 1.7.2 pyhd3eb1b0_0 cryptography 3.4.8 py38h71e12ea_0 cycler 0.11.0 pyhd3eb1b0_0 dataclasses 0.8 pyh6d0b6a4_7 … tensorflow 2.3.0 mkl_py38h8557ec7_0 tensorflow-base 2.3.0 eigen_py38h75a453f_0 tensorflow-estimator 2.6.0 pyh7b7c402_0 tensorflow-gpu 2.3.0 he13fc11_0
pip install tensorflow-gpu) 2. Are there any log messages about loading the CUDA libraries the first time you create atf.Session?tensorflow-gpudoesn't actually install a GPU build anymore. Mine installed a MKL build, for instance. You have to specify a GPU build of thetensorflowpackage instead. stackoverflow.com/a/71809780/125507