pub enum LossScaler {
None,
Static {
scale: f32,
},
Dynamic {
scale: f32,
growth_factor: f32,
backoff_factor: f32,
growth_interval: usize,
steps_since_overflow: usize,
},
}Expand description
Loss scaling strategy for mixed precision training.
Variants§
None
No loss scaling (not recommended for FP16)
Static
Static loss scaling with fixed scale factor
Dynamic
Dynamic loss scaling that adjusts based on gradient overflow
Implementations§
Source§impl LossScaler
impl LossScaler
Sourcepub fn static_scale(scale: f32) -> Self
pub fn static_scale(scale: f32) -> Self
Creates a static loss scaler.
Sourcepub fn dynamic(
initial_scale: f32,
growth_factor: f32,
growth_interval: usize,
) -> Self
pub fn dynamic( initial_scale: f32, growth_factor: f32, growth_interval: usize, ) -> Self
Creates a dynamic loss scaler with typical defaults.
§Arguments
initial_scale- Starting scale (typically 2^15 = 32768)growth_factor- How much to grow scale (typically 2.0)growth_interval- Steps before growing (typically 2000)
Sourcepub fn scale_loss(&self, loss: f32) -> f32
pub fn scale_loss(&self, loss: f32) -> f32
Scales a loss value.
Sourcepub fn unscale_gradients(&self, gradients: &mut Array2<f32>)
pub fn unscale_gradients(&self, gradients: &mut Array2<f32>)
Unscales gradients (divides by scale).
Trait Implementations§
Source§impl Clone for LossScaler
impl Clone for LossScaler
Source§fn clone(&self) -> LossScaler
fn clone(&self) -> LossScaler
Returns a duplicate of the value. Read more
1.0.0 · 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 LossScaler
impl Debug for LossScaler
Source§impl<'de> Deserialize<'de> for LossScaler
impl<'de> Deserialize<'de> for LossScaler
Source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
Deserialize this value from the given Serde deserializer. Read more
Auto Trait Implementations§
impl Freeze for LossScaler
impl RefUnwindSafe for LossScaler
impl Send for LossScaler
impl Sync for LossScaler
impl Unpin for LossScaler
impl UnwindSafe for LossScaler
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
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
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