pub struct GradientClipper<T> { /* private fields */ }Expand description
Advanced gradient clipping system with adaptive scaling
Implementations§
Source§impl<T> GradientClipper<T>
impl<T> GradientClipper<T>
Sourcepub fn new(config: GradientClippingConfig) -> Self
pub fn new(config: GradientClippingConfig) -> Self
Create a new gradient clipper with the specified configuration
Sourcepub fn default_stable() -> Self
pub fn default_stable() -> Self
Create a gradient clipper with default settings for stable training
Sourcepub fn default_adaptive() -> Self
pub fn default_adaptive() -> Self
Create a gradient clipper with adaptive scaling for dynamic adjustment
Sourcepub fn add_parameter_group(&mut self, group_name: String, threshold: f64)
pub fn add_parameter_group(&mut self, group_name: String, threshold: f64)
Add a parameter group with its own clipping threshold
Sourcepub fn clip_gradients(&mut self, gradients: &mut [Tensor<T>]) -> Result<f64>
pub fn clip_gradients(&mut self, gradients: &mut [Tensor<T>]) -> Result<f64>
Clip gradients using global norm clipping
This is the main method for applying gradient clipping. It computes the global gradient norm across all tensors and scales them proportionally if needed.
Sourcepub fn clip_parameter_group(
&mut self,
group_name: &str,
gradients: &mut [Tensor<T>],
) -> Result<f64>
pub fn clip_parameter_group( &mut self, group_name: &str, gradients: &mut [Tensor<T>], ) -> Result<f64>
Clip gradients for a specific parameter group
Sourcepub fn get_statistics(&self) -> &GradientStatistics
pub fn get_statistics(&self) -> &GradientStatistics
Get current gradient statistics
Sourcepub fn get_config(&self) -> &GradientClippingConfig
pub fn get_config(&self) -> &GradientClippingConfig
Get the current configuration
Sourcepub fn reset_statistics(&mut self)
pub fn reset_statistics(&mut self)
Reset statistics (useful for training phase transitions)
Sourcepub fn get_clipping_rate(&self) -> f64
pub fn get_clipping_rate(&self) -> f64
Get clipping rate (percentage of updates where clipping was applied)
Sourcepub fn would_clip(&self, gradients: &[Tensor<T>]) -> Result<bool>
pub fn would_clip(&self, gradients: &[Tensor<T>]) -> Result<bool>
Check if gradients would be clipped with current threshold
Auto Trait Implementations§
impl<T> Freeze for GradientClipper<T>
impl<T> RefUnwindSafe for GradientClipper<T>where
T: RefUnwindSafe,
impl<T> Send for GradientClipper<T>where
T: Send,
impl<T> Sync for GradientClipper<T>where
T: Sync,
impl<T> Unpin for GradientClipper<T>where
T: Unpin,
impl<T> UnsafeUnpin for GradientClipper<T>
impl<T> UnwindSafe for GradientClipper<T>where
T: UnwindSafe,
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
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>
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>
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