class_docstr: Manages all the learning details needed when training an agent.
  
  These include:
    * Using distribution strategies correctly
    * Summaries
    * Checkpoints
    * Minimizing entering/exiting TF context:
        Especially in the case of TPUs scheduling a single TPU program to
        perform multiple train steps is critical for performance.
    * Generalizes the train call to be done correctly across CPU, GPU, or TPU
      executions managed by DistributionStrategies. This uses `strategy.run` and
      then makes sure to do a reduce operation over the `LossInfo` returned by
      the agent.
class_docstr_tok: ["Manages","all","the","learning","details","needed","when","training","an","agent",".","These","include",":","*","Using","distribution","strategies","correctly","*","Summaries","*","Checkpoints","*","Minimizing","entering\/exiting","TF","context",":","Especially","in","the","case","of","TPUs","scheduling","a","single","TPU","program","to","perform","multiple","train","steps","is","critical","for","performance",".","*","Generalizes","the","train","call","to","be","done","correctly","across","CPU",",","GPU",",","or","TPU","executions","managed","by","DistributionStrategies",".","This","uses","`","strategy.run","`","and","then","makes","sure","to","do","a","reduce","operation","over","the","`","LossInfo","`","returned","by","the","agent","."]
code: def _train(self, iterations, iterator, parallel_iterations):
      # Call run explicitly once to get loss info shape for autograph. Because the
      # for loop below will get converted to a `tf.while_loop` by autograph we
      # need the shape of loss info to be well defined.
      loss_info = self.single_train_step(iterator)
  
      for _ in tf.range(iterations - 1):
          tf.autograph.experimental.set_loop_options(
              parallel_iterations=parallel_iterations
          )
          loss_info = self.single_train_step(iterator)
  
      def _reduce_loss(loss):
          rank = None
          if isinstance(loss, tf.distribute.DistributedValues):
              # If loss is distributed get the rank from the first replica.
              rank = loss.values[0].shape.rank
          elif tf.is_tensor(loss):
              rank = loss.shape.rank
          axis = None
          if rank:
              axis = tuple(range(0, rank))
          return self.strategy.reduce(
              tf.distribute.ReduceOp.SUM, loss, axis=axis
          )
  
      # We assume all data can be reduced in the loss_info. This means no
      # string dtypes are currently allowed as LossInfo Fields.
      reduced_loss_info = tf.nest.map_structure(_reduce_loss, loss_info)
      return reduced_loss_info
  
file_path: agents/tf_agents/train/learner.py
imports: import os
  from typing import Any, Optional, Tuple
  from absl import logging
  import gin
  import tensorflow.compat.v2
  from tf_agents.agents import tf_agent
  from tf_agents.specs import tensor_spec
  from tf_agents.train import interval_trigger
  from tf_agents.typing import types
  from tf_agents.utils import common
label_desc: Use image node_id 5 for calling the Learner obj's underlying member method code with example usage: obj._train(iterations, iterator, parallel_iterations) and returns: reduced_loss_info, self