TorchLean API

NN.Runtime.RL.PPO.Collect

PPO Rollout Collection (Checked Sessions) #

This file provides the rollout-collection loop used by executable PPO workflows. The key goals are:

The unified session interface lives in NN.Runtime.RL.Session (Session.CheckedSession). The lower-level Gymnasium subprocess protocol is implemented in NN.Runtime.RL.Gymnasium.

References:

Rollout collection (ergonomic core API) #

def Runtime.RL.PPO.collect {α : Type} [TorchLean.Storage α] [Context α] {obsShape : Spec.Shape} {nActions horizon : ℕ} [NeZero horizon] [NeZero nActions] (session : Session.CheckedSession obsShape nActions) (castObservation castReward : Float → α) (predictLogits : TorchLean.Tensor α obsShape → TorchLean.Tensor α [nActions]) (predictValue : TorchLean.Tensor α obsShape → α) (rngSeed rngCounter : ℕ) :
IO (Rollout α obsShape nActions horizon × ℕ)

Collect a fixed-horizon rollout from any stateful environment session that can produce fully-observed, contract-checked transitions.

The caller provides:

  • session: initialization, observation, and checked stepping for the environment,
  • castObservation to inject host Float observations into the chosen scalar backend α,
  • castReward to inject host Float rewards into the chosen scalar backend α,
  • predictLogits for the current actor,
  • predictValue for the current critic (returns a scalar α).

The API supports the “typed graph + parameters” calling convention used throughout TorchLean. Stored log-probabilities use logSoftmax without clamping. When using this rollout with Autograd.PPO.objective, selected log-probabilities must lie inside its [-10^30, 10^30] clamp and the policy reductions must agree for identical parameters to yield a unit ratio.

Instances For

    Rollout collection from Gymnasium (subprocess bridge) #

    def Runtime.RL.PPO.collectRolloutFromGymnasium {α : Type} [TorchLean.Storage α] [Context α] {obsShape : Spec.Shape} {nActions horizon : ℕ} [NeZero horizon] [NeZero nActions] (castObservation castReward : Float → α) (gym : Gymnasium.Client obsShape nActions) (predictLogits : TorchLean.Tensor α obsShape → TorchLean.Tensor α [nActions]) (predictValue : TorchLean.Tensor α obsShape → α) (rngSeed rngCounter resetSeed : ℕ) :
    IO (Rollout α obsShape nActions horizon × ℕ)

    Collect a fixed-horizon rollout from a Gymnasium subprocess environment.

    This specializes collect to Gymnasium.Session.

    Instances For