Google-colaboratory:没有可用的 GPU 后端

Google-colaboratory: No backend with GPU available

Here描述了如何使用gpu与google-colaboratory:

Simply select "GPU" in the Accelerator drop-down in Notebook Settings (either through the Edit menu or the command palette at cmd/ctrl-shift-P).

然而,当我在笔记本设置中 select gpu 时,我得到一个弹出窗口说:

Failed to assign a backend No backend with GPU available. Would you like to use a runtime with no accelerator?

当我运行:

import tensorflow as tf
device_name = tf.test.gpu_device_name()
if device_name != '/device:GPU:0':
    raise SystemError('GPU device not found')
print('Found GPU at: {}'.format(device_name))

当然,我得到GPU device not found。似乎描述不完整。知道需要做什么吗?

您需要稍后在 GPU 可用时重试。该消息表明所有可用的 GPU 都在使用中。

FAQ 提供了额外的信息:

How may I use GPUs and why are they sometimes unavailable?

Colaboratory is intended for interactive use. Long-running background computations, particularly on GPUs, may be stopped. Please do not use Colaboratory for cryptocurrency mining. Doing so is unsupported and may result in service unavailability. We encourage users who wish to run continuous or long-running computations through Colaboratory’s UI to use a local runtime.

使用 GPU 进行持续训练似乎有冷却时间。所以,如果遇到错误对话框,请稍后再试,或许可以尝试在后续会话中限制长期训练。

您需要为笔记本配置 GPU 设备

点击编辑->笔记本设置->硬件加速器->GPU

Reset runtime没用后,我做了:

Runtime -> Reset all runtimes -> Yes

然后我就开心了:

Found GPU at: /device:GPU:0

加几张图更清楚

我的声望有点低,无法发表评论,但这里有一些关于@Bob Smith 的冷却时间回答的额外信息。

There seems to be a cooldown on continuous training with GPUs. So, if you encounter the error dialog, try again later, and perhaps try to limit long-term training in subsequent sessions.

根据我自己最近的经验,我相信 Colab 最多会给你分配 12 小时的 GPU 使用时间,之后大约有 8 小时的冷却时间,然后你才能再次使用计算资源。就我而言,即使没有 GPU,我也无法连接到实例。接下来我不太确定,但我认为如果你 运行 一次说 3 个实例,你的 12 小时会以 3 倍的速度耗尽。我不知道 12 小时限制会在多长时间后重置,但我猜可能是一天。

无论如何,仍然缺少一些细节,但主要的收获是,如果你超过了你的限制,你将被锁定在 8 小时内无法连接到实例(如果你是积极致力于某事)。

Google Colab默认有tensorflow 2.0,改成tensorflow 1。添加代码,

%tensorflow_version 1.x 在任何 keras 或 tensorflow 代码之前使用它。

这是对你问题的准确回答,伙计。 根据来自 Colab 的 post:

overall usage limits, as well as idle timeout periods, maximum VM lifetime, GPU types available, and other factors, vary over time.

GPUs and TPUs are sometimes prioritized for users who use Colab interactively rather than for long-running computations, or for users who have recently used less resources in Colab. As a result, users who use Colab for long-running computations, or users who have recently used more resources in Colab, are more likely to run into usage limits and have their access to GPUs and TPUs temporarily restricted. Users with high computational needs may be interested in using Colab’s UI with a local runtime running on their own hardware.