Skip to main content

GradientClipper

Struct GradientClipper 

Source
pub struct GradientClipper<T> { /* private fields */ }
Expand description

Advanced gradient clipping system with adaptive scaling

Implementations§

Source§

impl<T> GradientClipper<T>
where T: Float + FromPrimitive + Clone + Send + Sync + Default + 'static,

Source

pub fn new(config: GradientClippingConfig) -> Self

Create a new gradient clipper with the specified configuration

Source

pub fn default_stable() -> Self

Create a gradient clipper with default settings for stable training

Source

pub fn default_adaptive() -> Self

Create a gradient clipper with adaptive scaling for dynamic adjustment

Source

pub fn add_parameter_group(&mut self, group_name: String, threshold: f64)

Add a parameter group with its own clipping threshold

Source

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.

Source

pub fn clip_parameter_group( &mut self, group_name: &str, gradients: &mut [Tensor<T>], ) -> Result<f64>

Clip gradients for a specific parameter group

Source

pub fn get_statistics(&self) -> &GradientStatistics

Get current gradient statistics

Source

pub fn get_config(&self) -> &GradientClippingConfig

Get the current configuration

Source

pub fn reset_statistics(&mut self)

Reset statistics (useful for training phase transitions)

Source

pub fn get_clipping_rate(&self) -> f64

Get clipping rate (percentage of updates where clipping was applied)

Source

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> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

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
Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V