Skip to main content

Sgd

Struct Sgd 

Source
pub struct Sgd { /* private fields */ }

Implementations§

Source§

impl Sgd

Source

pub fn new( parameters: impl IntoIterator<Item = Parameter>, learning_rate: f32, momentum: f32, weight_decay: f32, ) -> Result<Self>

Bind SGD to a nonempty FP32 parameter set.

A positive momentum coefficient allocates one zero-initialized momentum tensor per parameter. Weight decay follows the donor kernels exactly.

§Errors

Returns an error for invalid hyperparameters, duplicate parameters, mixed-runtime ownership, or momentum allocation/upload failure.

Source

pub fn new_with_groups( groups: Vec<ParameterGroup>, learning_rate: f32, momentum: f32, weight_decay: f32, ) -> Result<Self>

Bind SGD over named parameter groups with differential treatment, following the AdamW contract: lr_scale multiplies the base learning rate, weight_decay replaces the optimizer default per group (Some(0.0) excludes members), and frozen groups skip value and momentum updates entirely.

§Errors

Returns the construction errors of the uniform constructor plus overlapping membership, empty groups, and invalid group scales.

Source

pub fn zero_grad(&self)

Discard every currently accumulated parameter gradient.

Source

pub fn step(&mut self) -> Result<()>

Record one SGD update for every parameter carrying a gradient.

§Errors

Returns an error when the step counter is exhausted, a parameter contract changed, or runtime recording fails.

Source

pub const fn learning_rate(&self) -> f32

Return the learning rate used by the next step.

Source

pub fn set_learning_rate(&mut self, learning_rate: f32) -> Result<()>

Set the learning rate used by subsequent steps.

§Errors

Returns an error when the value is not finite and non-negative.

Source

pub const fn step_count(&self) -> u64

Return the number of completed logical steps.

Trait Implementations§

Source§

impl Optimizer for Sgd

Source§

fn zero_grad(&self)

Discard every currently accumulated parameter gradient.
Source§

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

Record one logical parameter update. Read more
Source§

fn learning_rate(&self) -> f32

Return the learning rate used by the next optimizer step.
Source§

fn set_learning_rate(&mut self, learning_rate: f32) -> Result<()>

Set the learning rate used by subsequent optimizer steps. Read more
Source§

fn step_count(&self) -> u64

Return the number of completed logical optimizer steps.
Source§

fn belongs_to(&self, runtime: &Runtime) -> bool

Return whether this optimizer can participate in work owned by runtime.
Source§

fn set_finite_gate(&mut self, flag: &Matrix) -> Result<()>

Bind a device-resident finite flag gating captured updates. Read more

Auto Trait Implementations§

§

impl !RefUnwindSafe for Sgd

§

impl !Send for Sgd

§

impl !Sync for Sgd

§

impl !UnwindSafe for Sgd

§

impl Forget for Sgd

§

impl Freeze for Sgd
where *const u8 is !null: Freeze, PhantomData<SgdParameterState>: Freeze, PhantomData<usize>: Freeze, PhantomData<SgdGroupMeta>: Freeze,

§

impl Move for Sgd

§

impl Unpin for Sgd
where *const u8 is !null: Unpin, Rc<RefCell<ParameterState>>: Unpin, Rc<RefCell<RuntimeState>>: Unpin, Rc<StorageInner>: Unpin, Rc<MatrixSemantic>: Unpin, Rc<()>: Unpin,

§

impl UnsafeUnpin for Sgd
where *const u8 is !null: UnsafeUnpin, PhantomData<SgdParameterState>: UnsafeUnpin, PhantomData<usize>: UnsafeUnpin, PhantomData<SgdGroupMeta>: UnsafeUnpin,

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> CheckpointOptimizer for T
where T: Optimizer + Persistence,

Source§

impl<S, T> Duplex<S> for T
where T: FromSample<S> + ToSample<S>,

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<S> FromSample<S> for S

Source§

fn from_sample_(s: S) -> S

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<F, T> IntoSample<T> for F
where T: FromSample<F>,

Source§

fn into_sample(self) -> T

Source§

impl<T> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T, U> ToSample<U> for T
where U: FromSample<T>,

Source§

fn to_sample_(self) -> U

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

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.