使用estimator获得InvalidArgumentError无法分配设备进行操作,allow_soft_placement:true不起作用

时间:2019-08-13 03:58:44

标签: tensorflow tensorflow-estimator tensor2tensor

def create_hparams():
    return trainer_lib.create_hparams(
      FLAGS.hparams_set,
      FLAGS.hparams,
      data_dir=os.path.expanduser(FLAGS.data_dir),
      problem_name=FLAGS.problem)


def create_decode_hparams():
    decode_hp = decoding.decode_hparams(FLAGS.decode_hparams)
    decode_hp.shards = FLAGS.decode_shards
    decode_hp.shard_id = FLAGS.worker_id
    decode_in_memory = FLAGS.decode_in_memory or decode_hp.decode_in_memory
    decode_hp.decode_in_memory = decode_in_memory
    decode_hp.decode_to_file = FLAGS.decode_to_file
    decode_hp.decode_reference = FLAGS.decode_reference
    return decode_hp

hp = create_hparams()
decode_hp = create_decode_hparams()
run_conf = t2t_trainer.create_run_config(hp)
estimator = trainer_lib.create_estimator(
    FLAGS.model,
    hp,
    run_conf,
    decode_hparams=decode_hp,
    use_tpu=FLAGS.use_tpu)
print(run_conf.session_config)

def input_fn():
    inputs = tf.placeholder(tf.int32, shape=(1, None, 1, 1), name="inputs")
    input_tensor = {'inputs': inputs }
    return tf.estimator.export.ServingInputReceiver(input_tensor, input_tensor)

predictor=tf.contrib.predictor.from_estimator(estimator, input_fn)

我得到了

的输出
  

InvalidArgumentError:无法分配设备进行操作   变压器/身体/ parallel_0 /身体/编码器/ layer_0 / self_attention / multihead_attention / dot_product_attention / attention:无法满足明确的设备规范“ / device:GPU:0”   因为没有可用的GPU设备支持的内核。代管   调试信息:托管组具有以下类型并受支持   设备:根成员(assigned_device_name_index _ =-1   required_device_name _ ='/ device:GPU:0'signed_device_name_ =''   resource_device_name _ =“ supported_device_types _ = [CPU]   可能的设备_ = []图片摘要:CPU

     

托管成员,用户请求的设备和分配的框架   设备(如果有):
  变形金刚/身体/ parallel_0 /身体/编码器/ layer_0 /自我注意/多头注意力/ dot_product_attention /注意   (ImageSummary)/ device:GPU:0

     

Op:ImageSummary节点属性:max_images = 1,T = DT_FLOAT,   bad_color =张量已注册   内核:device ='CPU'

当我打印run_conf.session_config时,我得到allow_soft_placement:true。许多人说它可以解决InvalidArgumentError的问题,但似乎对我不起作用。

0 个答案:

没有答案