class_docstr: Toy model to test mesh_tensorflow.
class_docstr_tok: ["Toy","model","to","test","mesh_tensorflow","."]
docstr: Construct EstimatorSpec for EVAL mode.
docstr_tok: ["Construct","EstimatorSpec","for","EVAL","mode","."]
code: def estimator_spec_eval(
      self, features, logits, labels, loss, restore_hook, use_tpu
  ):
      """Construct EstimatorSpec for EVAL mode."""
      hparams = self.hparams
      problem = hparams.problem
      if logits.get_shape().ndims == 3:
          logits = tf.expand_dims(tf.expand_dims(logits, 2), 3)
  
      # Support for multiproblem
      task_list = [problem]
      if hasattr(problem, "task_list"):
          task_list = problem.task_list
  
      eval_metrics_fns = metrics.create_evaluation_metrics(
          task_list, hparams
      )
  
      if use_tpu:
  
          def metric_fn(tf_logits, labels):
              with tf.device("cpu:0"), mtf.utils.outside_all_rewrites():
                  eval_metrics = {}
                  for metric_name, metric_fn in six.iteritems(
                      eval_metrics_fns
                  ):
                      if (
                          metric_name.split("/")[-1]
                          not in t2t_model.TPU_METRIC_BLACKLIST
                      ):
                          eval_metrics[metric_name] = metric_fn(
                              tf_logits, None, tf.identity(labels)
                          )
                  return eval_metrics
  
          return tpu_estimator.TPUEstimatorSpec(
              tf_estimator.ModeKeys.EVAL,
              evaluation_hooks=[restore_hook],
              loss=loss,
              eval_metrics=(metric_fn, [logits, labels]),
          )
      else:
          eval_metrics = {}
          predictions = {"predictions": logits}
          for metric_name, metric_fn in six.iteritems(eval_metrics_fns):
              eval_metrics[metric_name] = metric_fn(
                  logits, features, features["targets"]
              )
  
          return tf_estimator.EstimatorSpec(
              tf_estimator.ModeKeys.EVAL,
              predictions=predictions,
              eval_metric_ops=eval_metrics,
              evaluation_hooks=[restore_hook],
              loss=loss,
          )
  
file_path: tensor2tensor/tensor2tensor/utils/mtf_model.py
imports: from __future__ import absolute_import
  from __future__ import division
  from __future__ import print_function
  import mesh_tensorflow
  import six
  from tensor2tensor.utils import hparams_lib
  from tensor2tensor.utils import learning_rate
  from tensor2tensor.utils import metrics
  from tensor2tensor.utils import t2t_model
  import tensorflow.compat.v1
  from tensorflow.compat.v1 import estimator
  from tensorflow.contrib.tpu.python.tpu import tpu_estimator
label_desc: Use image node_id 2 for calling the MtfModel obj's underlying member method code with example usage: obj.estimator_spec_eval(features, logits, labels, loss, restore_hook, use_tpu) and returns: tpu_estimator, tf_estimator, eval_metrics