class_docstr: Phoenix: A smart search AutoML algorithm.
class_docstr_tok: ["Phoenix",":","A","smart","search","AutoML","algorithm","."]
docstr: Constructs a Phoenix instance.
  
  Args:
    phoenix_spec: A `PhoenixSpec` proto with the spec for the run.
    input_layer_fn: A function that converts feature Tensors to input layer.
      See learning.autolx.model_search.data.Provider.get_input_layer_fn
      for details.
    study_owner: A string holding the ldap of the study owner. We use tuner
      platforms to conduct the various architectures training. This field
      specifies the study owner.
    study_name: A string holding the study name.
    head: A head to use with Phoenix for creating the loss and eval metrics.
      If no head is given, Phoenix falls back to using the loss_fn and
      metric_fn. N.B.: Phoenix creates its own EstimatorSpec so everything
        besides the loss and eval metrics returned by head will be ignored.
    logits_dimension: An int holding the dimension of the output. Must be
      provided if head is None. Will be ignored if head is not None.
    label_vocabulary: List or tuple with labels vocabulary. Needed only if the
      labels are of type string. This list is used by the loss function if
      loss_fn is not provided. It is also used in the metric function to
      create the accuracy metric ops. Use only with multiclass classification
      problems.
    loss_fn: A function to compute the loss. Ignored if `head` is not None.
      Must accept as inputs a `labels` Tensor, a `logits` Tensor, and
      a `weights` Tensor. `weights` must either be rank 0 or have
      the same rank as labels. If None, Phoenix defaults to using softmax
      cross-entropy.
      Additional `params` holding the hparameters of the trial can be added
      as input to the signature.
      For multitaks, you have the option to pass a dict of functions keyed
      by the task name to apply different loss functions for different tasks.
    metric_fn: Metrics for Tensorboard. Ignored if `head` is not None.
      metric_fn takes `label` and `predictions` as input, and outputs a
      dictionary of (tensor, update_op) tuples. `label` is a Tensor (in the
      single task case) or a dict of Tensors (in the case of multi-task, where
      the key of the dicts correspond to the task names). `predictions` is a
      dict of Tensors. In the single task case, it consists of `predictions`,
      `probabilities`, and `log_probabilities`. In the multi-task case, it
      consists of the same keys as that of the single task case, but also
      those corresponding to each task (e.g., predictions/task_name_1). See
      `metric_fns` for more detail. If `metric_fn` is None, it will include a
      metric for the number of parameters, accuracy (if logit_dimensions >=
      2), and AUC metrics (if logit_dimensions == 2).
    predictions_fn: A function to convert eval logits to the
      `predictions` dictionary passed to metric_fn. If `None`, defaults to
      computing 'predictions', 'probabilities', and 'log_probabilities'.
      For multitaks, you have the option to pass a dict of functions keyed
      by the task name to apply different prediction functions for different
      tasks.
    metadata: An object that implements metadata api in
      learning.adanets.phoenix.metadata.Metadata
    optimizer_fn: A function that follows two possible signatures: 1. takes
      `params` as args and returns a tensorflow v1 optimizer instance.
      2. A function with no args that returns a tensorflow v1 optimizer.
      Please keep as None to use our default optimizers (i.e. let the
      search choose an optimizer).
