简体   繁体   English

如何在 AWS EC2 实例上激活 GPU 的使用?

[英]How to activate the use of a GPU on AWS EC2 instance?

I am using AWS to train a CNN on a custom dataset.我正在使用 AWS 在自定义数据集上训练 CNN。 I launched a p2.xlarge instance, uploaded my (Python) scripts to the virtual machine, and I am running my code via the CLI.我启动了一个 p2.xlarge 实例,将我的 (Python) 脚本上传到虚拟机,然后通过 CLI 运行我的代码。

I activated a virtual environment for TensorFlow(+Keras2) with Python3 (CUDA 10.0 and Intel MKL-DNN), which was a default option via AWS.我使用 Python3(CUDA 10.0 和英特尔 MKL-DNN)激活了 TensorFlow(+Keras2) 的虚拟环境,这是 AWS 的默认选项。

I am now running my code to train the.network, but it feels like the GPU is not 'activated'.我现在正在运行我的代码来训练 .network,但感觉 GPU 没有“激活”。 The training goes just as fast (slow) as when I run it locally with a CPU.训练进行得和我在本地用 CPU 运行时一样快(慢)。

This is the script that I am running:这是我正在运行的脚本:

https://github.com/AntonMu/TrainYourOwnYOLO/blob/master/2_Training/Train_YOLO.py https://github.com/AntonMu/TrainYourOwnYOLO/blob/master/2_Training/Train_YOLO.py

I also tried to alter it by putting with tf.device('/device:GPU: 0'): after the parser (line 142) and indenting everything underneath under there.我还尝试通过在解析器(第 142 行)之后放置with tf.device('/device:GPU: 0'):并缩进下面的所有内容来更改它。 However, this doesn't seem to have changed anything.然而,这似乎并没有改变什么。

Any tips on how to activate the GPU (or check if the GPU is activated)?关于如何激活 GPU 的任何提示(或检查 GPU 是否已激活)?

Checkout this answer for listing available GPUs.查看此答案以列出可用的 GPU。

from tensorflow.python.client import device_lib

def get_available_gpus():
    local_device_protos = device_lib.list_local_devices()
    return [x.name for x in local_device_protos if x.device_type == 'GPU']

You can also use CUDA to list the current device and, if necessary,set the device .您还可以使用 CUDA 列出当前设备,并在必要时设置设备

import torch

print(torch.cuda.is_available())
print(torch.cuda.current_device())

In the end it had to do with my tensorflow package. I had to uninstall tensorflow and install tensorflow-gpu.最后还是和我的tensorflow package有关,只好卸载tensorflow,安装tensorflow-gpu。 After that the GPU was automatically activated.之后 GPU 自动激活。

For documentation see: https://www.tensorflow.org/install/gpu有关文档,请参阅: https://www.tensorflow.org/install/gpu

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM