Skip to main content

SacConfig

Struct SacConfig 

Source
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: f64

Adam learning rate for the stochastic actor.

§critic_lr: f64

Adam learning rate for both online critics (q1, q2).

§alpha_lr: f64

Adam learning rate for the entropy temperature log_alpha. Only used when Self::auto_alpha is true.

§gamma: f64

Discount factor used in the critic TD target.

§tau: f64

Polyak (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: usize

Number of transitions sampled per gradient update.

§buffer_capacity: usize

Maximum number of transitions stored in the replay buffer. Older transitions are evicted FIFO once capacity is reached.

§min_buffer_size: usize

Minimum number of transitions required before the first gradient update. Until the buffer holds this many transitions the trainer only collects experience.

§learning_starts: usize

Number of environment steps for which actions are drawn uniformly at random (pure exploration) before the actor starts choosing actions.

§gradient_steps_per_env_step: usize

Number of gradient updates performed per environment step (the update-to-data ratio).

§hidden_dim: usize

Width of every hidden layer in the actor and critics.

§num_hidden_layers: usize

Number of hidden layers in the actor and critic trunks.

§auto_alpha: bool

Automatically 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: f32

Initial 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: u64

Seed threaded through replay sampling, actor noise sampling, and seeded network init for bit-exact reproducibility.

Implementations§

Source§

impl SacConfig

Source

pub fn new() -> Self

Create a new default configuration.

Source

pub fn validate(&self) -> Result<()>

Validate configuration parameters.

Returns an Err describing the first invalid field encountered.

Source

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.

Source

pub fn actor_lr(self, lr: f64) -> Self

Set the actor learning rate.

Source

pub fn critic_lr(self, lr: f64) -> Self

Set the critic learning rate (applied to both online critics).

Source

pub fn alpha_lr(self, lr: f64) -> Self

Set the entropy-temperature learning rate.

Source

pub fn gamma(self, gamma: f64) -> Self

Set the discount factor gamma.

Source

pub fn tau(self, tau: f64) -> Self

Set the Polyak soft-update coefficient tau.

Source

pub fn batch_size(self, size: usize) -> Self

Set the minibatch size.

Source

pub fn buffer_capacity(self, capacity: usize) -> Self

Set the replay buffer capacity.

Source

pub fn min_buffer_size(self, size: usize) -> Self

Set the minimum buffer size before the first gradient update.

Source

pub fn learning_starts(self, steps: usize) -> Self

Set the number of random-action warmup steps.

Source

pub fn gradient_steps_per_env_step(self, steps: usize) -> Self

Set the number of gradient updates per environment step.

Source

pub fn hidden_dim(self, dim: usize) -> Self

Set the hidden-layer width for the actor and critics.

Source

pub fn num_hidden_layers(self, layers: usize) -> Self

Set the number of hidden layers for the actor and critics.

Source

pub fn auto_alpha(self, enabled: bool) -> Self

Enable or disable automatic entropy-temperature tuning.

Source

pub fn init_alpha(self, alpha: f32) -> Self

Set the initial (or fixed) entropy temperature alpha.

Source

pub fn target_entropy(self, entropy: f32) -> Self

Set an explicit target entropy, overriding the -action_dim heuristic.

Source

pub fn max_grad_norm(self, norm: f64) -> Self

Enable global gradient-norm clipping with the given cap.

Source

pub fn seed(self, seed: u64) -> Self

Set the reproducibility seed.

Trait Implementations§

Source§

impl Clone for SacConfig

Source§

fn clone(&self) -> SacConfig

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for SacConfig

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for SacConfig

Source§

fn default() -> Self

Returns the “default value” for a type. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts 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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts 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
Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more