pytorch 为什么GPU可以使用'torch'而不能使用'tensorflow'

oipij1gg  于 6个月前  发布在  其他
关注(0)|答案(1)|浏览(78)

我试图将我的GPU卡应用到TensorFlow笔记本电脑中,但我遇到了torch
我有以下设置:

(myen2v) C:\Users\Jan>conda list cudnn
# packages in environment at D:\BitDownlD\Anaconda8\envs\myen2v:
#
# Name                    Version                   Build  Channel
cudnn                     8.9.2.26               cuda11_0    anaconda

(myen2v) C:\Users\Jan>conda list cuda
# packages in environment at D:\BitDownlD\Anaconda8\envs\myen2v:
#
# Name                    Version                   Build  Channel
cudatoolkit               11.8.0               hd77b12b_0

(myen2v) C:\Users\Jan>conda list torch
# packages in environment at D:\BitDownlD\Anaconda8\envs\myen2v:
#
# Name                    Version                   Build  Channel
pytorch                   2.0.1           cpu_py38hb0bdfb8_0
torch                     2.1.0                    pypi_0    pypi

(myen2v) C:\Users\Jan>conda list tensor
# packages in environment at D:\BitDownlD\Anaconda8\envs\myen2v:
#
# Name                    Version                   Build  Channel
tensorboard               2.13.0                   pypi_0    pypi
tensorboard-data-server   0.7.1                    pypi_0    pypi
tensorboard-plugin-wit    1.8.1            py38haa95532_0
tensorflow                2.13.0                   pypi_0    pypi
tensorflow-base           2.3.0           eigen_py38h75a453f_0
tensorflow-estimator      2.13.0                   pypi_0    pypi
tensorflow-gpu            2.3.0                    pypi_0    pypi
tensorflow-gpu-estimator  2.3.0                    pypi_0    pypi
tensorflow-io-gcs-filesystem 0.31.0                   pypi_0    pypi

字符串
我可以运行这个代码:

# Create tensors on GPU
a = torch.tensor([1, 2, 3], device="cuda")
b = torch.tensor([4, 5, 6], device="cuda")

# Perform operations on GPU
c = a + b
print(c)
tensor([5, 7, 9], device='cuda:0')

的数据
但我无法运行下面的代码:

import tensorflow as tf

physical_devices = tf.config.list_physical_devices('GPU')
print("Num GPUs:", len(physical_devices))


我收到这个错误:

---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
Cell In[12], line 1
----> 1 physical_devices = tf.config.list_physical_devices('GPU')
      2 print("Num GPUs:", len(physical_devices))

AttributeError: module 'tensorflow' has no attribute 'config'


连这个也不行

import tensorflow as tf
print("Num of GPUs available: ", len(tf.test.gpu_device_name()))
--------------------------------------------------------------------------- AttributeError                            Traceback (most recent call
> last) Cell In[13], line 2
>       1 import tensorflow as tf
> ----> 2 print("Num of GPUs available: ", len(tf.test.gpu_device_name()))
> 
> AttributeError: module 'tensorflow' has no attribute 'test'

的字符串

a11xaf1n

a11xaf1n1#

这不太可能与CUDA有关,更有可能与tensorflow安装的坏版本有关。先了解一些基础知识:

import tensorflow as tf
print(tf.__version__)

字符串
确保你看到的和

$ pip show tensorflow

相关问题