pub enum ClippingStrategy {
GlobalNorm {
max_norm: f64,
},
PerTensorNorm {
max_norm: f64,
},
ValueClip {
min: f64,
max: f64,
},
Adaptive {
target_norm: f64,
momentum: f64,
},
}Expand description
Strategy for clipping gradients.
Variants§
GlobalNorm
Clip all gradients so that their global L2 norm is at most max_norm.
PerTensorNorm
Clip each gradient tensor independently so its L2 norm is at most max_norm.
ValueClip
Clamp every scalar value in every tensor to the range [min, max].
Adaptive
Running EMA of the global norm; clip when current norm > EMA * 1.5.
The EMA is updated as: ema = momentum * ema + (1 - momentum) * global_norm.
On the very first call the EMA is bootstrapped to the current global norm so
no spurious clipping occurs on the initial step.
Trait Implementations§
Source§impl Clone for ClippingStrategy
impl Clone for ClippingStrategy
Source§fn clone(&self) -> ClippingStrategy
fn clone(&self) -> ClippingStrategy
Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreSource§impl Debug for ClippingStrategy
impl Debug for ClippingStrategy
Source§impl PartialEq for ClippingStrategy
impl PartialEq for ClippingStrategy
Source§fn eq(&self, other: &ClippingStrategy) -> bool
fn eq(&self, other: &ClippingStrategy) -> bool
Tests for
self and other values to be equal, and is used by ==.impl StructuralPartialEq for ClippingStrategy
Auto Trait Implementations§
impl Freeze for ClippingStrategy
impl RefUnwindSafe for ClippingStrategy
impl Send for ClippingStrategy
impl Sync for ClippingStrategy
impl Unpin for ClippingStrategy
impl UnsafeUnpin for ClippingStrategy
impl UnwindSafe for ClippingStrategy
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> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
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