pub struct GradientsParams { /* private fields */ }Expand description
Data type that contains gradients for parameters.
Implementations§
Source§impl GradientsParams
impl GradientsParams
Sourcepub fn new() -> Self
pub fn new() -> Self
Creates a new GradientsParams.
Sourcepub fn from_grads<M: AutodiffModule>(grads: Gradients, module: &M) -> Self
pub fn from_grads<M: AutodiffModule>(grads: Gradients, module: &M) -> Self
Extract each tensor gradients for the given module.
Note: This consumes the gradients. See [‘from_module’] to extract gradients only for a specific module.
Sourcepub fn from_module<M: AutodiffModule>(grads: &mut Gradients, module: &M) -> Self
pub fn from_module<M: AutodiffModule>(grads: &mut Gradients, module: &M) -> Self
Extract each tensor gradients for the given module.
Sourcepub fn from_params<M: AutodiffModule>(
grads: &mut Gradients,
module: &M,
params: &[ParamId],
) -> Self
pub fn from_params<M: AutodiffModule>( grads: &mut Gradients, module: &M, params: &[ParamId], ) -> Self
Extract tensor gradients for the given module and given parameters.
Sourcepub fn get<const D: usize>(&self, id: ParamId) -> Option<Tensor<D>>
pub fn get<const D: usize>(&self, id: ParamId) -> Option<Tensor<D>>
Get the gradients for the given parameter id.
§Notes
You should use remove if you want to get the gradients only one time.
Sourcepub fn remove<const D: usize>(&mut self, id: ParamId) -> Option<Tensor<D>>
pub fn remove<const D: usize>(&mut self, id: ParamId) -> Option<Tensor<D>>
Remove the gradients for the given parameter id.
Sourcepub fn register<const D: usize>(&mut self, id: ParamId, value: Tensor<D>)
pub fn register<const D: usize>(&mut self, id: ParamId, value: Tensor<D>)
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.
Trait Implementations§
Source§impl Debug for GradientsParams
impl Debug for GradientsParams
Source§impl Default for GradientsParams
impl Default for GradientsParams
Source§fn default() -> GradientsParams
fn default() -> GradientsParams
Returns the “default value” for a type. Read more
Source§impl From<GradientsParams> for GradAdaptor
impl From<GradientsParams> for GradAdaptor
Source§fn from(grads: GradientsParams) -> Self
fn from(grads: GradientsParams) -> Self
Converts to this type from the input type.
Auto Trait Implementations§
impl !RefUnwindSafe for GradientsParams
impl !Sync for GradientsParams
impl !UnwindSafe for GradientsParams
impl Freeze for GradientsParams
impl Send for GradientsParams
impl Unpin for GradientsParams
impl UnsafeUnpin for GradientsParams
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
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> Downcast for Twhere
T: Any,
impl<T> Downcast for Twhere
T: Any,
Source§fn into_any(self: Box<T>) -> Box<dyn Any>
fn into_any(self: Box<T>) -> Box<dyn Any>
Converts
Box<dyn Trait> (where Trait: Downcast) to Box<dyn Any>, which can then be
downcast into Box<dyn ConcreteType> where ConcreteType implements Trait.Source§fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
Converts
Rc<Trait> (where Trait: Downcast) to Rc<Any>, which can then be further
downcast into Rc<ConcreteType> where ConcreteType implements Trait.Source§fn as_any(&self) -> &(dyn Any + 'static)
fn as_any(&self) -> &(dyn Any + 'static)
Converts
&Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &Any’s vtable from &Trait’s.Source§fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
Converts
&mut Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &mut Any’s vtable from &mut Trait’s.Source§impl<T> DowncastSend for T
impl<T> DowncastSend for T
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
Source§fn in_current_span(self) -> Instrumented<Self> ⓘ
fn in_current_span(self) -> Instrumented<Self> ⓘ
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
Converts
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
Converts
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more