LoginSignup
2
0

More than 5 years have passed since last update.

g2.2xlargeでtensorflow-gpuは動作しない(2018年7月時点)

Last updated at Posted at 2018-07-24

はじめに

以前からAWS上でTensorFlowをGPUで動作させることに興味があったので、g2.2xlargeのセッションを開設して試してみました。
結論からいうと、g2.2xlarge上でtensorflow-gpuを動作させることはできません(2018年7月時点)。結局のところ、p2.xlargeを新たに開設してやっと動作確認することができました。

g2.2xlargeの開設

AWSのデフォルトユーザー設定では、g2.2xlarge等の高機能セッションの開設数に制限がかかっているので、それを解放しないといけません。解放の仕方は、AWSのサポートセンターのページで直接担当者にメッセージを送る形です。

AWSサポートセンター.png

1日程度で制限が解除され、g2.2xlargeが使えるようになります。

AWS上限値変更.png

DeepLearningAMI

AWSいはく、TensorFlowやChainerが既にインストールされたセッションが用意されているので、それを選択します。

DeeplearningAMIで選択できる環境一覧
=============================================================================
       __|  __|_  )
       _|  (     /   Deep Learning AMI 11.0 (Amazon Linux)
      ___|\___|___|
=============================================================================

Please use one of the following commands to start the required environment with the framework of your choice:
for MXNet(+Keras1) with Python3 (CUDA 9.0 and Intel MKL-DNN) _______________________________ source activate mxnet_p36
for MXNet(+Keras1) with Python2 (CUDA 9.0 and Intel MKL-DNN) _______________________________ source activate mxnet_p27
for TensorFlow(+Keras2) with Python3 (CUDA 9.0 and Intel MKL-DNN) _____________________ source activate tensorflow_p36
for TensorFlow(+Keras2) with Python2 (CUDA 9.0 and Intel MKL-DNN) _____________________ source activate tensorflow_p27
for Theano(+Keras2) with Python3 (CUDA 9.0) _______________________________________________ source activate theano_p36
for Theano(+Keras2) with Python2 (CUDA 9.0) _______________________________________________ source activate theano_p27
for PyTorch with Python3 (CUDA 9.0 and Intel MKL) ________________________________________ source activate pytorch_p36
for PyTorch with Python2 (CUDA 9.0 and Intel MKL) ________________________________________ source activate pytorch_p27
for CNTK(+Keras2) with Python3 (CUDA 9.0 and Intel MKL-DNN) _________________________________ source activate cntk_p36
for CNTK(+Keras2) with Python2 (CUDA 9.0 and Intel MKL-DNN) _________________________________ source activate cntk_p27
for Caffe2 with Python2 (CUDA 9.0) ________________________________________________________ source activate caffe2_p27
for Caffe with Python2 (CUDA 8.0) __________________________________________________________ source activate caffe_p27
for Caffe with Python3 (CUDA 8.0) __________________________________________________________ source activate caffe_p35
for Chainer with Python2 (CUDA 9.0 and Intel iDeep) ______________________________________ source activate chainer_p27
for Chainer with Python3 (CUDA 9.0 and Intel iDeep) ______________________________________ source activate chainer_p36
for base Python2 (CUDA 9.0) __________________________________________________________________ source activate python2
for base Python3 (CUDA 9.0) __________________________________________________________________ source activate python3

tensorflow-gpuのエラーメッセージ

TensorFlowのインポートでのエラー

プレインストールされているtensorflowでは、エラーメッセージが出てきて、Pythonからのインポートができません。結局、このエラーの回避方法はわからずじまいでした。

TensorFlowのインポートで出てくるエラー
>>> import tensorflow as tf
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/home/ec2-user/anaconda3/envs/tensorflow_p36/lib/python3.6/site-packages/tensorflow/__init__.py", line 22, in <module>
    from tensorflow.python import pywrap_tensorflow  # pylint: disable=unused-import
  File "/home/ec2-user/anaconda3/envs/tensorflow_p36/lib/python3.6/site-packages/tensorflow/python/__init__.py", line 81, in <module>
    from tensorflow.python import keras
  File "/home/ec2-user/anaconda3/envs/tensorflow_p36/lib/python3.6/site-packages/tensorflow/python/keras/__init__.py", line 24, in <module>
    from tensorflow.python.keras import activations
  File "/home/ec2-user/anaconda3/envs/tensorflow_p36/lib/python3.6/site-packages/tensorflow/python/keras/activations/__init__.py", line 22, in <module>
    from tensorflow.python.keras._impl.keras.activations import elu
  File "/home/ec2-user/anaconda3/envs/tensorflow_p36/lib/python3.6/site-packages/tensorflow/python/keras/_impl/keras/__init__.py", line 21, in <module>
    from tensorflow.python.keras._impl.keras import activations
  File "/home/ec2-user/anaconda3/envs/tensorflow_p36/lib/python3.6/site-packages/tensorflow/python/keras/_impl/keras/activations.py", line 23, in <module>
    from tensorflow.python.keras._impl.keras import backend as K
  File "/home/ec2-user/anaconda3/envs/tensorflow_p36/lib/python3.6/site-packages/tensorflow/python/keras/_impl/keras/backend.py", line 38, in <module>
    from tensorflow.python.layers import base as tf_base_layers
  File "/home/ec2-user/anaconda3/envs/tensorflow_p36/lib/python3.6/site-packages/tensorflow/python/layers/base.py", line 25, in <module>
    from tensorflow.python.keras.engine import base_layer
  File "/home/ec2-user/anaconda3/envs/tensorflow_p36/lib/python3.6/site-packages/tensorflow/python/keras/engine/__init__.py", line 21, in <module>
    from tensorflow.python.keras.engine.base_layer import InputSpec
  File "/home/ec2-user/anaconda3/envs/tensorflow_p36/lib/python3.6/site-packages/tensorflow/python/keras/engine/base_layer.py", line 33, in <module>
    from tensorflow.python.keras import backend
  File "/home/ec2-user/anaconda3/envs/tensorflow_p36/lib/python3.6/site-packages/tensorflow/python/keras/backend/__init__.py", line 22, in <module>
    from tensorflow.python.keras._impl.keras.backend import abs
ImportError: cannot import name 'abs

CUDAのみを利用

CUDAのみがインストールされている仮想環境があったので、そこにtensorflow-gpuをダウンロードしたら、TensorFlowのインポートはすることができました。
しかし、確認してみると、どうやらGPUは認識していないようです。

g2.2xlarge上で認識されているCPU&GPU
>>> from tensorflow.python.client import device_lib
>>> device_lib.list_local_devices()
[name: "/device:CPU:0"
device_type: "CPU"
memory_limit: 268435456
locality {
}
incarnation: 6183111557610762570
]
>>> 

調べてみると、tensorflow-gpuが、CUDAが定義する計算性能(CudaComputeCapability)が3.5以上であるGPUしか認識しないことが原因のようでした。g2.2xlargeが搭載しているGPUのCudaComputeCapabilityは3.0であるようなので、どうしようもありません。

p2.xlargeのGPUであれば問題なく認識

上記問題を解決することができなかったため、p2.xlargeのセッションを用意しました。p2.xlargeであれば、tensorflow-gpuは問題なくGPUを認識します。

p2.xlarge上で認識されているCPU&GPU
>>> from tensorflow.python.client import device_lib
/home/ubuntu/anaconda3/envs/tensorflow_p36/lib/python3.6/site-packages/h5py/__init__.py:36: FutureWarning: Conversion of the second argument of issubdtype from `float` to `np.floating` is deprecated. In future, it will be treated as `np.float64 == np.dtype(float).type`.
  from ._conv import register_converters as _register_converters
>>> device_lib.list_local_devices()
2018-07-24 11:40:25.235809: I tensorflow/stream_executor/cuda/cuda_gpu_executor.cc:898] successful NUMA node read from SysFS had negative value (-1), but there must be at least one NUMA node, so returning NUMA node zero
2018-07-24 11:40:25.236201: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1356] Found device 0 with properties: 
name: Tesla K80 major: 3 minor: 7 memoryClockRate(GHz): 0.8235
pciBusID: 0000:00:1e.0
totalMemory: 11.17GiB freeMemory: 11.10GiB
2018-07-24 11:40:25.236228: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1435] Adding visible gpu devices: 0
2018-07-24 11:40:26.481888: I tensorflow/core/common_runtime/gpu/gpu_device.cc:923] Device interconnect StreamExecutor with strength 1 edge matrix:
2018-07-24 11:40:26.481937: I tensorflow/core/common_runtime/gpu/gpu_device.cc:929]      0 
2018-07-24 11:40:26.481958: I tensorflow/core/common_runtime/gpu/gpu_device.cc:942] 0:   N 
2018-07-24 11:40:26.484813: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1053] Created TensorFlow device (/device:GPU:0 with 10763 MB memory) -> physical GPU (device: 0, name: Tesla K80, pci bus id: 0000:00:1e.0, compute capability: 3.7)
[name: "/device:CPU:0"
device_type: "CPU"
memory_limit: 268435456
locality {
}
incarnation: 5961224172411216964
, name: "/device:GPU:0"
device_type: "GPU"
memory_limit: 11286285517
locality {
  bus_id: 1
  links {
  }
}
incarnation: 4981542486696783358
physical_device_desc: "device: 0, name: Tesla K80, pci bus id: 0000:00:1e.0, compute capability: 3.7"
]

p2.xlargeが搭載しているGPU(Tesla K80)のCudaComputeCapabilityは3.7あるようです。g2.2xlargeとp2.xlargeの利用料はそれほど変わらないので、手こずるようであればg2.2xlargeには見切りをつけた方がいいでしょう。

2
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2
0