就我而言,我打开了2个python控制台,都使用keras / tensorflow。当我关闭旧控制台(前一天忘记了)时,一切开始正常工作。
因此,最好检查一下是否没有多个控制台/进程占用GPU。
0
就我而言,我打开了2个python控制台,都使用keras / tensorflow。当我关闭旧控制台(前一天忘记了)时,一切开始正常工作。
因此,最好检查一下是否没有多个控制台/进程占用GPU。
0
我遇到了此问题,并通过设置allow_soft_placement=True
和gpu_options = tf.GPUOptions(per_process_gpu_memory_fraction=0.3)
,该问题专门定义了已使用的GPU内存gpu_options = tf.GPUOptions(per_process_gpu_memory_fraction=0.3)
。我想这有助于避免两个张量流进程争夺GPU内存。
gpu_options = tf.GPUOptions(per_process_gpu_memory_fraction=0.3)
sess = tf.Session(config=tf.ConfigProto(
allow_soft_placement=True, log_device_placement=True))
0
运行Tensorflow Distributed时出现此错误。您是否检查了是否有任何工人正在报告CUDA_OUT_OF_MEMORY错误?如果是这种情况,则可能与放置权重和偏差变量的位置有关。例如
with tf.device("/job:paramserver/task:0/cpu:0"):
W = weight_variable([input_units, num_hidden_units])
b = bias_variable([num_hidden_units])
0
我的环境是Python 3.5,Tensorflow 0.12和Windows 10(无Docker)。我正在用CPU和GPU训练神经网络。我遇到相同的错误InternalError: Blas SGEMM launch failed
每当在GPU中进行训练时, InternalError: Blas SGEMM launch failed
都会InternalError: Blas SGEMM launch failed
。
我找不到发生此错误的原因,但是我通过避免tensorflow函数tensorflow.contrib.slim.one_hot_encoding()
设法在GPU中运行代码。相反,我在numpy(输入和输出变量)中进行了一次热编码操作。
以下代码重现该错误和修复程序。这是使用梯度下降学习y = x ** 2
函数的最小设置。
import numpy as np
import tensorflow as tf
import tensorflow.contrib.slim as slim
def test_one_hot_encoding_using_tf():
# This function raises the "InternalError: Blas SGEMM launch failed" when run in the GPU
# Initialize
tf.reset_default_graph()
input_size = 10
output_size = 100
input_holder = tf.placeholder(shape=[1], dtype=tf.int32, name='input')
output_holder = tf.placeholder(shape=[1], dtype=tf.int32, name='output')
# Define network
input_oh = slim.one_hot_encoding(input_holder, input_size)
output_oh = slim.one_hot_encoding(output_holder, output_size)
W1 = tf.Variable(tf.random_uniform([input_size, output_size], 0, 0.01))
output_v = tf.matmul(input_oh, W1)
output_v = tf.reshape(output_v, [-1])
# Define updates
loss = tf.reduce_sum(tf.square(output_oh - output_v))
trainer = tf.train.GradientDescentOptimizer(learning_rate=0.1)
update_model = trainer.minimize(loss)
# Optimize
init = tf.initialize_all_variables()
steps = 1000
# Force CPU/GPU
config = tf.ConfigProto(
# device_count={'GPU': 0} # uncomment this line to force CPU
)
# Launch the tensorflow graph
with tf.Session(config=config) as sess:
sess.run(init)
for step_i in range(steps):
# Get sample
x = np.random.randint(0, 10)
y = np.power(x, 2).astype('int32')
# Update
_, l = sess.run([update_model, loss], feed_dict={input_holder: [x], output_holder: [y]})
# Check model
print('Final loss: %f' % l)
def test_one_hot_encoding_no_tf():
# This function does not raise the "InternalError: Blas SGEMM launch failed" when run in the GPU
def oh_encoding(label, num_classes):
return np.identity(num_classes)[label:label + 1].astype('int32')
# Initialize
tf.reset_default_graph()
input_size = 10
output_size = 100
input_holder = tf.placeholder(shape=[1, input_size], dtype=tf.float32, name='input')
output_holder = tf.placeholder(shape=[1, output_size], dtype=tf.float32, name='output')
# Define network
W1 = tf.Variable(tf.random_uniform([input_size, output_size], 0, 0.01))
output_v = tf.matmul(input_holder, W1)
output_v = tf.reshape(output_v, [-1])
# Define updates
loss = tf.reduce_sum(tf.square(output_holder - output_v))
trainer = tf.train.GradientDescentOptimizer(learning_rate=0.1)
update_model = trainer.minimize(loss)
# Optimize
init = tf.initialize_all_variables()
steps = 1000
# Force CPU/GPU
config = tf.ConfigProto(
# device_count={'GPU': 0} # uncomment this line to force CPU
)
# Launch the tensorflow graph
with tf.Session(config=config) as sess:
sess.run(init)
for step_i in range(steps):
# Get sample
x = np.random.randint(0, 10)
y = np.power(x, 2).astype('int32')
# One hot encoding
x = oh_encoding(x, 10)
y = oh_encoding(y, 100)
# Update
_, l = sess.run([update_model, loss], feed_dict={input_holder: x, output_holder: y})
# Check model
print('Final loss: %f' % l)
0
我关闭了所有其他正在运行的Jupyter Session,这解决了问题。我认为这是GPU内存问题。
0
如果您使用的是Linux,则可能无法完全释放gpu,请尝试使用“ ps -ef | grep python”查看使用GPU的作业。然后杀死他们
0
旧问题,但可能会帮助其他人。
尝试关闭在其他进程中处于活动状态的交互式会话(如果使用IPython Notebook-只需重新启动内核)。这对我有帮助!
此外,在实验过程中,我使用以下代码关闭了该内核中的本地会话:
if 'session' in locals() and session is not None:
print('Close interactive session')
session.close()
0
当我运行
sess.run(train_step, feed_dict={x: batch_xs, y_: batch_ys})
我收到InternalError: Blas SGEMM launch failed
。这是完整的错误和堆栈跟踪:堆栈:EC2 g2.8xlarge机器,Ubuntu 14.04