class_docstr: Manages all the learning details needed when training an PPO.
  
  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","PPO",".","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","."]
docstr: Train `num_samples` batches repeating for `num_epochs` of iterations.
  
  Args:
    parallel_iterations: Maximum number of train iterations to allow running
      in parallel. This value is forwarded directly to the training tf.while
      loop.
  
  Returns:
    The total loss computed before running the final step.
docstr_tok: ["Train","`","num_samples","`","batches","repeating","for","`","num_epochs","`","of","iterations",".","Args",":","parallel_iterations",":","Maximum","number","of","train","iterations","to","allow","running","in","parallel",".","This","value","is","forwarded","directly","to","the","training","tf.while","loop",".","Returns",":","The","total","loss","computed","before","running","the","final","step","."]
code: def run(self, parallel_iterations=10):
      """Train `num_samples` batches repeating for `num_epochs` of iterations.
  
      Args:
        parallel_iterations: Maximum number of train iterations to allow running
          in parallel. This value is forwarded directly to the training tf.while
          loop.
  
      Returns:
        The total loss computed before running the final step.
      """
      num_frames = self._update_normalizers(
          self._normalization_iterator
      )
      self.num_frames_for_training.assign(num_frames)
  
      if self._minibatch_size:
          num_total_batches = (
              int(
                  self.num_frames_for_training.numpy()
                  / self._minibatch_size
              )
              * self._num_epochs
          )
      else:
          num_total_batches = self._num_samples * self._num_epochs
  
      iterations = int(num_total_batches / self.num_replicas)
      if iterations == 0:
          raise ValueError(
              "Cannot distribute {} batches across {} replicas. "
              "Please increase PPOLearner.num_samples. See PPOLeaner."
              "num_samples documentation for more details.".format(
                  num_total_batches, self.num_replicas
              )
          )
      loss_info = self._generic_learner.run(
          iterations,
          self._train_iterator,
          parallel_iterations=parallel_iterations,
      )
  
      return loss_info
  
file_path: agents/tf_agents/train/ppo_learner.py
imports: from typing import Callable, Optional, Text
  import gin
  import tensorflow
  from tf_agents.agents import tf_agent
  from tf_agents.agents.ppo import ppo_agent
  from tf_agents.networks import utils
  from tf_agents.specs import tensor_spec
  from tf_agents.train import learner
  from tf_agents.typing import types
  from tf_agents.utils import common
  from tf_agents.utils import nest_utils
label_desc: Use image node_id 3 for calling the PPOLearner obj's underlying member method code with example usage: obj.run(parallel_iterations) and returns: loss_info