pub struct SparseAdam { /* private fields */ }Expand description
Sparse Adam optimizer
A variant of Adam that handles sparse gradients more efficiently by only updating the parameters that have non-zero gradients.
Implementations§
Source§impl SparseAdam
impl SparseAdam
Sourcepub fn new(
params: Vec<Arc<RwLock<Tensor>>>,
lr: Option<f32>,
beta1: Option<f32>,
beta2: Option<f32>,
eps: Option<f32>,
weight_decay: Option<f32>,
) -> Self
pub fn new( params: Vec<Arc<RwLock<Tensor>>>, lr: Option<f32>, beta1: Option<f32>, beta2: Option<f32>, eps: Option<f32>, weight_decay: Option<f32>, ) -> Self
Create a new SparseAdam optimizer
§Arguments
params- Parameters to optimizelr- Learning rate (default: 1e-3)beta1- First moment decay rate (default: 0.9)beta2- Second moment decay rate (default: 0.999)eps- Small constant for numerical stability (default: 1e-8)weight_decay- Weight decay (L2 penalty) (default: 0.0)
Trait Implementations§
Source§impl Optimizer for SparseAdam
impl Optimizer for SparseAdam
Source§fn step(&mut self) -> OptimizerResult<()>
fn step(&mut self) -> OptimizerResult<()>
Perform a single optimization step
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 SparseAdam
impl !UnwindSafe for SparseAdam
impl Freeze for SparseAdam
impl Send for SparseAdam
impl Sync for SparseAdam
impl Unpin for SparseAdam
impl UnsafeUnpin for SparseAdam
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