code: def run_avg_external_eval(
      infer_model,
      infer_sess,
      model_dir,
      hparams,
      summary_writer,
      global_step,
  ):
      """Creates an averaged checkpoint and run external eval with it."""
      avg_dev_scores, avg_test_scores = None, None
      if hparams.avg_ckpts:
          # Convert VariableName:0 to VariableName.
          global_step_name = infer_model.model.global_step.name.split(
              ":"
          )[0]
          avg_model_dir = model_helper.avg_checkpoints(
              model_dir,
              hparams.num_keep_ckpts,
              global_step,
              global_step_name,
          )
  
          if avg_model_dir:
              avg_dev_scores, avg_test_scores, _ = run_external_eval(
                  infer_model,
                  infer_sess,
                  avg_model_dir,
                  hparams,
                  summary_writer,
                  avg_ckpts=True,
              )
  
      return avg_dev_scores, avg_test_scores
  
imports: from __future__ import print_function
  import math
  import os
  import random
  import time
  import tensorflow
  from .None import inference, gnmt_model
  from .gnmt import attention_model, model
  from .gnmt import model_helper
  from .gnmt.utils import nmt_utils, misc_utils
label_desc: Use image node_id 4 for calling a global function with example usage: run_avg_external_eval(infer_model, infer_sess, model_dir, hparams, summary_writer, global_step) and returns: avg_dev_scores,  avg_test_scores