我正在使用TensorFlow的pythonapi来训练LSTM的一个变体。
为此,我使用tf.while_loop
函数迭代时间步。在
在cpu上运行我的脚本时,它不会产生任何错误消息,但在gpu上,python崩溃的原因是:
...tensorflow/tensorflow/core/framework/tensor.cc:885] Check failed: nullptr != b.buf_ (nullptr vs. 00...)
我的代码中导致这个失败的部分(当注释掉它时,它起作用了)在while循环的主体中:
...
h_gathered = h_ta.gather(tf.range(time))
h_gathered = tf.transpose(h_gathered, [1, 0, 2])
syn_t = self.syntactic_weights_ta.read(time)[:, :time]
syn_t = tf.expand_dims(syn_t, 1)
syn_state_t = tf.squeeze(tf.tanh(tf.matmul(syn_t, h_gathered)), 1)
...
其中time
从零开始,在每一步之后递增,h_ta
是张量阵列
而且self.syntactic_weights_ta
也是张量阵列
self.syntactic_weights_ta = tf.TensorArray(
dtype=dtype,
size=max_seq_len,
tensor_array_name="fw_syntactic_weights")
self.syntactic_weights_ta = self.syntactic_weights_ta.unstack(syntactic_weights)
我试图在代码片段中实现的基本上是存储在h_ta
中的过去输出的加权和。
最后我用tf.train.AdamOptimizer
训练网络。在
我再次测试了这个脚本,但是这次while循环中的swap_memory
参数设置为False
,它也可以在GPU上运行,不过我很想知道它为什么不能与swap_memory=True
一起工作。在
这看起来像是一个bug,因为TensorArray的张量存储机制与while\u loop在swap_memory=True时执行的分配魔术交互。在
你能在TF的github上打开一个问题吗?还请包括:
并在这里回复github问题的链接?在
相关问题 更多 >
编程相关推荐