在张量流分布式训练中如何进行评估和推理?

nab*_*ost 5 python distributed distributed-computing tensorflow

我了解tensorflow分布式培训,并且实现了自己的脚本。

我现在想要做的是整合为某些工作人员分配异步评估模型任务的可能性。

假设我们有6个工作人员,我要做的是使用其中4个工作人员进行异步培训,一个工作人员定期评估模型,另一个工作人员定期进行模型推断。

我的直觉是实现以下目标:

....
elif FLAGS.job_name == "worker":

    if FLAGS.task_index <= (len(cluster_dict["worker"][:-2]) - 1):
         logging.info("Training worker started")
         ...
        with tf.device(tf.train.replica_device_setter(
                worker_device="/job:worker/task:%d" % FLAGS.task_index,
                cluster=cluster,
                ps_tasks=len(cluster_dict["ps"])
            )):
                train_model = Model(
                    mode=tf.contrib.learn.ModeKeys.TRAIN
                )
               with tf.train.MonitoredTrainingSession(
                    is_chief=(FLAGS.task_index == 0),
                    master=server.target,
                    checkpoint_dir=ckpt_dir,
                    config=config_proto,
                    hooks=hooks
                ) as mon_sess:
                    while not mon_sess.should_stop():
                        res = train_model.train(...)
                        ...

   elif FLAGS.task_index == (len(cluster_dict["worker"][-2]) - 1):
         logging.info("Evaluation worker started")
         ...
         with tf.device(tf.train.replica_device_setter(
              worker_device="/job:worker/task:%d" % FLAGS.task_index,
              cluster=cluster,
              ps_tasks=len(cluster_dict["ps"])
          )):
              eval_model = Model(
                 mode=tf.contrib.learn.ModeKeys.EVAL
              )
              ...

   elif FLAGS.task_index == (len(cluster_dict["worker"][-1]) - 1):
        logging.info("Inference worker started")
        ...
        with tf.device(tf.train.replica_device_setter(
               worker_device="/job:worker/task:%d" % FLAGS.task_index,
               cluster=cluster,
               ps_tasks=len(cluster_dict["ps"])
            )):
                infer_model = Model(
                    mode=tf.contrib.learn.ModeKeys.INFER
                )
                ...
Run Code Online (Sandbox Code Playgroud)

现在,评估和推理会议如何?对于培训,我可以使用tf.train.MonitoredTrainingSession,但是对于评估和推断,我看不到这样舒适的解决方案,而我看到的唯一可能性就是使用tf.Session

关于实际的评估和推断循环,我认为应该使用一个while循环,在该循环中工作人员会定期调用eval_model.eval(...)infer_model.infer(...),但这意味着评估是在考虑时间的情况下进行的,而不是考虑global_step以及我只能赋予的唯一含义”是睡觉的线程。

在分布式张量流设置中异步执行训练,评估和推断的正确方法吗?