class_docstr: Defines a configuration class from which a PPO Algorithm can be built.
  
  .. testcode::
  
      from ray.rllib.algorithms.ppo import PPOConfig
      config = PPOConfig()
      config = config.training(gamma=0.9, lr=0.01, kl_coeff=0.3,
          train_batch_size=128)
      config = config.resources(num_gpus=0)
      config = config.rollouts(num_rollout_workers=1)
  
      # Build a Algorithm object from the config and run 1 training iteration.
      algo = config.build(env="CartPole-v1")
      algo.train()
  
  .. testcode::
  
      from ray.rllib.algorithms.ppo import PPOConfig
      from ray import air
      from ray import tune
      config = PPOConfig()
      # Print out some default values.
  
      # Update the config object.
      config.training(
          lr=tune.grid_search([0.001 ]), clip_param=0.2
      )
      # Set the config object's env.
      config = config.environment(env="CartPole-v1")
  
      # Use to_dict() to get the old-style python config dict
      # when running with tune.
      tune.Tuner(
          "PPO",
          run_config=air.RunConfig(stop={"training_iteration": 1}),
          param_space=config.to_dict(),
      ).fit()
  
  .. testoutput::
      :hide:
  
      ...
class_docstr_tok: ["Defines","a","configuration","class","from","which","a","PPO","Algorithm","can","be","built",".","..","testcode",":",":","from","ray.rllib.algorithms.ppo","import","PPOConfig","config","=","PPOConfig","(",")","config","=","config.training","(","gamma=0.9",",","lr=0.01",",","kl_coeff=0.3",",","train_batch_size=128",")","config","=","config.resources","(","num_gpus=0",")","config","=","config.rollouts","(","num_rollout_workers=1",")","#","Build","a","Algorithm","object","from","the","config","and","run","1","training","iteration",".","algo","=","config.build","(","env=","''","CartPole-v1","''",")","algo.train","(",")","..","testcode",":",":","from","ray.rllib.algorithms.ppo","import","PPOConfig","from","ray","import","air","from","ray","import","tune","config","=","PPOConfig","(",")","#","Print","out","some","default","values",".","#","Update","the","config","object",".","config.training","(","lr=tune.grid_search","(","[","0.001","]",")",",","clip_param=0.2",")","#","Set","the","config","object","'s","env",".","config","=","config.environment","(","env=","''","CartPole-v1","''",")","#","Use","to_dict","(",")","to","get","the","old-style","python","config","dict","#","when","running","with","tune",".","tune.Tuner","(","``","PPO","''",",","run_config=air.RunConfig","(","stop=","{","``","training_iteration","''",":","1","}",")",",","param_space=config.to_dict","(",")",",",")",".fit","(",")","..","testoutput",":",":",":","hide",":","..."]
code: def validate(self) -> None:
      # Call super's validation method.
      super().validate()
  
      # Synchronous sampling, on-policy/PPO algos -> Check mismatches between
      # `rollout_fragment_length` and `train_batch_size` to avoid user confusion.
      # TODO (sven): Make rollout_fragment_length a property and create a private
      #  attribute to store (possibly) user provided value (or "auto") in. Deprecate
      #  `self.get_rollout_fragment_length()`.
      self.validate_train_batch_size_vs_rollout_fragment_length()
  
      # SGD minibatch size must be smaller than train_batch_size (b/c
      # we subsample a batch of `sgd_minibatch_size` from the train-batch for
      # each `num_sgd_iter`).
      # Note: Only check this if `train_batch_size` > 0 (DDPPO sets this
      # to -1 to auto-calculate the actual batch size later).
      if self.sgd_minibatch_size > self.train_batch_size:
          raise ValueError(
              f"`sgd_minibatch_size` ({self.sgd_minibatch_size}) must be <= "
              f"`train_batch_size` ({self.train_batch_size}). In PPO, the train batch"
              f" will be split into {self.sgd_minibatch_size} chunks, each of which "
              f"is iterated over (used for updating the policy) {self.num_sgd_iter} "
              "times."
          )
  
      # Episodes may only be truncated (and passed into PPO's
      # `postprocessing_fn`), iff generalized advantage estimation is used
      # (value function estimate at end of truncated episode to estimate
      # remaining value).
      if (
          not self.in_evaluation
          and self.batch_mode == "truncate_episodes"
          and not self.use_gae
      ):
          raise ValueError(
              "Episode truncation is not supported without a value "
              "function (to estimate the return at the end of the truncated"
              " trajectory). Consider setting "
              "batch_mode=complete_episodes."
          )
  
      # Entropy coeff schedule checking.
      if self._enable_new_api_stack:
          if self.entropy_coeff_schedule is not None:
              raise ValueError(
                  "`entropy_coeff_schedule` is deprecated and must be None! Use the "
                  "`entropy_coeff` setting to setup a schedule."
              )
          Scheduler.validate(
              fixed_value_or_schedule=self.entropy_coeff,
              setting_name="entropy_coeff",
              description="entropy coefficient",
          )
      if (
          isinstance(self.entropy_coeff, float)
          and self.entropy_coeff < 0.0
      ):
          raise ValueError("`entropy_coeff` must be >= 0.0")
  
imports: import logging
  from typing import List, Optional, Type, Union, TYPE_CHECKING
  import numpy
  import tree
  from ray.rllib.algorithms.algorithm import Algorithm
  from ray.rllib.algorithms.algorithm_config import AlgorithmConfig, NotProvided
  from ray.rllib.core.rl_module.rl_module import SingleAgentRLModuleSpec
  from ray.rllib.evaluation.postprocessing_v2 import postprocess_episodes_to_sample_batch
  from ray.rllib.evaluation.rollout_worker import RolloutWorker
  from ray.rllib.execution.rollout_ops import standardize_fields, synchronous_parallel_sample
  from ray.rllib.execution.train_ops import train_one_step, multi_gpu_train_one_step
  from ray.rllib.policy.policy import Policy
  from ray.rllib.utils.annotations import override
  from ray.rllib.utils.deprecation import DEPRECATED_VALUE
  from ray.rllib.utils.metrics.learner_info import LEARNER_STATS_KEY
  from ray.rllib.utils.metrics import NUM_AGENT_STEPS_SAMPLED, NUM_ENV_STEPS_SAMPLED, SYNCH_WORKER_WEIGHTS_TIMER, SAMPLE_TIMER, ALL_MODULES
  from ray.rllib.env.single_agent_episode import SingleAgentEpisode
  from ray.rllib.policy.sample_batch import SampleBatch
  from ray.rllib.utils.schedules.scheduler import Scheduler
  from ray.rllib.utils.typing import ResultDict
  from ray.util.debug import log_once
label_desc: Use image node_id 5 for calling the PPOConfig obj's underlying member method code with example usage: obj.validate() without return types