pub struct GradientsParams { /* private fields */ }
Expand description

Data type that contains gradients for parameters.

Implementations§

source§

impl GradientsParams

source

pub fn new() -> Self

source

pub fn get<B, const D: usize>(&self, id: &ParamId) -> Option<Tensor<B, D>>where B: Backend,

Get the gradients for the given parameter id.

Notes

You should use remove if you want to get the gradients only one time.

source

pub fn remove<B, const D: usize>(&self, id: &ParamId) -> Option<Tensor<B, D>>where B: Backend,

Remove the gradients for the given parameter id.

source

pub fn register<B, const D: usize>(&mut self, id: ParamId, value: Tensor<B, D>)where B: Backend,

Register a gradients tensor for the given parameter id.

Notes

If a tensor is already registered for the given parameter id, it will be replaced.

source

pub fn len(&self) -> usize

The number of gradients tensors registered.

source

pub fn is_empty(&self) -> bool

If any tensor is contained.

source

pub fn to_device<B: ADBackend, M: ADModule<B>>( self, device: &B::Device, module: &M ) -> Self

Change the device of each tensor gradients registered for the given module.

source

pub fn from_grads<B: ADBackend, M: ADModule<B>>( grads: B::Gradients, module: &M ) -> Self

Extract each tensor gradients for the given module.

Trait Implementations§

source§

impl Default for GradientsParams

source§

fn default() -> GradientsParams

Returns the “default value” for a type. 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, 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