Run a training/validation session.

  Flags must have been parsed for this function to behave.

  Args:
    data: The data as loaded by `prepare_data()`.
    base_logdir: The top-level logdir to which to write summary data.
    session_id: A unique string ID for this session.
    group_id: The string ID of the session group that includes this
      session.
    hparams: A dict mapping hyperparameters in `HPARAMS` to values.

def run(data, base_logdir, session_id, group_id, hparams):
  """Run a training/validation session.

  Flags must have been parsed for this function to behave.

  Args:
    data: The data as loaded by `prepare_data()`.
    base_logdir: The top-level logdir to which to write summary data.
    session_id: A unique string ID for this session.
    group_id: The string ID of the session group that includes this
      session.
    hparams: A dict mapping hyperparameters in `HPARAMS` to values.
  """
  model = model_fn(hparams=hparams, seed=session_id)
  logdir = os.path.join(base_logdir, session_id)

  callback = tf.keras.callbacks.TensorBoard(
      logdir,
      update_freq=flags.FLAGS.summary_freq,
      profile_batch=0,  # workaround for issue #2084
  )
  hparams_callback = hp.KerasCallback(logdir, hparams, group_name=group_id)
  ((x_train, y_train), (x_test, y_test)) = data
  result = model.fit(
      x=x_train,
      y=y_train,
      epochs=flags.FLAGS.num_epochs,
      shuffle=False,
      validation_data=(x_test, y_test),
      callbacks=[callback, hparams_callback],
  )