pub struct Adam {
pub learning_rate: f32,
pub betas: (f32, f32),
pub eps: f32,
pub weight_decay: f32,
pub amsgrad: bool,
pub m: Vec<Tensor>,
pub v: Vec<Tensor>,
pub vm: Vec<Tensor>,
pub t: usize,
}Expand description
§Adaptive momentum estimation optimizer
Fields§
§learning_rate: f32learning rate (default: 1e-3)
betas: (f32, f32)coefficients used for computing running averages of gradient and its square (default: (0.9, 0.999))
eps: f32term added to the denominator to improve numerical stability (default: 1e-8)
weight_decay: f32weight decay (L2 penalty) (default: 0)
amsgrad: boolwhether to use the AMSGrad variant of this algorithm from the paper On the Convergence of Adam and Beyond (default: false)
m: Vec<Tensor>m
v: Vec<Tensor>v
vm: Vec<Tensor>vm
t: usizet
Implementations§
Source§impl Adam
impl Adam
Sourcepub fn update<'a>(
&mut self,
parameters: impl IntoIterator<Item = &'a mut Tensor>,
gradients: impl IntoIterator<Item = Tensor>,
)
pub fn update<'a>( &mut self, parameters: impl IntoIterator<Item = &'a mut Tensor>, gradients: impl IntoIterator<Item = Tensor>, )
Updates parameters with gradients. Number of parameters must be the same as number of gradients. Gradients can be None, those are simply skipped.
Trait Implementations§
Source§impl<'a> IntoIterator for &'a Adam
impl<'a> IntoIterator for &'a Adam
Source§impl<'a> IntoIterator for &'a mut Adam
impl<'a> IntoIterator for &'a mut Adam
Source§impl Module for Adam
impl Module for Adam
Source§fn iter_mut<'a>(&'a mut self) -> impl Iterator<Item = &'a mut Tensor>
fn iter_mut<'a>(&'a mut self) -> impl Iterator<Item = &'a mut Tensor>
Iterate over all tensors mutably
Source§fn iter_tensors<'a>(&'a self) -> impl Iterator<Item = (String, &'a Tensor)>
fn iter_tensors<'a>(&'a self) -> impl Iterator<Item = (String, &'a Tensor)>
Iterate over tensors without consuming the module
Source§fn iter_tensors_mut<'a>(
&'a mut self,
) -> impl Iterator<Item = (String, &'a mut Tensor)>
fn iter_tensors_mut<'a>( &'a mut self, ) -> impl Iterator<Item = (String, &'a mut Tensor)>
From tensors
Source§fn set_params(&mut self, params: &mut HashMap<String, Tensor>)
fn set_params(&mut self, params: &mut HashMap<String, Tensor>)
Set parameters, removes them from params, skips parameters that are not found in params.
Source§fn save(&self, path: impl AsRef<Path>) -> Result<(), ZyxError>
fn save(&self, path: impl AsRef<Path>) -> Result<(), ZyxError>
Save tensors or modules to a file determined by file extension.
Currently only safetensors is supported format. Read more
Source§fn save_numpy(&self, path: impl AsRef<Path>) -> Result<(), ZyxError>
fn save_numpy(&self, path: impl AsRef<Path>) -> Result<(), ZyxError>
Save a single tensor to a
.npy file (numpy array format).
Mirrors load_numpy: little-endian, C order (Fortran order
is never written). Header is padded so data starts at a 64-byte
boundary, like numpy >= 1.9. Numpy files hold a single array, so
saving a module with more than one tensor is an error. Read moreAuto Trait Implementations§
impl Freeze for Adam
impl RefUnwindSafe for Adam
impl Send for Adam
impl Sync for Adam
impl Unpin for Adam
impl UnsafeUnpin for Adam
impl UnwindSafe for Adam
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