Struct tch::nn::Optimizer

source ·
pub struct Optimizer { /* private fields */ }
Expand description

An optimizer to run gradient descent.

Implementations§

source§

impl Optimizer

source

pub fn zero_grad(&mut self)

Zeroes the gradient for the tensors tracked by this optimizer.

source

pub fn clip_grad_value(&self, max: f64)

Clips gradient value at some specified maximum value.

source

pub fn clip_grad_norm(&self, max: f64)

Clips gradient L2 norm over all trainable parameters.

The norm is computed over all gradients together, as if they were concatenated into a single vector.

source

pub fn step(&mut self)

Performs an optimization step, updating the tracked tensors based on their gradients.

source

pub fn backward_step(&mut self, loss: &Tensor)

Applies a backward step pass, update the gradients, and performs an optimization step.

source

pub fn backward_step_clip(&mut self, loss: &Tensor, max: f64)

Applies a backward step pass, update the gradients, and performs an optimization step.

The gradients are clipped based on max before being applied.

source

pub fn backward_step_clip_norm(&mut self, loss: &Tensor, max: f64)

Applies a backward step pass, update the gradients, and performs an optimization step.

The gradients L2 norm is clipped based on max.

source

pub fn set_lr(&mut self, lr: f64)

Sets the optimizer learning rate.

source

pub fn set_momentum(&mut self, m: f64)

Sets the optimizer momentum.

source

pub fn set_lr_group(&mut self, group: usize, lr: f64)

Sets the optimizer learning rate for a parameter group.

source

pub fn set_momentum_group(&mut self, group: usize, m: f64)

Sets the optimizer momentum.

source

pub fn trainable_variables(&self) -> Vec<Tensor>

Returns all the trainable variables for this optimizer.

source

pub fn set_weight_decay(&mut self, weight_decay: f64)

Sets the optimizer weight decay.

source

pub fn set_weight_decay_group(&mut self, group: usize, weight_decay: f64)

Sets the optimizer weight decay.

Trait Implementations§

source§

impl Debug for Optimizer

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

Blanket Implementations§

source§

impl<T> Any for Twhere T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for Twhere T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for Twhere T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for Twhere 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<T> Same<T> for T

§

type Output = T

Should always be Self
source§

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

§

type Error = Infallible

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

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for Twhere U: TryFrom<T>,

§

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.
§

impl<V, T> VZip<V> for Twhere V: MultiLane<T>,

§

fn vzip(self) -> V