pub struct TensorGradientClipper {
pub strategy: ClippingStrategy,
pub stats: ClipperStats,
pub ema_norm: f64,
}Expand description
Applies gradient-clipping strategies to collections of GradientTensors.
Fields§
§strategy: ClippingStrategyThe clipping strategy in use.
stats: ClipperStatsCumulative statistics.
ema_norm: f64EMA of the global norm (used only by ClippingStrategy::Adaptive).
Implementations§
Source§impl TensorGradientClipper
impl TensorGradientClipper
Sourcepub fn new(strategy: ClippingStrategy) -> Self
pub fn new(strategy: ClippingStrategy) -> Self
Create a new clipper with the given strategy and zeroed statistics.
Sourcepub fn clip(&mut self, tensors: &mut [GradientTensor]) -> Vec<ClippingResult>
pub fn clip(&mut self, tensors: &mut [GradientTensor]) -> Vec<ClippingResult>
Apply the configured clipping strategy to tensors in-place.
Returns one ClippingResult per input tensor.
Sourcepub fn reset_stats(&mut self)
pub fn reset_stats(&mut self)
Reset all statistics and the EMA norm to their initial state.
Sourcepub fn stats(&self) -> &ClipperStats
pub fn stats(&self) -> &ClipperStats
Return a reference to the current statistics.
Auto Trait Implementations§
impl Freeze for TensorGradientClipper
impl RefUnwindSafe for TensorGradientClipper
impl Send for TensorGradientClipper
impl Sync for TensorGradientClipper
impl Unpin for TensorGradientClipper
impl UnsafeUnpin for TensorGradientClipper
impl UnwindSafe for TensorGradientClipper
Blanket Implementations§
impl<T> Allocation for T
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> 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