Struct burn_core::optim::GradientsParams
source · 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 get<B, const D: usize>(&self, id: &ParamId) -> Option<Tensor<B, D>>where
B: Backend,
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.
sourcepub fn remove<B, const D: usize>(
&mut self,
id: &ParamId
) -> Option<Tensor<B, D>>where
B: Backend,
pub fn remove<B, const D: usize>( &mut self, id: &ParamId ) -> Option<Tensor<B, D>>where B: Backend,
Remove the gradients for the given parameter id.
sourcepub fn register<B, const D: usize>(&mut self, id: ParamId, value: Tensor<B, D>)where
B: Backend,
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.
sourcepub fn to_device<B: AutodiffBackend, M: AutodiffModule<B>>(
self,
device: &B::Device,
module: &M
) -> Self
pub fn to_device<B: AutodiffBackend, M: AutodiffModule<B>>( self, device: &B::Device, module: &M ) -> Self
Change the device of each tensor gradients registered for the given module.
sourcepub fn from_grads<B: AutodiffBackend, M: AutodiffModule<B>>(
grads: B::Gradients,
module: &M
) -> Self
pub fn from_grads<B: AutodiffBackend, M: AutodiffModule<B>>( grads: B::Gradients, module: &M ) -> Self
Extract each tensor gradients for the given module.
Trait Implementations§
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
Auto Trait Implementations§
impl !RefUnwindSafe for GradientsParams
impl Send for GradientsParams
impl Sync for GradientsParams
impl Unpin for GradientsParams
impl !UnwindSafe 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