pub struct SGD {
pub learning_rate: f32,
pub momentum: f32,
pub weight_decay: f32,
pub dampening: f32,
pub nesterov: bool,
pub maximize: bool,
pub bias: Vec<Tensor>,
}Expand description
§Stochastic gradient descent optimizer
Fields§
§learning_rate: f32learning rate (default: 0.001)
momentum: f32momentum factor (default: 0.0)
weight_decay: f32weight decay (L2 penalty) (default: 0.0)
dampening: f32dampening for momentum (default: 0.0)
nesterov: boolenables Nesterov momentum (default: false)
maximize: boolmaximize the objective with respect to the params, instead of minimizing (default: false)
bias: Vec<Tensor>stores momentum, starts empty and will be initialized on demand
Implementations§
Source§impl SGD
impl SGD
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 SGD
impl<'a> IntoIterator for &'a SGD
Source§impl<'a> IntoIterator for &'a mut SGD
impl<'a> IntoIterator for &'a mut SGD
Source§impl Module for SGD
impl Module for SGD
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 SGD
impl RefUnwindSafe for SGD
impl Send for SGD
impl Sync for SGD
impl Unpin for SGD
impl UnsafeUnpin for SGD
impl UnwindSafe for SGD
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