pub struct RecurrentPPOTrainer<B, P, O>{ /* private fields */ }Expand description
Recurrent PPO trainer (Burn backend).
Generic over the same three parameters as
crate::train::ppo::trainer::PPOTrainerBurn:
B: AutodiffBackend— the Burn backend.P: AutodiffModule<B>— the recurrent policy module (e.g.crate::policy::lstm::LstmBurnPolicy).O: Optimizer<P, B>— the Burn optimizer.
The policy is held in Option<P> because Burn’s Optimizer::step consumes
the module by value; we .take() / put-back across each gradient step.
Implementations§
Source§impl<B, P, O> RecurrentPPOTrainer<B, P, O>
impl<B, P, O> RecurrentPPOTrainer<B, P, O>
Sourcepub fn new(
config: PPOConfig,
policy: P,
optimizer: BurnOptimizer<B, P, O>,
device: B::Device,
) -> Result<Self>
pub fn new( config: PPOConfig, policy: P, optimizer: BurnOptimizer<B, P, O>, device: B::Device, ) -> Result<Self>
Build a new recurrent PPO trainer.
device is the Burn device the sequence-batch tensors are
materialized on (the buffer stores host Vec data, so — unlike the
feedforward trainer, which reads the device off the observation tensor
passed to train_step — the recurrent trainer must be told which
device to build minibatches on).
Validates the config and stages the global gradient-norm cap
(PPOConfig::max_grad_norm) on the optimizer wrapper; train_step
applies it to the gradients of every minibatch step (issue #299).
Sourcepub fn set_learning_rate(&mut self, lr: f64)
pub fn set_learning_rate(&mut self, lr: f64)
Override the learning rate used by subsequent train_step calls.
Enables caller-driven schedules (linear annealing, warmup, …). Pass the
per-update rate before each train_step. Without a call, the
optimizer’s configured rate is used.
Sourcepub fn policy(&self) -> &P
pub fn policy(&self) -> &P
Borrow the policy. Panics if called mid-step (the policy has been moved
into the optimizer); only safe between train_step invocations.
Sourcepub fn total_steps(&self) -> usize
pub fn total_steps(&self) -> usize
Total completed gradient updates.
Sourcepub fn total_episodes(&self) -> usize
pub fn total_episodes(&self) -> usize
Total completed episodes (caller increments).
Sourcepub fn increment_episodes(&mut self, n: usize)
pub fn increment_episodes(&mut self, n: usize)
Increment the episode counter.
Sourcepub fn train_step<F>(
&mut self,
buffer: &RecurrentRolloutBuffer,
envs_per_minibatch: usize,
evaluate_fn: F,
) -> Result<TrainingStats>
pub fn train_step<F>( &mut self, buffer: &RecurrentRolloutBuffer, envs_per_minibatch: usize, evaluate_fn: F, ) -> Result<TrainingStats>
Train for one recurrent PPO update.
Iterates n_epochs passes over the buffer’s env-major minibatches
(whole trajectories, envs_per_minibatch at a time), running the
rank-3 evaluate_fn forward, flattening to rank-1, and applying the
shared PPO surrogate / value / entropy losses. Mirrors
crate::train::ppo::trainer::PPOTrainerBurn::train_step step-for-step
except for the sequence-batch assembly and the rank-2 → rank-1 flatten.
buffer— the recurrent rollout buffer; advantages/returns must already be computed (viabuffer.compute_advantages).envs_per_minibatch— whole env-trajectories per minibatch (the recurrent analogue of the feedforwardbatch_size).evaluate_fn— receives(&policy, obs_seq, actions, episode_starts)and returns(log_probs, entropy, values), each[N_env, T].
Auto Trait Implementations§
impl<B, P, O> Freeze for RecurrentPPOTrainer<B, P, O>
impl<B, P, O> RefUnwindSafe for RecurrentPPOTrainer<B, P, O>where
<B as BackendTypes>::Device: RefUnwindSafe,
P: RefUnwindSafe,
O: RefUnwindSafe,
B: RefUnwindSafe,
impl<B, P, O> Send for RecurrentPPOTrainer<B, P, O>
impl<B, P, O> Sync for RecurrentPPOTrainer<B, P, O>
impl<B, P, O> Unpin for RecurrentPPOTrainer<B, P, O>
impl<B, P, O> UnsafeUnpin for RecurrentPPOTrainer<B, P, O>
impl<B, P, O> UnwindSafe for RecurrentPPOTrainer<B, P, O>
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more