pub struct AdvancedAdam {
pub lr: f64,
pub beta1: f64,
pub beta2: f64,
pub eps: f64,
pub weight_decay: f64,
pub amsgrad: bool,
pub param_groups: Vec<ParamGroup>,
pub state: HashMap<String, AdamState>,
pub step_count: u64,
pub adaptive_lr: bool,
pub gradient_clipping: Option<f64>,
pub warmup_steps: Option<u64>,
}Expand description
Advanced Adam optimizer with SciRS2 enhancements
Fields§
§lr: f64§beta1: f64§beta2: f64§eps: f64§weight_decay: f64§amsgrad: bool§param_groups: Vec<ParamGroup>Parameter groups optimised by this instance
state: HashMap<String, AdamState>§step_count: u64§adaptive_lr: bool§gradient_clipping: Option<f64>§warmup_steps: Option<u64>Implementations§
Source§impl AdvancedAdam
impl AdvancedAdam
Sourcepub fn with_params(lr: f64, params: Vec<Arc<RwLock<Tensor>>>) -> Self
pub fn with_params(lr: f64, params: Vec<Arc<RwLock<Tensor>>>) -> Self
Create an optimizer that already owns params
Sourcepub fn with_amsgrad(self) -> Self
pub fn with_amsgrad(self) -> Self
Enable AMSGrad variant
Sourcepub fn with_weight_decay(self, weight_decay: f64) -> Self
pub fn with_weight_decay(self, weight_decay: f64) -> Self
Add weight decay (L2 regularization)
Sourcepub fn with_adaptive_lr(self) -> Self
pub fn with_adaptive_lr(self) -> Self
Enable the adaptive (inverse square-root) learning rate schedule
With this enabled the learning rate decays as sqrt(t_ref / t) once the
step count passes t_ref (the warmup length, or 1 when no warmup is
configured) — the “Noam” schedule used for transformer training.
Sourcepub fn with_gradient_clipping(self, max_norm: f64) -> Self
pub fn with_gradient_clipping(self, max_norm: f64) -> Self
Add gradient clipping
Sourcepub fn with_warmup(self, warmup_steps: u64) -> Self
pub fn with_warmup(self, warmup_steps: u64) -> Self
Add learning rate warmup
Trait Implementations§
Source§impl Optimizer for AdvancedAdam
impl Optimizer for AdvancedAdam
Source§fn step(&mut self) -> OptimizerResult<()>
fn step(&mut self) -> OptimizerResult<()>
Perform a single optimization step
Source§fn set_lrs(&mut self, lrs: &[f32])
fn set_lrs(&mut self, lrs: &[f32])
Set the learning rate of each parameter group individually. Read more
Source§fn add_param_group(
&mut self,
params: Vec<Arc<RwLock<Tensor>>>,
options: HashMap<String, f32>,
)
fn add_param_group( &mut self, params: Vec<Arc<RwLock<Tensor>>>, options: HashMap<String, f32>, )
Add a parameter group
Source§fn parameters(&self) -> Vec<Arc<RwLock<Tensor>>>
fn parameters(&self) -> Vec<Arc<RwLock<Tensor>>>
Get the parameter tensors managed by this optimizer. Read more
Source§fn state_dict(&self) -> OptimizerResult<OptimizerState>
fn state_dict(&self) -> OptimizerResult<OptimizerState>
Get state dict for serialization
Source§fn load_state_dict(&mut self, state: OptimizerState) -> OptimizerResult<()>
fn load_state_dict(&mut self, state: OptimizerState) -> OptimizerResult<()>
Load state dict
Auto Trait Implementations§
impl !RefUnwindSafe for AdvancedAdam
impl !UnwindSafe for AdvancedAdam
impl Freeze for AdvancedAdam
impl Send for AdvancedAdam
impl Sync for AdvancedAdam
impl Unpin for AdvancedAdam
impl UnsafeUnpin for AdvancedAdam
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
Mutably borrows from an owned value. Read more
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
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> ⓘ
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 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> ⓘ
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 moreSource§impl<O> OptimizerExt for Owhere
O: Optimizer,
impl<O> OptimizerExt for Owhere
O: Optimizer,
Source§fn distributed(
self,
config: DistributedConfig,
) -> OptimizerResult<DistributedOptimizer<Self>>
fn distributed( self, config: DistributedConfig, ) -> OptimizerResult<DistributedOptimizer<Self>>
Wrap this optimizer with distributed functionality