docstr_tok: ["Constructs","a","Phoenix","instance",".","Args",":","phoenix_spec",":","A","`","PhoenixSpec","`","proto","with","the","spec","for","the","run",".","input_layer_fn",":","A","function","that","converts","feature","Tensors","to","input","layer",".","See","learning.autolx.model_search.data.Provider.get_input_layer_fn","for","details",".","study_owner",":","A","string","holding","the","ldap","of","the","study","owner",".","We","use","tuner","platforms","to","conduct","the","various","architectures","training",".","This","field","specifies","the","study","owner",".","study_name",":","A","string","holding","the","study","name",".","head",":","A","head","to","use","with","Phoenix","for","creating","the","loss","and","eval","metrics",".","If","no","head","is","given",",","Phoenix","falls","back","to","using","the","loss_fn","and","metric_fn",".","N.B",".",":","Phoenix","creates","its","own","EstimatorSpec","so","everything","besides","the","loss","and","eval","metrics","returned","by","head","will","be","ignored",".","logits_dimension",":","An","int","holding","the","dimension","of","the","output",".","Must","be","provided","if","head","is","None",".","Will","be","ignored","if","head","is","not","None",".","label_vocabulary",":","List","or","tuple","with","labels","vocabulary",".","Needed","only","if","the","labels","are","of","type","string",".","This","list","is","used","by","the","loss","function","if","loss_fn","is","not","provided",".","It","is","also","used","in","the","metric","function","to","create","the","accuracy","metric","ops",".","Use","only","with","multiclass","classification","problems",".","loss_fn",":","A","function","to","compute","the","loss",".","Ignored","if","`","head","`","is","not","None",".","Must","accept","as","inputs","a","`","labels","`","Tensor",",","a","`","logits","`","Tensor",",","and","a","`","weights","`","Tensor",".","`","weights","`","must","either","be","rank","0","or","have","the","same","rank","as","labels",".","If","None",",","Phoenix","defaults","to","using","softmax","cross-entropy",".","Additional","`","params","`","holding","the","hparameters","of","the","trial","can","be","added","as","input","to","the","signature",".","For","multitaks",",","you","have","the","option","to","pass","a","dict","of","functions","keyed","by","the","task","name","to","apply","different","loss","functions","for","different","tasks",".","metric_fn",":","Metrics","for","Tensorboard",".","Ignored","if","`","head","`","is","not","None",".","metric_fn","takes","`","label","`","and","`","predictions","`","as","input",",","and","outputs","a","dictionary","of","(","tensor",",","update_op",")","tuples",".","`","label","`","is","a","Tensor","(","in","the","single","task","case",")","or","a","dict","of","Tensors","(","in","the","case","of","multi-task",",","where","the","key","of","the","dicts","correspond","to","the","task","names",")",".","`","predictions","`","is","a","dict","of","Tensors",".","In","the","single","task","case",",","it","consists","of","`","predictions","`",",","`","probabilities","`",",","and","`","log_probabilities","`",".","In","the","multi-task","case",",","it","consists","of","the","same","keys","as","that","of","the","single","task","case",",","but","also","those","corresponding","to","each","task","(","e.g.",",","predictions\/task_name_1",")",".","See","`","metric_fns","`","for","more","detail",".","If","`","metric_fn","`","is","None",",","it","will","include","a","metric","for","the","number","of","parameters",",","accuracy","(","if","logit_dimensions",">","=","2",")",",","and","AUC","metrics","(","if","logit_dimensions","==","2",")",".","predictions_fn",":","A","function","to","convert","eval","logits","to","the","`","predictions","`","dictionary","passed","to","metric_fn",".","If","`","None","`",",","defaults","to","computing","'predictions","'",",","'probabilities","'",",","and","'log_probabilities","'",".","For","multitaks",",","you","have","the","option","to","pass","a","dict","of","functions","keyed","by","the","task","name","to","apply","different","prediction","functions","for","different","tasks",".","metadata",":","An","object","that","implements","metadata","api","in","learning.adanets.phoenix.metadata.Metadata","optimizer_fn",":","A","function","that","follows","two","possible","signatures",":","1.","takes","`","params","`","as","args","and","returns","a","tensorflow","v1","optimizer","instance",".","2",".","A","function","with","no","args","that","returns","a","tensorflow","v1","optimizer",".","Please","keep","as","None","to","use","our","default","optimizers","(","i.e",".","let","the","search","choose","an","optimizer",")","."]
code: def __init__(
      self,
      phoenix_spec,
      input_layer_fn,
      study_owner,
      study_name,
      head=None,
      logits_dimension=None,
      label_vocabulary=None,
      loss_fn=None,
      metric_fn=None,
      predictions_fn=None,
      metadata=None,
      optimizer_fn=None,
  ):
      """Constructs a Phoenix instance.
  
      Args:
        phoenix_spec: A `PhoenixSpec` proto with the spec for the run.
        input_layer_fn: A function that converts feature Tensors to input layer.
          See learning.autolx.model_search.data.Provider.get_input_layer_fn
          for details.
        study_owner: A string holding the ldap of the study owner. We use tuner
          platforms to conduct the various architectures training. This field
          specifies the study owner.
        study_name: A string holding the study name.
        head: A head to use with Phoenix for creating the loss and eval metrics.
          If no head is given, Phoenix falls back to using the loss_fn and
          metric_fn. N.B.: Phoenix creates its own EstimatorSpec so everything
            besides the loss and eval metrics returned by head will be ignored.
        logits_dimension: An int holding the dimension of the output. Must be
          provided if head is None. Will be ignored if head is not None.
        label_vocabulary: List or tuple with labels vocabulary. Needed only if the
          labels are of type string. This list is used by the loss function if
          loss_fn is not provided. It is also used in the metric function to
          create the accuracy metric ops. Use only with multiclass classification
          problems.
        loss_fn: A function to compute the loss. Ignored if `head` is not None.
          Must accept as inputs a `labels` Tensor, a `logits` Tensor, and
          a `weights` Tensor. `weights` must either be rank 0 or have
          the same rank as labels. If None, Phoenix defaults to using softmax
          cross-entropy.
          Additional `params` holding the hparameters of the trial can be added
          as input to the signature.
          For multitaks, you have the option to pass a dict of functions keyed
          by the task name to apply different loss functions for different tasks.
        metric_fn: Metrics for Tensorboard. Ignored if `head` is not None.
          metric_fn takes `label` and `predictions` as input, and outputs a
          dictionary of (tensor, update_op) tuples. `label` is a Tensor (in the
          single task case) or a dict of Tensors (in the case of multi-task, where
          the key of the dicts correspond to the task names). `predictions` is a
          dict of Tensors. In the single task case, it consists of `predictions`,
          `probabilities`, and `log_probabilities`. In the multi-task case, it
          consists of the same keys as that of the single task case, but also
          those corresponding to each task (e.g., predictions/task_name_1). See
          `metric_fns` for more detail. If `metric_fn` is None, it will include a
          metric for the number of parameters, accuracy (if logit_dimensions >=
          2), and AUC metrics (if logit_dimensions == 2).
        predictions_fn: A function to convert eval logits to the
          `predictions` dictionary passed to metric_fn. If `None`, defaults to
          computing 'predictions', 'probabilities', and 'log_probabilities'.
          For multitaks, you have the option to pass a dict of functions keyed
          by the task name to apply different prediction functions for different
          tasks.
        metadata: An object that implements metadata api in
          learning.adanets.phoenix.metadata.Metadata
        optimizer_fn: A function that follows two possible signatures: 1. takes
          `params` as args and returns a tensorflow v1 optimizer instance.
          2. A function with no args that returns a tensorflow v1 optimizer.
          Please keep as None to use our default optimizers (i.e. let the
          search choose an optimizer).
      """
  
      # Check Phoenix preconditions and fail early if any of them are broken.
      if phoenix_spec.multi_task_spec:
          # TODO(b/172564129): Add support for head and custom loss_fns in
          # multi-task.
          assert not head, "head is not supported for multi-task."
      if head:
          msg = "Do not specify {} when using head as head already contains it."
          assert not logits_dimension, msg.format("logits_dimension")
          assert not label_vocabulary, msg.format("label_vocabulary")
          assert not loss_fn, msg.format("loss_fn")
          assert not metric_fn, msg.format("metric_fn")
  
      # Check ensemble search / distillation preconditions.
      ensemble_spec = phoenix_spec.ensemble_spec
      distillation_spec = phoenix_spec.distillation_spec
      if (
          trial_utils.has_distillation(distillation_spec)
          and trial_utils.has_ensemble_search(ensemble_spec)
          and not trial_utils.is_intermixed_ensemble_search(
              ensemble_spec
          )
      ):
          ensemble_search_spec = (
              ensemble_spec.nonadaptive_search
              if trial_utils.is_nonadaptive_ensemble_search(
                  ensemble_spec
              )
              else ensemble_spec.adaptive_search
          )
          if (
              distillation_spec.minimal_pool_size
              == ensemble_search_spec.minimal_pool_size
          ):
              logging.warning(
                  "minimal_pool_size is the same for ensemble spec and "
                  "distillation spec, so distillation will be ignored."
              )
  
      self._phoenix_spec = phoenix_spec
      self._input_layer_fn = input_layer_fn
      self._study_owner = study_owner
      self._study_name = study_name
      self._head = head
      self._logits_dimension = (
          self._head.logits_dimension if head else logits_dimension
      )
      self._label_vocabulary = label_vocabulary
      if self._label_vocabulary:
          assert self._logits_dimension == len(self._label_vocabulary)
  
      self._loss_fn = loss_fn or loss_fns.make_multi_class_loss_fn(
          label_vocabulary=label_vocabulary
      )
  
      self._user_specified_metric_fn = metric_fn
  
      self._predictions_fn = predictions_fn or _default_predictions_fn
  
      if metadata is None:
          self._metadata = ml_metadata_db.MLMetaData(
              phoenix_spec, study_name, study_owner
          )
      else:
          self._metadata = metadata
      self._task_manager = task_manager.TaskManager(
          phoenix_spec=phoenix_spec,
          logits_dimension=logits_dimension,
          loss_fn=self._loss_fn,
          head=self._head,
      )
      self._controller = controller.InProcessController(
          phoenix_spec=phoenix_spec, metadata=self._metadata
      )
      self._user_optimizer_fn = optimizer_fn
  
imports: import functools
  import inspect
  from absl import logging
  import keras_tuner
  from model_search import controller
  from model_search import hparam
  from model_search import loss_fns
  from model_search import metric_fns
  from model_search import task_manager
  from model_search.architecture import architecture_utils
  from model_search.generators import base_tower_generator
  from model_search.generators import trial_utils
  from model_search.meta import transfer_learning
  from model_search.metadata import ml_metadata_db
  from model_search.proto import phoenix_spec_pb2
  from model_search.proto import transfer_learning_spec_pb2
  import numpy
  import tensorflow.compat.v2
label_desc: Use image node_id 1 to create a new Phoenix object from inherited base classes: object with example: obj = Phoenix(phoenix_spec, input_layer_fn, study_owner, study_name, head, logits_dimension, label_vocabulary, loss_fn, metric_fn, predictions_fn, metadata, optimizer_fn)