class_docstr: An AI Platform Training based distributed CloudTuner.
  
  Attributes:
      oracle: Instance of Oracle class.
      hypermodel: Instance of HyperModel class
      directory: The Google Cloud Storage path for logs and checkpoints.
class_docstr_tok: ["An","AI","Platform","Training","based","distributed","CloudTuner",".","Attributes",":","oracle",":","Instance","of","Oracle","class",".","hypermodel",":","Instance","of","HyperModel","class","directory",":","The","Google","Cloud","Storage","path","for","logs","and","checkpoints","."]
docstr: Add a TensorBoard callback if needed, otherwise log hyperparameters.
  
  Note: Due to https://github.com/keras-team/keras/issues/14223, multiple
  TensorBoard callbacks are not supported. If user specified a TensorBoard
  callback, we treat it as an intent to log the metrics, and we shall
  additionally log the hyperparameters as well. Otherwise, we'll add a
  TensorBoard callback to pass back the epoch related metrics from
  remote execution.
  
  Args:
      callbacks: List of callbacks passed in to the search function.
      trial: A `Trial` instance.
  Raises:
      ValueError: If TensorBoard callback's log_dir does not match
      self.directory.
docstr_tok: ["Add","a","TensorBoard","callback","if","needed",",","otherwise","log","hyperparameters",".","Note",":","Due","to","https",":","\/\/github.com\/keras-team\/keras\/issues\/14223",",","multiple","TensorBoard","callbacks","are","not","supported",".","If","user","specified","a","TensorBoard","callback",",","we","treat","it","as","an","intent","to","log","the","metrics",",","and","we","shall","additionally","log","the","hyperparameters","as","well",".","Otherwise",",","we","'ll","add","a","TensorBoard","callback","to","pass","back","the","epoch","related","metrics","from","remote","execution",".","Args",":","callbacks",":","List","of","callbacks","passed","in","to","the","search","function",".","trial",":","A","`","Trial","`","instance",".","Raises",":","ValueError",":","If","TensorBoard","callback","'s","log_dir","does","not","match","self.directory","."]
code: def _add_logging(self, callbacks, trial):
      """Add a TensorBoard callback if needed, otherwise log hyperparameters.
  
      Note: Due to https://github.com/keras-team/keras/issues/14223, multiple
      TensorBoard callbacks are not supported. If user specified a TensorBoard
      callback, we treat it as an intent to log the metrics, and we shall
      additionally log the hyperparameters as well. Otherwise, we'll add a
      TensorBoard callback to pass back the epoch related metrics from
      remote execution.
  
      Args:
          callbacks: List of callbacks passed in to the search function.
          trial: A `Trial` instance.
      Raises:
          ValueError: If TensorBoard callback's log_dir does not match
          self.directory.
      """
  
      logdir = self._get_tensorboard_log_dir(trial.trial_id)
      for callback in callbacks:
          if issubclass(
              callback.__class__, tf.keras.callbacks.TensorBoard
          ):
              # Validate TensorBoard log_dir
              if callback.log_dir != self.directory:
                  raise ValueError(
                      f"log_dir in TensorBoard callback should be "
                      f"{self.directory}, but was {callback.log_dir}"
                  )
              # Patch the log_dir
              callback.log_dir = logdir
              # Do hyperparameter logging here to avoid having to
              # serialize/deserialize the hyperparameters if logged through
              # passing hparams_api.KerasCallback to client.cloud_fit.
              with tf.summary.create_file_writer(logdir).as_default():
                  hparams_api.hparams(
                      utils.convert_hyperparams_to_hparams(
                          trial.hyperparameters
                      )
                  )
              # We're done here, since there should only be one TensorBoard
              # callback
              return
  
      # TensorBoard callback not specified by user, add it here. The
      # TensorBoard logs are used for passing metrics back from
      # remote execution.
      callbacks.append(tf.keras.callbacks.TensorBoard(log_dir=logdir))
  
imports: import collections
  import copy
  import datetime
  import os
  import time
  from typing import Any, Callable, Dict, List, Mapping, Optional, Text, Union
  from keras_tuner.engine import hypermodel
  from keras_tuner.engine import hyperparameters
  from keras_tuner.engine import metrics_tracking
  from keras_tuner.engine import oracle
  from keras_tuner.engine import trial
  from keras_tuner.engine import tuner
  import tensorflow
  from tensorboard.plugins.hparams import api
  from tensorflow_cloud.core import deploy
  from tensorflow_cloud.core import machine_config
  from tensorflow_cloud.core import validate
  from tensorflow_cloud.tuner import cloud_fit_client
  from tensorflow_cloud.tuner import utils
  from tensorflow_cloud.tuner import vizier_client
  from tensorflow_cloud.utils import google_api_client
  from tensorflow_cloud.utils import tf_utils
label_desc: Use image node_id 8 for calling the DistributingCloudTuner obj's underlying member method code with example usage: obj._add_logging(callbacks, trial) without return types