Expand description
PPO loss math (Burn backend).
After phase 5 of the Burn migration (#82), Burn is the only tensor
backend in the workspace; this module hosts the canonical PPO loss
surface used by crate::train::ppo::trainer::PPOTrainerBurn.
§API notes
- Burn’s
mean()returns a rank-1 scalar tensor — there is noKind::Floatargument, and the resulting tensor still carries the backend parameter. We expose the scalar-extracting helper (scalar_f64) that the trainer needs at the loss boundary. - Burn carries the const rank in the type, so the policy-loss / value-loss
tensors carry their concrete rank (
Tensor<B, 1>for per-row, scalar at the end). - We extract scalars via
scalar_f64which detaches implicitly via.into_scalar(); no explicitno_gradscope is needed because the autograd tape is not extended beyond the loss tensors we return.
Functions§
- compute_
entropy_ loss - Entropy loss =
-mean(entropy)(we minimize loss, so we negate the entropy bonus before adding it into the total loss). - compute_
policy_ loss - Compute PPO policy (surrogate) loss with clipping.
- compute_
value_ loss - Compute the value-function loss with optional clipping.
- generate_
minibatch_ indices - Generate randomized minibatch indices from a flat rollout buffer.
- generate_
minibatch_ indices_ with_ rng - Generate randomized minibatch indices from a flat rollout buffer using a caller-supplied RNG.
- scalar_
f64 - Read a scalar tensor’s value into an
f64.