pub struct MixedPrecisionManager<F: Float + Debug + ScalarOperand + FromPrimitive + Send + Sync + Display, LF: Float + Debug + ScalarOperand + Send + Sync> {
pub config: MixedPrecisionConfig,
/* private fields */
}
Expand description
Mixed precision training manager
Fields§
§config: MixedPrecisionConfig
Configuration for mixed precision training
Implementations§
Source§impl<F: Float + Debug + ScalarOperand + FromPrimitive + Send + Sync + Display, LF: Float + Debug + ScalarOperand + Send + Sync> MixedPrecisionManager<F, LF>
impl<F: Float + Debug + ScalarOperand + FromPrimitive + Send + Sync + Display, LF: Float + Debug + ScalarOperand + Send + Sync> MixedPrecisionManager<F, LF>
Sourcepub fn new(config: MixedPrecisionConfig) -> Self
pub fn new(config: MixedPrecisionConfig) -> Self
Create a new mixed precision manager
Sourcepub fn initialize<L: Layer<F> + Clone + Send + Sync + 'static>(
&mut self,
model: &L,
) -> Result<()>
pub fn initialize<L: Layer<F> + Clone + Send + Sync + 'static>( &mut self, model: &L, ) -> Result<()>
Initialize the manager with a model
Sourcepub fn to_low_precision<L: Layer<F> + ?Sized, L2: Layer<LF> + ?Sized>(
&self,
high_precision_model: &L,
low_precision_model: &mut L2,
) -> Result<()>
pub fn to_low_precision<L: Layer<F> + ?Sized, L2: Layer<LF> + ?Sized>( &self, high_precision_model: &L, low_precision_model: &mut L2, ) -> Result<()>
Convert a model’s parameters to low precision
Sourcepub fn gradients_to_high_precision(
&mut self,
low_precision_gradients: &[Array<LF, IxDyn>],
) -> Result<Vec<Array<F, IxDyn>>>
pub fn gradients_to_high_precision( &mut self, low_precision_gradients: &[Array<LF, IxDyn>], ) -> Result<Vec<Array<F, IxDyn>>>
Convert gradients from low to high precision
Sourcepub fn train_step<LM: Layer<LF> + ?Sized, HM: Layer<F> + ParamLayer<F> + ?Sized, O: Optimizer<F> + OptimizerStep<F>>(
&mut self,
low_precision_model: &mut LM,
high_precision_model: &mut HM,
optimizer: &mut O,
inputs: &Array<F, IxDyn>,
targets: &Array<F, IxDyn>,
loss_fn: &dyn Loss<F>,
) -> Result<F>
pub fn train_step<LM: Layer<LF> + ?Sized, HM: Layer<F> + ParamLayer<F> + ?Sized, O: Optimizer<F> + OptimizerStep<F>>( &mut self, low_precision_model: &mut LM, high_precision_model: &mut HM, optimizer: &mut O, inputs: &Array<F, IxDyn>, targets: &Array<F, IxDyn>, loss_fn: &dyn Loss<F>, ) -> Result<F>
Train a step with mixed precision
Sourcepub fn get_loss_scale(&self) -> F
pub fn get_loss_scale(&self) -> F
Get the current loss scale
Sourcepub fn get_success_counter(&self) -> usize
pub fn get_success_counter(&self) -> usize
Get the number of consecutive successful steps
Sourcepub fn overflow_occurred(&self) -> bool
pub fn overflow_occurred(&self) -> bool
Check if overflow occurred in the last step
Sourcepub fn train_epoch<LM: Layer<LF> + ?Sized, HM: ParamLayer<F> + ?Sized, O: Optimizer<F>, D: Dataset<F> + Clone>(
&mut self,
low_precision_model: &mut LM,
high_precision_model: &mut HM,
optimizer: &mut O,
dataset: &D,
loss_fn: &dyn Loss<F>,
batch_size: usize,
shuffle: bool,
) -> Result<(F, usize)>
pub fn train_epoch<LM: Layer<LF> + ?Sized, HM: ParamLayer<F> + ?Sized, O: Optimizer<F>, D: Dataset<F> + Clone>( &mut self, low_precision_model: &mut LM, high_precision_model: &mut HM, optimizer: &mut O, dataset: &D, loss_fn: &dyn Loss<F>, batch_size: usize, shuffle: bool, ) -> Result<(F, usize)>
Train for one epoch with mixed precision
Auto Trait Implementations§
impl<F, LF> Freeze for MixedPrecisionManager<F, LF>where
F: Freeze,
impl<F, LF> !RefUnwindSafe for MixedPrecisionManager<F, LF>
impl<F, LF> Send for MixedPrecisionManager<F, LF>
impl<F, LF> Sync for MixedPrecisionManager<F, LF>
impl<F, LF> Unpin for MixedPrecisionManager<F, LF>where
F: Unpin,
impl<F, LF> !UnwindSafe for MixedPrecisionManager<F, LF>
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> 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