sagemaker-python-sdk icon indicating copy to clipboard operation
sagemaker-python-sdk copied to clipboard

Sagemaker Tensorflow_p36 kernel notebook not using GPU

Open Kuntal-G opened this issue 8 years ago • 30 comments

System Information

  • Framework (e.g. TensorFlow) / Algorithm (e.g. KMeans): Tensorflow
  • Framework Version: NA
  • Python Version: 3.6.6
  • CPU or GPU: GPU (ml.p2.8xlarge)
  • Python SDK Version: NA
  • Are you using a custom image:NA

Describe the problem

I'm running Sagemaker notebook (ml.p2.8xlarge) and checking the number of GPU's available before running my Tensorflow code. But when I checked the available devices from tensorflow and keras, it was not showing any GPU information, only CPU information is getting printed.

Using nvidia-smi from the notebook or shell in sagemaker was printing the GPUS properly. Also using pytorch environment and using to check GPUS is working fine- torch.cuda.get_device_name(0)

Now after I upgrade the tensorflow with conda from the notebook and then restarting the notebook instance solved the problem with Tensorflow and GPU information is working fine.

Now my questions are:

  1. Is Sagemaker notebook/platform not tested well with tensorflow gpu settings properly, so that by default the notebook works properly with GPU without manual upgrade or uninstall/install of tensorflow-gpu package?

  2. Am I making anything wrong, because I launched a new Sagemaker notebook instance,so its the latest that AWS is providing now?

  3. Also why the log device placement information from the tensorflow is not getting printed in the sagemaker notebook? tf.Session(config=tf.ConfigProto(log_device_placement=True))

  • Exact command to reproduce: Error/Issue before manual conda install/upgrade
import tensorflow as tf
tf.__version__

Output '1.10.0'


from tensorflow.python.client import device_lib
device_lib.list_local_devices()

Output [name: "/device:CPU:0" device_type: "CPU" memory_limit: 268435456 locality { }


After conda upgrade in the notebook- !y|conda install tensorflow-gpu

import tensorflow as tf
tf.__version__

Output: '1.11.0'

from tensorflow.python.client import device_lib
device_lib.list_local_devices()

Output

[name: "/device:CPU:0" device_type: "CPU" memory_limit: 268435456 locality { } incarnation: 13414246756793993509, name: "/device:GPU:0" device_type: "GPU" memory_limit: 11279561524 locality { bus_id: 1 links { link { device_id: 1 type: "StreamExecutor" strength: 1 } link { device_id: 2 type: "StreamExecutor" strength: 1 } link { device_id: 3 type: "StreamExecutor" strength: 1 } link { device_id: 4 type: "StreamExecutor" strength: 1 } link { device_id: 5 type: "StreamExecutor" strength: 1 } link { device_id: 6 type: "StreamExecutor" strength: 1 } link { device_id: 7 type: "StreamExecutor" strength: 1 } } } incarnation: 9978466201706397067 physical_device_desc: "device: 0, name: Tesla K80, pci bus id: 0000:00:17.0, compute capability: 3.7", name: "/device:GPU:1" device_type: "GPU" memory_limit: 11279561524 locality { bus_id: 1 links { link { type: "StreamExecutor" strength: 1 } . . .


Validated the GPU before and after upgrade with nvidia-smi as well. !nvidia-smi -l

Kuntal-G avatar Nov 13 '18 16:11 Kuntal-G

Same for me, I only can make GPU work in Sagemaker notebook if I install separate env with keras-gpu or tensorflow-gpu.

ghost avatar Jul 26 '19 13:07 ghost

@devforfu thanks for trying this out! Really appreciate your help in debugging this issue. Can you try the same with the conda_tensorflow_p36 kernel? The *amazonei* kernels are specific to the Elastic Inference-enabled notebook instances, which might have unintended effects if you're not using one.

mckev-amazon avatar Jul 26 '19 19:07 mckev-amazon

@mckev-amazon Yeah, you're totally right. The conda_tensorflow_p36 seems to properly use GPU right out of the box, without any additional changes. I had to do a more proper investigation before creating a custom environment.

gpu_utilization

i-zaitsev avatar Jul 30 '19 14:07 i-zaitsev

Would anyone here mind posting a quick summary of what is and isn't working when it comes to SageMaker and Tensorflow on GPU?

m1sta avatar Aug 01 '19 05:08 m1sta

@mckev-amazon its working.

ghost avatar Aug 01 '19 05:08 ghost

@jazzman37 and @devforfu great to hear! If you continue to have issues with GPU on SageMaker notebooks, please open a new issue as the original issue reported has been resolved.

Thanks for using SageMaker!

mckev-amazon avatar Aug 02 '19 03:08 mckev-amazon

I am having a similar issue. I opened: #1346

nectario avatar Mar 10 '20 17:03 nectario

@devforfu thanks for trying this out! Really appreciate your help in debugging this issue. Can you try the same with the conda_tensorflow_p36 kernel? The *amazonei* kernels are specific to the Elastic Inference-enabled notebook instances, which might have unintended effects if you're not using one.

So how do I enable GPU using amazonei?

nectario avatar Mar 10 '20 17:03 nectario

Hi nectario,

You can find a tutorial here: https://docs.aws.amazon.com/sagemaker/latest/dg/ei.html

dleen avatar Mar 20 '20 23:03 dleen

I may be having the same problem but I'm not sure. When I train my model using Google Colab, I complete one epoch every 45 minutes. Now I am using the same code in a Sagemaker notebook (just training on the local notebook). I am using a ml.p2.xlarge instance which comes with a GPU, and I have followed the above instructions to make sure that Keras sees a gpu. However, my model is training extremely slowly: it takes over 5.5 hours to train one epoch! I am not sure if AWS just gave me a super slow GPU, or if my GPU is not being used during the training.

I ran this code: tf.config.experimental.list_physical_devices('GPU')

and my output was: [PhysicalDevice(name='/physical_device:GPU:0', device_type='GPU')]

Does that mean my GPU is currently in use, and it is just really slow? Thank you for your help.

Tylersuard avatar Jul 08 '21 18:07 Tylersuard