rllib/agents/ppo/ppo.py
def validate_config(self, config: TrainerConfigDict) -> None:
        """Validates the Trainer's config dict.

        Args:
            config (TrainerConfigDict): The Trainer's config to check.

        Raises:
            ValueError: In case something is wrong with the config.
        """
        # Call super's validation method.
        super().validate_config(config)

        if isinstance(config["entropy_coeff"], int):
            config["entropy_coeff"] = float(config["entropy_coeff"])

        if config["entropy_coeff"] < 0.0:
            raise DeprecationWarning("entropy_coeff must be >= 0.0")

        # 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 (
            config["train_batch_size"] > 0
            and config["sgd_minibatch_size"] > config["train_batch_size"]
        ):
            raise ValueError(
                "`sgd_minibatch_size` ({}) must be <= "
                "`train_batch_size` ({}).".format(
                    config["sgd_minibatch_size"], config["train_batch_size"]
                )
            )

        # Check for mismatches between `train_batch_size` and
        # `rollout_fragment_length` and auto-adjust `rollout_fragment_length`
        # if necessary.
        # Note: Only check this if `train_batch_size` > 0 (DDPPO sets this
        # to -1 to auto-calculate the actual batch size later).
        num_workers = config["num_workers"] or 1
        calculated_min_rollout_size = (
            num_workers
            * config["num_envs_per_worker"]
            * config["rollout_fragment_length"]
        )
        if (
            config["train_batch_size"] > 0
            and config["train_batch_size"] % calculated_min_rollout_size != 0
        ):
            new_rollout_fragment_length = config["train_batch_size"] // (
                num_workers * config["num_envs_per_worker"]
            )
            logger.warning(
                "`train_batch_size` ({}) cannot be achieved with your other "
                "settings (num_workers={} num_envs_per_worker={} "
                "rollout_fragment_length={})! Auto-adjusting "
                "`rollout_fragment_length` to {}.".format(
                    config["train_batch_size"],
                    config["num_workers"],
                    config["num_envs_per_worker"],
                    config["rollout_fragment_length"],
                    new_rollout_fragment_length,
                )
            )
            config["rollout_fragment_length"] = new_rollout_fragment_length

        # 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 config["batch_mode"] == "truncate_episodes" and not config["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."
            )

        # Multi-agent mode and multi-GPU optimizer.
        if config["multiagent"]["policies"] and not config["simple_optimizer"]:
            logger.info(
                "In multi-agent mode, policies will be optimized sequentially"
                " by the multi-GPU optimizer. Consider setting "
                "simple_optimizer=True if this doesn't work for you."
            )
Validates the Trainer's config dict.

        Args:
            config (TrainerConfigDict): The Trainer's config to check.

        Raises:
            ValueError: In case something is wrong with the config.
        
Validates the Trainer's config dict.
Validates the Trainer ' s config dict .
def validate_config(self, config: TrainerConfigDict) -> None:
        super().validate_config(config)
        if isinstance(config["entropy_coeff"], int):
            config["entropy_coeff"] = float(config["entropy_coeff"])
        if config["entropy_coeff"] < 0.0:
            raise DeprecationWarning("entropy_coeff must be >= 0.0")
        if (
            config["train_batch_size"] > 0
            and config["sgd_minibatch_size"] > config["train_batch_size"]
        ):
            raise ValueError(
                "`sgd_minibatch_size` ({}) must be <= "
                "`train_batch_size` ({}).".format(
                    config["sgd_minibatch_size"], config["train_batch_size"]
                )
            )
        num_workers = config["num_workers"] or 1
        calculated_min_rollout_size = (
            num_workers
            * config["num_envs_per_worker"]
            * config["rollout_fragment_length"]
        )
        if (
            config["train_batch_size"] > 0
            and config["train_batch_size"] % calculated_min_rollout_size != 0
        ):
            new_rollout_fragment_length = config["train_batch_size"] // (
                num_workers * config["num_envs_per_worker"]
            )
            logger.warning(
                "`train_batch_size` ({}) cannot be achieved with your other "
                "settings (num_workers={} num_envs_per_worker={} "
                "rollout_fragment_length={})! Auto-adjusting "
                "`rollout_fragment_length` to {}.".format(
                    config["train_batch_size"],
                    config["num_workers"],
                    config["num_envs_per_worker"],
                    config["rollout_fragment_length"],
                    new_rollout_fragment_length,
                )
            )
            config["rollout_fragment_length"] = new_rollout_fragment_length
        if config["batch_mode"] == "truncate_episodes" and not config["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."
            )
        if config["multiagent"]["policies"] and not config["simple_optimizer"]:
            logger.info(
                "In multi-agent mode, policies will be optimized sequentially"
                " by the multi-GPU optimizer. Consider setting "
                "simple_optimizer=True if this doesn't work for you."
            )
def validate_config ( self , config : TrainerConfigDict ) -> None : super ( ) . validate_config ( config ) if isinstance ( config [ "entropy_coeff" ] , int ) : config [ "entropy_coeff" ] = float ( config [ "entropy_coeff" ] ) if config [ "entropy_coeff" ] < 0.0 : raise DeprecationWarning ( "entropy_coeff must be >= 0.0" ) if ( config [ "train_batch_size" ] > 0 and config [ "sgd_minibatch_size" ] > config [ "train_batch_size" ] ) : raise ValueError ( "`sgd_minibatch_size` ({}) must be <= " "`train_batch_size` ({})." . format ( config [ "sgd_minibatch_size" ] , config [ "train_batch_size" ] ) ) num_workers = config [ "num_workers" ] or 1 calculated_min_rollout_size = ( num_workers * config [ "num_envs_per_worker" ] * config [ "rollout_fragment_length" ] ) if ( config [ "train_batch_size" ] > 0 and config [ "train_batch_size" ] % calculated_min_rollout_size != 0 ) : new_rollout_fragment_length = config [ "train_batch_size" ] // ( num_workers * config [ "num_envs_per_worker" ] ) logger . warning ( "`train_batch_size` ({}) cannot be achieved with your other " "settings (num_workers={} num_envs_per_worker={} " "rollout_fragment_length={})! Auto-adjusting " "`rollout_fragment_length` to {}." . format ( config [ "train_batch_size" ] , config [ "num_workers" ] , config [ "num_envs_per_worker" ] , config [ "rollout_fragment_length" ] , new_rollout_fragment_length , ) ) config [ "rollout_fragment_length" ] = new_rollout_fragment_length if config [ "batch_mode" ] == "truncate_episodes" and not config [ "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." ) if config [ "multiagent" ] [ "policies" ] and not config [ "simple_optimizer" ] : logger . info ( "In multi-agent mode, policies will be optimized sequentially" " by the multi-GPU optimizer. Consider setting " "simple_optimizer=True if this doesn't work for you." )
Validates the Trainer's config dict.
Validates the Trainer ' s config dict .
"""Validates the Trainer's config dict.

        Args:
            config (TrainerConfigDict): The Trainer's config to check.

        Raises:
            ValueError: In case something is wrong with the config.
        """ # Call super's validation method. # 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). # Check for mismatches between `train_batch_size` and # `rollout_fragment_length` and auto-adjust `rollout_fragment_length` # if necessary. # Note: Only check this if `train_batch_size` > 0 (DDPPO sets this # to -1 to auto-calculate the actual batch size later). # 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). # Multi-agent mode and multi-GPU optimizer.
In case something is wrong with the config.
In case something is wrong with the config .
ValueError
self
config
TrainerConfigDict
The Trainer's config to check.
The Trainer ' s config to check .