无法将 Google Colab 上的 GPU 用于 tensorflow 2.0

Alw*_*ind 4 python tensorflow google-colaboratory tensorflow2.0

我正在尝试使用 Google Colab 上的 GPU 运行我的笔记本,但它没有为我提供 GPU,但是当我使用 tensorflow 1.15.0 运行笔记本时,GPU 可用。

tf.test.gpu_device_name()
Run Code Online (Sandbox Code Playgroud)

给出'/device:GPU:0' tensorflow 1.15.0的输出

但是当我对 tensorflow 2.0.0 做同样的事情时,函数返回''.

小智 7

我解决了在 google colab 中安装的问题

!pip install tensorflow-gpu 
Run Code Online (Sandbox Code Playgroud)

!pip install tf-nightly 
Run Code Online (Sandbox Code Playgroud)

所以现在 tf.test.gpu_device_name(),输出为/device:GPU:0 But,TensorFlow 自动将其版本升级为2.1.0-dev20191120


小智 5

尝试

%tensorflow_version 2.x

import tensorflow as tf
print(tf.__version__)
print(tf.test.gpu_device_name())
print("Num GPUs Available: ", len(tf.config.experimental.list_physical_devices('GPU')))
Run Code Online (Sandbox Code Playgroud)