pub struct GradientMonitor {
pub gradient_norms: Vec<f64>,
pub gradient_means: Vec<f64>,
pub gradient_stds: Vec<f64>,
pub vanishing_count: usize,
pub exploding_count: usize,
/* private fields */
}Expand description
Gradient flow monitor for tracking gradient statistics during training.
This callback tracks gradient norms, mean, std, and identifies vanishing/exploding gradients. Useful for debugging training issues and understanding gradient flow through the network.
§Example
ⓘ
use tensorlogic_train::{GradientMonitor, CallbackList};
let mut callbacks = CallbackList::new();
callbacks.add(Box::new(GradientMonitor::new(
10, // log_frequency
1e-7, // vanishing_threshold
100.0, // exploding_threshold
)));Fields§
§gradient_norms: Vec<f64>History of gradient norms.
gradient_means: Vec<f64>History of gradient means.
gradient_stds: Vec<f64>History of gradient stds.
vanishing_count: usizeCount of vanishing gradient warnings.
exploding_count: usizeCount of exploding gradient warnings.
Implementations§
Source§impl GradientMonitor
impl GradientMonitor
Sourcepub fn new(
log_frequency: usize,
vanishing_threshold: f64,
exploding_threshold: f64,
) -> Self
pub fn new( log_frequency: usize, vanishing_threshold: f64, exploding_threshold: f64, ) -> Self
Create a new gradient monitor.
§Arguments
log_frequency- Log statistics every N batchesvanishing_threshold- Threshold below which gradients are considered vanishingexploding_threshold- Threshold above which gradients are considered exploding
Sourcepub fn summary(&self) -> GradientSummary
pub fn summary(&self) -> GradientSummary
Get summary statistics.
Trait Implementations§
Source§impl Callback for GradientMonitor
impl Callback for GradientMonitor
Source§fn on_batch_end(
&mut self,
_batch: usize,
state: &TrainingState,
) -> TrainResult<()>
fn on_batch_end( &mut self, _batch: usize, state: &TrainingState, ) -> TrainResult<()>
Called at the end of a batch.
Source§fn on_train_end(&mut self, _state: &TrainingState) -> TrainResult<()>
fn on_train_end(&mut self, _state: &TrainingState) -> TrainResult<()>
Called at the end of training.
Source§fn on_train_begin(&mut self, _state: &TrainingState) -> TrainResult<()>
fn on_train_begin(&mut self, _state: &TrainingState) -> TrainResult<()>
Called at the beginning of training.
Source§fn on_epoch_begin(
&mut self,
_epoch: usize,
_state: &TrainingState,
) -> TrainResult<()>
fn on_epoch_begin( &mut self, _epoch: usize, _state: &TrainingState, ) -> TrainResult<()>
Called at the beginning of an epoch.
Source§fn on_epoch_end(
&mut self,
_epoch: usize,
_state: &TrainingState,
) -> TrainResult<()>
fn on_epoch_end( &mut self, _epoch: usize, _state: &TrainingState, ) -> TrainResult<()>
Called at the end of an epoch.
Source§fn on_batch_begin(
&mut self,
_batch: usize,
_state: &TrainingState,
) -> TrainResult<()>
fn on_batch_begin( &mut self, _batch: usize, _state: &TrainingState, ) -> TrainResult<()>
Called at the beginning of a batch.
Source§fn on_validation_end(&mut self, _state: &TrainingState) -> TrainResult<()>
fn on_validation_end(&mut self, _state: &TrainingState) -> TrainResult<()>
Called after validation.
Source§fn should_stop(&self) -> bool
fn should_stop(&self) -> bool
Check if training should stop early.
Auto Trait Implementations§
impl Freeze for GradientMonitor
impl RefUnwindSafe for GradientMonitor
impl Send for GradientMonitor
impl Sync for GradientMonitor
impl Unpin for GradientMonitor
impl UnwindSafe for GradientMonitor
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