pub struct SacConfig {Show 17 fields
pub actor_lr: f64,
pub critic_lr: f64,
pub alpha_lr: f64,
pub gamma: f64,
pub tau: f64,
pub batch_size: usize,
pub buffer_capacity: usize,
pub min_buffer_size: usize,
pub learning_starts: usize,
pub gradient_steps_per_env_step: usize,
pub hidden_dim: usize,
pub num_hidden_layers: usize,
pub auto_alpha: bool,
pub init_alpha: f32,
pub target_entropy: Option<f32>,
pub max_grad_norm: Option<f64>,
pub seed: u64,
}Expand description
SAC configuration parameters.
Default values target classic Pendulum-scale continuous control:
1M-capacity replay, 256-sample batches, always-soft Polyak target
updates (tau = 0.005), automatic entropy temperature tuning, and the
3e-4 Adam learning rate the v2 paper uses for all three optimizers.
Smoke tests typically override buffer_capacity down to ~50k.
Fields§
§actor_lr: f64Adam learning rate for the stochastic actor.
critic_lr: f64Adam learning rate for both online critics (q1, q2).
alpha_lr: f64Adam learning rate for the entropy temperature log_alpha. Only
used when Self::auto_alpha is true.
gamma: f64Discount factor used in the critic TD target.
tau: f64Polyak (soft) target update coefficient tau. SAC always performs
a soft update of both target critics every gradient step:
theta_target <- tau * theta_online + (1 - tau) * theta_target.
batch_size: usizeNumber of transitions sampled per gradient update.
buffer_capacity: usizeMaximum number of transitions stored in the replay buffer. Older transitions are evicted FIFO once capacity is reached.
min_buffer_size: usizeMinimum number of transitions required before the first gradient update. Until the buffer holds this many transitions the trainer only collects experience.
learning_starts: usizeNumber of environment steps for which actions are drawn uniformly at random (pure exploration) before the actor starts choosing actions.
gradient_steps_per_env_step: usizeNumber of gradient updates performed per environment step (the update-to-data ratio).
Width of every hidden layer in the actor and critics.
Number of hidden layers in the actor and critic trunks.
auto_alpha: boolAutomatically tune the entropy temperature alpha (Haarnoja et al.
2018 v2). When true, log_alpha is optimized to drive the
policy entropy toward Self::target_entropy. When false,
alpha is held fixed at Self::init_alpha.
init_alpha: f32Initial entropy temperature alpha. When Self::auto_alpha is
false this is the fixed value used throughout training; when
true it is the starting point (log_alpha = ln(init_alpha)).
target_entropy: Option<f32>Target policy entropy for automatic temperature tuning. None
resolves to the conventional heuristic -action_dim at trainer
construction time.
max_grad_norm: Option<f64>Optional global gradient-norm clip applied to every optimizer
step. None (the SAC default) leaves the updates unclipped.
seed: u64Seed threaded through replay sampling, actor noise sampling, and seeded network init for bit-exact reproducibility.
Implementations§
Source§impl SacConfig
impl SacConfig
Sourcepub fn validate(&self) -> Result<()>
pub fn validate(&self) -> Result<()>
Validate configuration parameters.
Returns an Err describing the first invalid field encountered.
Sourcepub fn resolved_target_entropy(&self, action_dim: usize) -> f32
pub fn resolved_target_entropy(&self, action_dim: usize) -> f32
Resolve the effective target entropy for automatic temperature
tuning, applying the -action_dim heuristic when
Self::target_entropy is None.
Sourcepub fn critic_lr(self, lr: f64) -> Self
pub fn critic_lr(self, lr: f64) -> Self
Set the critic learning rate (applied to both online critics).
Sourcepub fn batch_size(self, size: usize) -> Self
pub fn batch_size(self, size: usize) -> Self
Set the minibatch size.
Sourcepub fn buffer_capacity(self, capacity: usize) -> Self
pub fn buffer_capacity(self, capacity: usize) -> Self
Set the replay buffer capacity.
Sourcepub fn min_buffer_size(self, size: usize) -> Self
pub fn min_buffer_size(self, size: usize) -> Self
Set the minimum buffer size before the first gradient update.
Sourcepub fn learning_starts(self, steps: usize) -> Self
pub fn learning_starts(self, steps: usize) -> Self
Set the number of random-action warmup steps.
Sourcepub fn gradient_steps_per_env_step(self, steps: usize) -> Self
pub fn gradient_steps_per_env_step(self, steps: usize) -> Self
Set the number of gradient updates per environment step.
Set the hidden-layer width for the actor and critics.
Set the number of hidden layers for the actor and critics.
Sourcepub fn auto_alpha(self, enabled: bool) -> Self
pub fn auto_alpha(self, enabled: bool) -> Self
Enable or disable automatic entropy-temperature tuning.
Sourcepub fn init_alpha(self, alpha: f32) -> Self
pub fn init_alpha(self, alpha: f32) -> Self
Set the initial (or fixed) entropy temperature alpha.
Sourcepub fn target_entropy(self, entropy: f32) -> Self
pub fn target_entropy(self, entropy: f32) -> Self
Set an explicit target entropy, overriding the -action_dim
heuristic.
Sourcepub fn max_grad_norm(self, norm: f64) -> Self
pub fn max_grad_norm(self, norm: f64) -> Self
Enable global gradient-norm clipping with the given cap.
Trait Implementations§
Auto Trait Implementations§
impl Freeze for SacConfig
impl RefUnwindSafe for SacConfig
impl Send for SacConfig
impl Sync for SacConfig
impl Unpin for SacConfig
impl UnsafeUnpin for SacConfig
impl UnwindSafe for SacConfig
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