【问题标题】:No GPU detected in VSCode for tensorflowVSCode 中未检测到用于张量流的 GPU
【发布时间】:2023-02-01 02:41:53
【问题描述】:

我已经为 Ubuntu 22.04 安装了 tensorflow 和 GPU 支持所需的依赖项,如 https://www.tensorflow.org/install/pip 中所述。

我测试了上面教程中提到的检测到 GPU,它检测到我的 Nvidia GTX 1060。但是如果我尝试在 VSCode 中的 GPU 上运行 tensorflow,则检测不到 GPU。

我有一个带有以下代码的 python 脚本test-tf.py

import tensorflow as tf
print(tf.config.list_physical_devices('GPU'))

当我运行它时,我得到以下信息:

[PhysicalDevice(name='/physical_device:GPU:0', device_type='GPU')]

当我在 VSCode 的 .ipynb 文件中运行相同的代码时,我得到:

[]
2022-12-27 18:59:38.079947: I tensorflow/compiler/xla/stream_executor/cuda/cuda_gpu_executor.cc:981] successful NUMA node read from SysFS had negative value (-1), but there must be at least one NUMA node, so returning NUMA node zero
2022-12-27 18:59:38.080624: W tensorflow/compiler/xla/stream_executor/platform/default/dso_loader.cc:64] Could not load dynamic library 'libcudart.so.11.0'; dlerror: libcudart.so.11.0: cannot open shared object file: No such file or directory
2022-12-27 18:59:38.080767: W tensorflow/compiler/xla/stream_executor/platform/default/dso_loader.cc:64] Could not load dynamic library 'libcublas.so.11'; dlerror: libcublas.so.11: cannot open shared object file: No such file or directory
2022-12-27 18:59:38.080843: W tensorflow/compiler/xla/stream_executor/platform/default/dso_loader.cc:64] Could not load dynamic library 'libcublasLt.so.11'; dlerror: libcublasLt.so.11: cannot open shared object file: No such file or directory
2022-12-27 18:59:38.080894: W tensorflow/compiler/xla/stream_executor/platform/default/dso_loader.cc:64] Could not load dynamic library 'libcufft.so.10'; dlerror: libcufft.so.10: cannot open shared object file: No such file or directory
2022-12-27 18:59:38.080940: W tensorflow/compiler/xla/stream_executor/platform/default/dso_loader.cc:64] Could not load dynamic library 'libcurand.so.10'; dlerror: libcurand.so.10: cannot open shared object file: No such file or directory
2022-12-27 18:59:38.080986: W tensorflow/compiler/xla/stream_executor/platform/default/dso_loader.cc:64] Could not load dynamic library 'libcusolver.so.11'; dlerror: libcusolver.so.11: cannot open shared object file: No such file or directory
2022-12-27 18:59:38.081032: W tensorflow/compiler/xla/stream_executor/platform/default/dso_loader.cc:64] Could not load dynamic library 'libcusparse.so.11'; dlerror: libcusparse.so.11: cannot open shared object file: No such file or directory
2022-12-27 18:59:38.081076: W tensorflow/compiler/xla/stream_executor/platform/default/dso_loader.cc:64] Could not load dynamic library 'libcudnn.so.8'; dlerror: libcudnn.so.8: cannot open shared object file: No such file or directory
2022-12-27 18:59:38.081087: W tensorflow/core/common_runtime/gpu/gpu_device.cc:1934] Cannot dlopen some GPU libraries. Please make sure the missing libraries mentioned above are installed properly if you would like to use GPU. Follow the guide at https://www.tensorflow.org/install/gpu for how to download and setup the required libraries for your platform.
Skipping registering GPU devices...

如果我使用 Jupyter Notebook 运行相同的 .ipynb 文件,GPU 会按预期检测到。仅当从 VSCode 使用笔记本时才检测不到。我已确保使用适当的 conda 环境。

【问题讨论】:

  • 请确保 VS 代码和 GPU 设置安装在同一个虚拟环境中以访问 GPU,正如我从上面的代码中看到的那样,可以使用 TensorFlow 访问 GPU。请检查同一链接中 step by step instructions 提到的 GPU 设置部分。尝试从同一个 VirEnv 启动并安装 VS code。附上这个link作为VS设置的参考,这可能对你有帮助。让我们知道问题是否仍然存在。谢谢你。
  • @TFer2,从 conda 环境打开 VSCode 解决了这个问题。谢谢!

标签: python-3.x tensorflow visual-studio-code ubuntu-22.04


【解决方案1】:

我遇到了同样的问题,但执行以下操作解决了我的问题

转到 vscode 中的终端选项卡-> 单击新终端

在左下角单击“+”号附近的下拉按钮,然后单击“设置默认配置文件”并选择“命令提示符”。

现在运行代码。

【讨论】:

    【解决方案2】:

    正如@TFer2 在问题的 cmets 中提到的,您需要从 conda 环境中打开 VSCode,并将 "terminal.integrated.inheritEnv": false 添加到用户 settings.json 中,tensorflow-gpu 才能使用 .ipynb 文件。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-06-07
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-09-15
      相关资源
      最近更新 更多