Skip to main content

Module loss

Module loss 

Source
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 no Kind::Float argument, 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_f64 which detaches implicitly via .into_scalar(); no explicit no_grad scope 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.