Search code examples
python-3.xtensorflowamazon-ec2gpu

How to get AWS GPU instance details using Python-tensorflow


I created an AWS GPU instance with g4dn.xlarge instance type.

I installed Python and Jupyter-notebook as well.

When I am trying to load the GPU details in the Jupyter notebook with the below code:

import tensorflow as tf
tf.config.list_physical_devices()

Output:

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

I tried few other methods as well

1

import tensorflow as tf

gpus = tf.config.list_physical_devices('GPU')
for gpu in gpus:
    print("Name:", gpu.name, "  Type:", gpu.device_type)

2

from tensorflow.python.client import device_lib

device_lib.list_local_devices()

3

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']

get_available_gpus()

All the codes will respond with no GPU.

what could be the possible options to access the GPU?


Solution

  • Since you said you installed Python yourself, it's likely you didn't start with a deep learning AMI with all the drivers installed, so you'd have to install Nvidia drivers, CUDA, and cudnn. But trying to install Nvidia drivers on an AWS EC2 instance can be tough...

    Solution: start with the deep learning AMIs:

    https://aws.amazon.com/machine-learning/amis/