pub struct A2cConfig {Show 13 fields
pub learning_rate: f64,
pub gamma: f64,
pub gae_lambda: f64,
pub value_coef: f64,
pub entropy_coef: f64,
pub n_steps: usize,
pub num_envs: usize,
pub max_grad_norm: f64,
pub normalize_advantages: bool,
pub use_vtrace: bool,
pub vtrace_rho_bar: f32,
pub vtrace_c_bar: f32,
pub seed: u64,
}Expand description
A2C configuration parameters.
These hyperparameters control the synchronous Advantage Actor-Critic
training process. Default values target classic discrete-control tasks
like CartPole: a single gradient update per n_steps-long rollout
collected across num_envs synchronous actors, full n-step returns
(gae_lambda = 1.0), and global gradient-norm clipping.
Fields§
§learning_rate: f64Learning rate for the shared actor-critic optimizer.
gamma: f64Discount factor (gamma).
gae_lambda: f64GAE lambda parameter. The classic A2C default of 1.0 recovers
full n-step returns (no GAE smoothing).
value_coef: f64Value function loss coefficient.
entropy_coef: f64Entropy bonus coefficient.
n_steps: usizeRollout length: number of environment steps collected per update (Mnih et al. 2016 use 5-step rollouts).
num_envs: usizeNumber of parallel synchronous actors.
max_grad_norm: f64Maximum global gradient norm for clipping.
normalize_advantages: boolWhether to normalize advantages to zero-mean/unit-variance per rollout before computing the policy loss.
use_vtrace: boolIf true, replace GAE with V-trace (Espeholt et al. 2018) for
off-policy correction. Requires that target-policy log-probs be
supplied to the rollout preprocessing step. Defaults to false,
leaving existing A2C behavior unchanged.
vtrace_rho_bar: f32V-trace rho clipping threshold (Espeholt 2018, eq. 1). Ignored when
use_vtrace = false. Typical value: 1.0 (the IMPALA paper
default).
vtrace_c_bar: f32V-trace c clipping threshold (Espeholt 2018, eq. 2). Ignored when
use_vtrace = false. Typical value: 1.0.
seed: u64Seed threaded into seeded network init (e.g.
MlpBurnConfig::with_seed)
for reproducibility. Two trainers built with the same seed
produce bit-identical initialization.
Implementations§
Source§impl A2cConfig
impl A2cConfig
Sourcepub fn validate(&self) -> Result<()>
pub fn validate(&self) -> Result<()>
Validate configuration parameters.
Returns an Err describing the first invalid field encountered.
Sourcepub fn learning_rate(self, lr: f64) -> Self
pub fn learning_rate(self, lr: f64) -> Self
Set the learning rate.
Sourcepub fn gae_lambda(self, lambda: f64) -> Self
pub fn gae_lambda(self, lambda: f64) -> Self
Set the GAE lambda parameter.
Sourcepub fn value_coef(self, coef: f64) -> Self
pub fn value_coef(self, coef: f64) -> Self
Set the value function loss coefficient.
Sourcepub fn entropy_coef(self, coef: f64) -> Self
pub fn entropy_coef(self, coef: f64) -> Self
Set the entropy bonus coefficient.
Sourcepub fn n_steps(self, steps: usize) -> Self
pub fn n_steps(self, steps: usize) -> Self
Set the rollout length (steps collected per update).
Sourcepub fn max_grad_norm(self, norm: f64) -> Self
pub fn max_grad_norm(self, norm: f64) -> Self
Set the maximum global gradient norm for clipping.
Sourcepub fn normalize_advantages(self, enabled: bool) -> Self
pub fn normalize_advantages(self, enabled: bool) -> Self
Enable or disable per-rollout advantage normalization.
Sourcepub fn use_vtrace(self, enabled: bool) -> Self
pub fn use_vtrace(self, enabled: bool) -> Self
Enable or disable V-trace off-policy correction (replaces GAE).
Sourcepub fn vtrace_rho_bar(self, rho_bar: f32) -> Self
pub fn vtrace_rho_bar(self, rho_bar: f32) -> Self
Set the V-trace rho clipping threshold (Espeholt 2018, eq. 1).
Sourcepub fn vtrace_c_bar(self, c_bar: f32) -> Self
pub fn vtrace_c_bar(self, c_bar: f32) -> Self
Set the V-trace c clipping threshold (Espeholt 2018, eq. 2).
Trait Implementations§
Auto Trait Implementations§
impl Freeze for A2cConfig
impl RefUnwindSafe for A2cConfig
impl Send for A2cConfig
impl Sync for A2cConfig
impl Unpin for A2cConfig
impl UnsafeUnpin for A2cConfig
impl UnwindSafe for A2cConfig
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> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
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