Skip to main content

AdvancedAdam

Struct AdvancedAdam 

Source
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

Source

pub fn new(lr: f64) -> Self

Create a new advanced Adam optimizer

Source

pub fn with_params(lr: f64, params: Vec<Arc<RwLock<Tensor>>>) -> Self

Create an optimizer that already owns params

Source

pub fn with_amsgrad(self) -> Self

Enable AMSGrad variant

Source

pub fn with_weight_decay(self, weight_decay: f64) -> Self

Add weight decay (L2 regularization)

Source

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.

Source

pub fn with_gradient_clipping(self, max_norm: f64) -> Self

Add gradient clipping

Source

pub fn with_warmup(self, warmup_steps: u64) -> Self

Add learning rate warmup

Trait Implementations§

Source§

impl Optimizer for AdvancedAdam

Source§

fn step(&mut self) -> OptimizerResult<()>

Perform a single optimization step
Source§

fn zero_grad(&mut self)

Zero all gradients
Source§

fn get_lr(&self) -> Vec<f32>

Get the current learning rate
Source§

fn set_lr(&mut self, lr: f32)

Set one learning rate for every parameter group (broadcast).
Source§

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>, )

Add a parameter group
Source§

fn parameters(&self) -> Vec<Arc<RwLock<Tensor>>>

Get the parameter tensors managed by this optimizer. Read more
Source§

fn state_dict(&self) -> OptimizerResult<OptimizerState>

Get state dict for serialization
Source§

fn load_state_dict(&mut self, state: OptimizerState) -> OptimizerResult<()>

Load state dict

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<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

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<O> OptimizerExt for O
where O: Optimizer,

Source§

fn distributed( self, config: DistributedConfig, ) -> OptimizerResult<DistributedOptimizer<Self>>

Wrap this optimizer with distributed functionality
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> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

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