pub struct GradientProcessor<T: Float + Debug + Default + Clone + Sum + ScalarOperand + Send + Sync + 'static> { /* private fields */ }Expand description
Gradient processor for transformer optimizer
Implementations§
Source§impl<T: Float + Debug + Default + Clone + Sum + ScalarOperand + Send + Sync + 'static> GradientProcessor<T>
impl<T: Float + Debug + Default + Clone + Sum + ScalarOperand + Send + Sync + 'static> GradientProcessor<T>
Sourcepub fn new(strategy: GradientProcessingStrategy) -> Self
pub fn new(strategy: GradientProcessingStrategy) -> Self
Create new gradient processor
Sourcepub fn new_with_params(
strategy: GradientProcessingStrategy,
params: GradientProcessingParams<T>,
) -> Self
pub fn new_with_params( strategy: GradientProcessingStrategy, params: GradientProcessingParams<T>, ) -> Self
Create with custom parameters
Sourcepub fn process_gradients(
&mut self,
param_name: &str,
gradients: &Array1<T>,
) -> Result<Array1<T>>
pub fn process_gradients( &mut self, param_name: &str, gradients: &Array1<T>, ) -> Result<Array1<T>>
Process gradients according to the selected strategy.
param_name selects the per-parameter state slot; callers that only have a
single parameter tensor may pass any stable identifier.
Sourcepub fn statistics(&self) -> &GradientStatistics<T>
pub fn statistics(&self) -> &GradientStatistics<T>
Get aggregate gradient statistics
Sourcepub fn statistics_for(&self, param_name: &str) -> Option<&GradientStatistics<T>>
pub fn statistics_for(&self, param_name: &str) -> Option<&GradientStatistics<T>>
Get gradient statistics for a specific parameter
Sourcepub fn strategy(&self) -> GradientProcessingStrategy
pub fn strategy(&self) -> GradientProcessingStrategy
Get the current processing strategy
Sourcepub fn parameters(&self) -> &GradientProcessingParams<T>
pub fn parameters(&self) -> &GradientProcessingParams<T>
Get the current processing parameters
Sourcepub fn set_strategy(&mut self, strategy: GradientProcessingStrategy)
pub fn set_strategy(&mut self, strategy: GradientProcessingStrategy)
Update processing strategy
Sourcepub fn set_parameters(&mut self, params: GradientProcessingParams<T>)
pub fn set_parameters(&mut self, params: GradientProcessingParams<T>)
Update processing parameters
Trait Implementations§
Auto Trait Implementations§
impl<T> Freeze for GradientProcessor<T>where
HashMap<String, PerParameterState<T>>: Freeze,
GradientStatistics<T>: Freeze,
GradientProcessingParams<T>: Freeze,
impl<T> RefUnwindSafe for GradientProcessor<T>where
HashMap<String, PerParameterState<T>>: RefUnwindSafe,
GradientStatistics<T>: RefUnwindSafe,
GradientProcessingParams<T>: RefUnwindSafe,
impl<T> Send for GradientProcessor<T>where
HashMap<String, PerParameterState<T>>: Send,
GradientStatistics<T>: Send,
GradientProcessingParams<T>: Send,
impl<T> Sync for GradientProcessor<T>where
HashMap<String, PerParameterState<T>>: Sync,
GradientStatistics<T>: Sync,
GradientProcessingParams<T>: Sync,
impl<T> Unpin for GradientProcessor<T>where
HashMap<String, PerParameterState<T>>: Unpin,
GradientStatistics<T>: Unpin,
GradientProcessingParams<T>: Unpin,
impl<T> UnsafeUnpin for GradientProcessor<T>where
HashMap<String, PerParameterState<T>>: UnsafeUnpin,
GradientStatistics<T>: UnsafeUnpin,
GradientProcessingParams<T>: UnsafeUnpin,
impl<T> UnwindSafe for GradientProcessor<T>where
HashMap<String, PerParameterState<T>>: UnwindSafe,
GradientStatistics<T>: UnwindSafe,
GradientProcessingParams<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
Mutably borrows from an owned value. Read more
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
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 moreSource§impl<T> Pointable for T
impl<T> Pointable for T
impl<T> Read<Exclusive, BecauseExclusive> for Twhere
T: ?Sized,
Source§impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
Source§fn to_subset(&self) -> Option<SS>
fn to_subset(&self) -> Option<SS>
The inverse inclusion map: attempts to construct
self from the equivalent element of its
superset. Read moreSource§fn is_in_subset(&self) -> bool
fn is_in_subset(&self) -> bool
Checks if
self is actually part of its subset T (and can be converted to it).Source§fn to_subset_unchecked(&self) -> SS
fn to_subset_unchecked(&self) -> SS
Use with care! Same as
self.to_subset but without any property checks. Always succeeds.Source§fn from_subset(element: &SS) -> SP
fn from_subset(element: &SS) -> SP
The inclusion map: converts
self to the equivalent element of its superset.