pub struct SparseAdam { /* private fields */ }Expand description
Sparse / lazy Adam optimizer over a 1-D dense parameter vector.
Per-coordinate moment state (m, v) and last_step are stored densely
(Adam always needs one moment pair per parameter) but are only read and
written for coordinates that carry a gradient on a given step, which is what
makes the step cost proportional to the number of non-zero coordinates.
Implementations§
Source§impl SparseAdam
impl SparseAdam
Sourcepub fn new(config: SparseAdamConfig) -> Self
pub fn new(config: SparseAdamConfig) -> Self
Create a new optimizer. State is allocated lazily on the first
SparseAdam::step from the length of the parameter vector.
Sourcepub fn global_step(&self) -> usize
pub fn global_step(&self) -> usize
The number of optimizer steps performed so far (the global t).
Sourcepub fn config(&self) -> &SparseAdamConfig
pub fn config(&self) -> &SparseAdamConfig
Immutable view of the configuration.
Sourcepub fn step(
&mut self,
params: &mut Array1<f64>,
grad: &CooGradient,
) -> Result<(), GpuOptimError>
pub fn step( &mut self, params: &mut Array1<f64>, grad: &CooGradient, ) -> Result<(), GpuOptimError>
Perform one sparse Adam update in place, touching only the coordinates
present in grad.
§Errors
Returns GpuOptimError::DimensionMismatch when the parameter length and
the gradient dimension disagree (or differ from a previous step), and
propagates validation errors from a malformed gradient.
Trait Implementations§
Source§impl Clone for SparseAdam
impl Clone for SparseAdam
Source§fn clone(&self) -> SparseAdam
fn clone(&self) -> SparseAdam
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreAuto Trait Implementations§
impl Freeze for SparseAdam
impl RefUnwindSafe for SparseAdam
impl Send for SparseAdam
impl Sync for SparseAdam
impl Unpin for SparseAdam
impl UnsafeUnpin for SparseAdam
impl UnwindSafe 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
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
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