LoginSignup
5
5

More than 3 years have passed since last update.

CUBLAS_STATUS_ALLOC_FAILEDエラー

Posted at

久しぶりに機械学習の勉強をしようとと思い、多クラス分類の復習をしようとしたら件のエラーが発生しました。

以前はちゃんと動いていたはずですなのですが・・・。

動作環境

OS:Windows10
演算領域:GPU
フレームワーク:Tensorflow
モジュール:keras

エラー内容

model.fit()を呼び出しているところで下記エラーが出てすすまない。

failed to create cublas handle: CUBLAS_STATUS_ALLOC_FAILED

原因

TensorflowがGPUのメモリが確保できず、model.fit()の処理が行えないらしい。

解決方法

TensorflowがGPUのメモリを動的に拡張できるようにコンフィグ設定を追加する。
具体的には下記コードをmodelの処理を実行する前に追加すればよい。
自分の場合はコードの先頭に追加しました。

tf_gpu_config.py
# TensorFlowのGPUメモリ使用量の制限
# https://github.com/tensorflow/tensorflow/issues/7072
import tensorflow as tf
from keras.backend.tensorflow_backend import set_session
config = tf.ConfigProto()
config.gpu_options.allow_growth = True  # dynamically grow the memory used on the GPU
config.log_device_placement = True  # to log device placement (on which device the operation ran)
                                    # (nothing gets printed in Jupyter, only if you run it standalone)
sess = tf.Session(config=config)
set_session(sess)  # set this TensorFlow session as the default session for Keras

参考

最後に

話が変わるけどTensorFlow内で利用されているnumpyでもWarningが発生してました。
float型は非推奨とのこと。
Tensorflowの新しいバージョンでは対応済かもしれませんが、Tensorflowのバージョン上げると、まーたCudaを動かすのにハマりそうだし、この場は趣味で触ってるだけなので放置

5
5
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
5
5