class_docstr: Generates TaskSpecs for various tasks in Phoenix.
docstr: Creates the task spec for a task.
docstr_tok: ["Creates","the","task","spec","for","a","task","."]
code: def _create_task_spec(
      self,
      labels,
      weights,
      train_logits_specs,
      eval_logits_spec,
      train_op_fn,
      name,
      mode,
      loss_fn,
      add_train_ops=True,
  ):
      """Creates the task spec for a task."""
      train_op_list = []
      hooks_list = []
      eval_loss = None
      eval_logits = eval_logits_spec.logits
      train_losses = []
      for spec in train_logits_specs:
          if mode != tf.estimator.ModeKeys.PREDICT:
              loss = loss_fn(
                  labels=labels, logits=spec.logits, weights=weights
              )
              # Optimization only. I.e., can be removed.
              # Tensorflow creates two nodes if invoking cross_entropy on the same
              # tensor twice. If this statement is removed the code will continue to
              # work only slower.
              if spec.logits is eval_logits:
                  eval_loss = loss
  
              loss *= spec.logits_weight
  
              if spec.aux_logits is not None:
                  aux_loss = loss_fn(
                      labels=labels,
                      logits=spec.aux_logits,
                      weights=weights,
                  )
                  loss += spec.aux_logits_weight * aux_loss
  
              if add_train_ops:
                  train_op, train_hooks = train_op_fn(loss)
                  train_op_list.append(train_op)
                  hooks_list.extend(train_hooks)
  
              train_losses.append(loss)
  
      # The loss to display in tensorboard. Display loss even then training
      # logits is an empty list. I.e., no parameters to train.
      if mode != tf.estimator.ModeKeys.PREDICT and eval_loss is None:
          eval_loss = loss_fn(
              labels=labels, logits=eval_logits, weights=weights
          )
  
      return TaskSpec(
          name=name,
          logits=eval_logits,
          loss=eval_loss,
          train_op_list=train_op_list,
          train_hooks_list=hooks_list,
          train_losses=train_losses,
      )
  
imports: import collections
  import functools
  import inspect
  from absl import logging
  from model_search import block_builder
  from model_search import ensembler
  from model_search.architecture import architecture_utils
  from model_search.architecture import tower
  from model_search.ensembler import EnsembleLogits
  from model_search.generators import base_tower_generator
  from model_search.generators import trial_utils
  from model_search.meta import distillation
  import numpy
  import tensorflow.compat.v2
label_desc: Use image node_id 2 for calling the TaskManager obj's underlying member method code with example usage: obj._create_task_spec(labels, weights, train_logits_specs, eval_logits_spec, train_op_fn, name, mode, loss_fn, add_train_ops) and returns: TaskSpec