pub struct Parameter { /* private fields */ }Expand description
Named trainable FP32 matrix with one live accumulated gradient.
Implementations§
Source§impl Parameter
impl Parameter
Sourcepub fn new(name: impl Into<String>, data: Matrix) -> Result<Self>
pub fn new(name: impl Into<String>, data: Matrix) -> Result<Self>
Create a trainable parameter from an existing FP32 matrix.
§Errors
Returns an error when data is not FP32.
Sourcepub fn data(&self) -> Matrix
pub fn data(&self) -> Matrix
Return a cheap handle to the current parameter storage.
AdamW updates this stable storage in place. Existing handles therefore observe later optimizer steps after the corresponding execution completes.
Sourcepub fn gradient(&self) -> Option<Matrix>
pub fn gradient(&self) -> Option<Matrix>
Return a cheap handle to the accumulated gradient, when present.
Sourcepub fn set_requires_grad(&self, requires_grad: bool)
pub fn set_requires_grad(&self, requires_grad: bool)
Enable or disable gradient accumulation for this parameter.
Sourcepub fn requires_grad(&self) -> bool
pub fn requires_grad(&self) -> bool
Return whether reverse-mode differentiation accumulates this parameter.
Sourcepub fn same_as(&self, other: &Self) -> bool
pub fn same_as(&self, other: &Self) -> bool
Return whether both handles refer to the same live parameter cell.
Sourcepub fn clear_gradient(&self)
pub fn clear_gradient(&self)
Clear any accumulated gradient without changing requires_grad.
Trait Implementations§
Auto Trait Implementations§
impl !RefUnwindSafe for Parameter
impl !Send for Parameter
impl !Sync for Parameter
impl !UnwindSafe for Parameter
impl Forget for Parameter
impl Freeze for Parameter
impl Move for Parameter
impl Unpin for Parameter
impl UnsafeUnpin for Parameterwhere
*const RcInner<RefCell<ParameterState>> is !null: UnsafeUnpin,
PhantomData<RcInner<RefCell<ParameterState>>>: UnsafeUnpin,
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