Tensorflow crashes with CUBLAS_STATUS_ALLOC_FAILED

前端 未结 10 1140
醉梦人生
醉梦人生 2020-12-03 00:43

I\'m running tensorflow-gpu on Windows 10 using a simple MINST neural network program. When it tries to run, it encounters a CUBLAS_STATUS_ALLOC_FAILED error. A

相关标签:
10条回答
  • 2020-12-03 01:29

    On windows, currently tensorflow does not allocate all available memory like it says in the documentation, instead you can work around this error by allowing dynamic memory growth as follows:

    tf.Session(config=tf.ConfigProto(allow_growth=True))
    
    0 讨论(0)
  • 2020-12-03 01:31

    The location of the "allow_growth" property of the session config seems to be different now. It's explained here: https://www.tensorflow.org/tutorials/using_gpu

    So currently you'd have to set it like this:

    import tensorflow as tf
    config = tf.ConfigProto()
    config.gpu_options.allow_growth = True
    session = tf.Session(config=config, ...)
    
    0 讨论(0)
  • 2020-12-03 01:50
    THIS CODE WORK FOR ME
    

    tensorflow>=2.0

    import tensorflow as tf
    config = tf.compat.v1.ConfigProto(gpu_options = 
                             tf.compat.v1.GPUOptions(per_process_gpu_memory_fraction=0.8)
    # device_count = {'GPU': 1}
    )
    config.gpu_options.allow_growth = True
    session = tf.compat.v1.Session(config=config)
    tf.compat.v1.keras.backend.set_session(session)
    
    0 讨论(0)
  • 2020-12-03 01:50

    Tensorflow 2.0 alpha

    Allowing GPU memory growth may fix this issue. For Tensorflow 2.0 alpha / nightly there are two methods you can try, to archive this.

    1.)

    import tensorflow as tf
    tf.config.gpu.set_per_process_memory_growth()
    

    2.)

    import tensorflow as tf
    tf.config.gpu.set_per_process_memory_fraction(0.4) # adjust this to the % of VRAM you 
                                                       # want to give to tensorflow.
    

    I suggest you try both, and see if it helps. Source: https://www.tensorflow.org/alpha/guide/using_gpu

    0 讨论(0)
提交回复
热议问题