Example #1
0
    def _make_workers(self, env_creator, policy, config, num_workers):
        """Default factory method for a WorkerSet running under this Trainer.

        Override this method by passing a custom `make_workers` into
        `build_trainer`.

        Args:
            env_creator (callable): A function that return and Env given an env
                config.
            policy (class): The Policy class to use for creating the policies
                of the workers.
            config (dict): The Trainer's config.
            num_workers (int): Number of remote rollout workers to create.
                0 for local only.
            remote_config_updates (Optional[List[dict]]): A list of config
                dicts to update `config` with for each Worker (len must be
                same as `num_workers`).

        Returns:
            WorkerSet: The created WorkerSet.
        """
        return WorkerSet(env_creator,
                         policy,
                         config,
                         num_workers=num_workers,
                         logdir=self.logdir)
Example #2
0
        def _init(self, config: TrainerConfigDict, env_creator: EnvCreator):

            # No `get_policy_class` function.
            if get_policy_class is None:
                # Default_policy must be provided (unless in multi-agent mode,
                # where each policy can have its own default policy class).
                if not config["multiagent"]["policies"]:
                    assert default_policy is not None
            # Query the function for a class to use.
            else:
                self._policy_class = get_policy_class(config)
                # If None returned, use default policy (must be provided).
                if self._policy_class is None:
                    assert default_policy is not None
                    self._policy_class = default_policy

            if before_init:
                before_init(self)

            # Creating all workers (excluding evaluation workers).
            self.workers = WorkerSet(
                env_creator=env_creator,
                validate_env=validate_env,
                policy_class=self._policy_class,
                trainer_config=config,
                num_workers=self.config["num_workers"],
            )

            self.train_exec_impl = self.execution_plan(
                self.workers, config, **self._kwargs_for_execution_plan())

            if after_init:
                after_init(self)
Example #3
0
 def _make_workers(self, env_creator, policy, config, num_workers):
     return WorkerSet(
         env_creator,
         policy,
         config,
         num_workers=num_workers,
         logdir=self.logdir)
Example #4
0
 def __init__(self, num_sets, env_creator, policy, trainer_config=None,
              num_workers_per_set=0, logdir=None, _setup=True):
     self._worker_sets = {}
     for i in range(num_sets):
         self._worker_sets[i] = WorkerSet(
             env_creator, policy, trainer_config, num_workers_per_set,
             logdir, _setup)