rllib/execution/train_ops.py
def train_one_step(trainer, train_batch, policies_to_train=None) -> Dict:
    """Function that improves the all policies in `train_batch` on the local worker.

    Examples:
        >>> from ray.rllib.execution.rollout_ops import synchronous_parallel_sample
        >>> trainer = [...] # doctest: +SKIP
        >>> train_batch = synchronous_parallel_sample(trainer.workers) # doctest: +SKIP
        >>> # This trains the policy on one batch.
        >>> results = train_one_step(trainer, train_batch)) # doctest: +SKIP
        {"default_policy": ...}

    Updates the NUM_ENV_STEPS_TRAINED and NUM_AGENT_STEPS_TRAINED counters as well as
    the LEARN_ON_BATCH_TIMER timer of the `trainer` object.
    """

    config = trainer.config
    workers = trainer.workers
    local_worker = workers.local_worker()
    num_sgd_iter = config.get("num_sgd_iter", 1)
    sgd_minibatch_size = config.get("sgd_minibatch_size", 0)

    learn_timer = trainer._timers[LEARN_ON_BATCH_TIMER]
    with learn_timer:
        # Subsample minibatches (size=`sgd_minibatch_size`) from the
        # train batch and loop through train batch `num_sgd_iter` times.
        if num_sgd_iter > 1 or sgd_minibatch_size > 0:
            info = do_minibatch_sgd(
                train_batch,
                {
                    pid: local_worker.get_policy(pid)
                    for pid in policies_to_train
                    or local_worker.get_policies_to_train(train_batch)
                },
                local_worker,
                num_sgd_iter,
                sgd_minibatch_size,
                [],
            )
        # Single update step using train batch.
        else:
            info = local_worker.learn_on_batch(train_batch)

    learn_timer.push_units_processed(train_batch.count)
    trainer._counters[NUM_ENV_STEPS_TRAINED] += train_batch.count
    trainer._counters[NUM_AGENT_STEPS_TRAINED] += train_batch.agent_steps()

    return info
Function that improves the all policies in `train_batch` on the local worker.

    Examples:
        >>> from ray.rllib.execution.rollout_ops import synchronous_parallel_sample
        >>> trainer = [...] # doctest: +SKIP
        >>> train_batch = synchronous_parallel_sample(trainer.workers) # doctest: +SKIP
        >>> # This trains the policy on one batch.
        >>> results = train_one_step(trainer, train_batch)) # doctest: +SKIP
        {"default_policy": ...}

    Updates the NUM_ENV_STEPS_TRAINED and NUM_AGENT_STEPS_TRAINED counters as well as
    the LEARN_ON_BATCH_TIMER timer of the `trainer` object.
    
Function that improves the all policies in `train_batch` on the local worker.
Function that improves the all policies in ` train_batch ` on the local worker .
def train_one_step(trainer, train_batch, policies_to_train=None) -> Dict:
    config = trainer.config
    workers = trainer.workers
    local_worker = workers.local_worker()
    num_sgd_iter = config.get("num_sgd_iter", 1)
    sgd_minibatch_size = config.get("sgd_minibatch_size", 0)
    learn_timer = trainer._timers[LEARN_ON_BATCH_TIMER]
    with learn_timer:
        if num_sgd_iter > 1 or sgd_minibatch_size > 0:
            info = do_minibatch_sgd(
                train_batch,
                {
                    pid: local_worker.get_policy(pid)
                    for pid in policies_to_train
                    or local_worker.get_policies_to_train(train_batch)
                },
                local_worker,
                num_sgd_iter,
                sgd_minibatch_size,
                [],
            )
        else:
            info = local_worker.learn_on_batch(train_batch)
    learn_timer.push_units_processed(train_batch.count)
    trainer._counters[NUM_ENV_STEPS_TRAINED] += train_batch.count
    trainer._counters[NUM_AGENT_STEPS_TRAINED] += train_batch.agent_steps()
    return info
def train_one_step ( trainer , train_batch , policies_to_train = None ) -> Dict : config = trainer . config workers = trainer . workers local_worker = workers . local_worker ( ) num_sgd_iter = config . get ( "num_sgd_iter" , 1 ) sgd_minibatch_size = config . get ( "sgd_minibatch_size" , 0 ) learn_timer = trainer . _timers [ LEARN_ON_BATCH_TIMER ] with learn_timer : if num_sgd_iter > 1 or sgd_minibatch_size > 0 : info = do_minibatch_sgd ( train_batch , { pid : local_worker . get_policy ( pid ) for pid in policies_to_train or local_worker . get_policies_to_train ( train_batch ) } , local_worker , num_sgd_iter , sgd_minibatch_size , [ ] , ) else : info = local_worker . learn_on_batch ( train_batch ) learn_timer . push_units_processed ( train_batch . count ) trainer . _counters [ NUM_ENV_STEPS_TRAINED ] += train_batch . count trainer . _counters [ NUM_AGENT_STEPS_TRAINED ] += train_batch . agent_steps ( ) return info
Function that improves the all policies in `train_batch` on the local worker.
Function that improves the all policies in ` train_batch ` on the local worker .
"""Function that improves the all policies in `train_batch` on the local worker.

    Examples:
        >>> from ray.rllib.execution.rollout_ops import synchronous_parallel_sample
        >>> trainer = [...] # doctest: +SKIP
        >>> train_batch = synchronous_parallel_sample(trainer.workers) # doctest: +SKIP
        >>> # This trains the policy on one batch.
        >>> results = train_one_step(trainer, train_batch)) # doctest: +SKIP
        {"default_policy": ...}

    Updates the NUM_ENV_STEPS_TRAINED and NUM_AGENT_STEPS_TRAINED counters as well as
    the LEARN_ON_BATCH_TIMER timer of the `trainer` object.
    """ # Subsample minibatches (size=`sgd_minibatch_size`) from the # train batch and loop through train batch `num_sgd_iter` times. # Single update step using train batch.
trainer
train_batch
policies_to_train
examples
>>> from ray.rllib.execution.rollout_ops import synchronous_parallel_sample
>>> trainer = [...] # doctest: +SKIP
>>> train_batch = synchronous_parallel_sample(trainer.workers) # doctest: +SKIP
>>> # This trains the policy on one batch.
>>> results = train_one_step(trainer, train_batch)) # doctest: +SKIP
{"default_policy": ...}
>>> from ray . rllib . execution . rollout_ops import synchronous_parallel_sample >>> trainer = [ ... ] # doctest : + SKIP >>> train_batch = synchronous_parallel_sample ( trainer . workers ) # doctest : + SKIP >>> # This trains the policy on one batch . >>> results = train_one_step ( trainer train_batch )) # doctest : + SKIP { " default_policy " : ... }