TPUEstimator不适用于use_tpu = False

时间:2018-08-17 23:26:19

标签: google-cloud-platform google-cloud-tpu

我正在尝试先在CPU上本地使用TPUEstimator运行模型,以通过在估算器初始化中设置use_tpu=False来验证其是否有效。火车运行时出现此错误。

InternalError: failed to synchronously memcpy host-to-device: host 0x7fcc7e4d4000 to device 0x1deffc002 size 4096: Failed precondition: Unable to enqueue when not opened, queue: [0000:00:04.0 PE0 C0 MC0 TN0 Queue HBM_WRITE]. State is: CLOSED [[Node: optimizer/gradients/neural_network/fully_connected_2/BiasAdd_grad/BiasAddGrad_G14 = _Recv[client_terminated=false, recv_device="/job:worker/replica:0/task:0/device:TPU:0", send_device="/job:worker/replica:0/task:0/device:CPU:0", send_device_incarnation=-7832507818616568453, tensor_name="edge_42_op...iasAddGrad", tensor_type=DT_FLOAT, _device="/job:worker/replica:0/task:0/device:TPU:0"]()]]

它似乎仍在尝试使用TPU,因为它显示为recv_device="/job:worker/replica:0/task:0/device:TPU:0"。当use_tpu设置为False时,为什么要尝试使用TPU?

1 个答案:

答案 0 :(得分:1)

您使用的是什么优化程序?如果您使用tf.contrib.tpu.CrossShardOptimizer并且use_tpu设置为False,则可能会发生这种类型的错误。优化程序正在尝试在TPU内核之间分配工作,但由于您在CPU上运行而无法这样做。

通常的做法是使用命令行标志来设置是否使用TPU。此标志用于切换CrossShardOptimizeruse_tpu之类的东西。例如,在MNIST参考模型中:

if FLAGS.use_tpu:
  optimizer = tf.contrib.tpu.CrossShardOptimizer(optimizer)

https://github.com/tensorflow/models/blob/ad3526a98e7d5e9e57c029b8857ef7b15c903ca2/official/mnist/mnist_tpu.py#L102

相关问题