pub struct TransformerOptimizer<T: Float + Debug + Default + Clone + Sum + ScalarOperand + Send + Sync + 'static> { /* private fields */ }Expand description
Transformer-based neural optimizer with self-attention mechanisms
Implementations§
Source§impl<T: Float + Debug + Default + Clone + Sum + ScalarOperand + Send + Sync + 'static> TransformerOptimizer<T>
impl<T: Float + Debug + Default + Clone + Sum + ScalarOperand + Send + Sync + 'static> TransformerOptimizer<T>
Sourcepub fn new(config: TransformerOptimizerConfig) -> Result<Self>
pub fn new(config: TransformerOptimizerConfig) -> Result<Self>
Create new transformer optimizer
Sourcepub fn step(
&mut self,
parameters: &mut HashMap<String, Array2<T>>,
gradients: &mut HashMap<String, Array2<T>>,
loss: T,
) -> Result<T>
pub fn step( &mut self, parameters: &mut HashMap<String, Array2<T>>, gradients: &mut HashMap<String, Array2<T>>, loss: T, ) -> Result<T>
Perform one optimization step, writing the updated values back into
parameters in place.
The pipeline is: regularize -> process -> adapt learning rate ->
integrate momentum -> run the recent optimization history through the
transformer -> apply param -= lr * modulation * momentum_gradient.
The transformer output is used as a bounded, strictly positive per-coordinate scale on the momentum-integrated gradient rather than as the update itself. This is the standard learned-preconditioner formulation: the network can speed up or slow down individual coordinates but cannot, by itself, reverse the descent direction, so an untrained network degrades gracefully to plain gradient descent instead of diverging.
Returns the loss it was given, so callers can chain steps.
Sourcepub fn get_statistics(&self) -> HashMap<String, f64>
pub fn get_statistics(&self) -> HashMap<String, f64>
Get current optimization statistics
Sourcepub fn set_training(&mut self, training: bool)
pub fn set_training(&mut self, training: bool)
Switch the network between training mode (dropout active) and inference mode. Optimizers are created in inference mode.
Sourcepub fn set_learning_rate(&mut self, lr: T)
pub fn set_learning_rate(&mut self, lr: T)
Override the base learning rate used by the adapter.
Sourcepub fn current_learning_rate(&self) -> T
pub fn current_learning_rate(&self) -> T
Current (post-adaptation) learning rate.
Sourcepub fn step_count(&self) -> usize
pub fn step_count(&self) -> usize
Number of steps taken so far.
Sourcepub fn config(&self) -> &TransformerOptimizerConfig
pub fn config(&self) -> &TransformerOptimizerConfig
Configuration in use.
Sourcepub fn lr_adapter_mut(&mut self) -> &mut LearningRateAdapter<T>
pub fn lr_adapter_mut(&mut self) -> &mut LearningRateAdapter<T>
Mutable access to the learning rate adapter.
Sourcepub fn gradient_processor_mut(&mut self) -> &mut GradientProcessor<T>
pub fn gradient_processor_mut(&mut self) -> &mut GradientProcessor<T>
Mutable access to the gradient processor.
Sourcepub fn momentum_integrator_mut(&mut self) -> &mut MomentumIntegrator<T>
pub fn momentum_integrator_mut(&mut self) -> &mut MomentumIntegrator<T>
Mutable access to the momentum integrator.
Sourcepub fn regularizer_mut(&mut self) -> &mut TransformerRegularizer<T>
pub fn regularizer_mut(&mut self) -> &mut TransformerRegularizer<T>
Mutable access to the regularizer.
Sourcepub fn meta_learner_mut(&mut self) -> &mut TransformerMetaLearner<T>
pub fn meta_learner_mut(&mut self) -> &mut TransformerMetaLearner<T>
Mutable access to the meta-learner.
Sourcepub fn evaluator_mut(&mut self) -> &mut TransformerEvaluator<T>
pub fn evaluator_mut(&mut self) -> &mut TransformerEvaluator<T>
Mutable access to the evaluator.
Trait Implementations§
Auto Trait Implementations§
impl<T> Freeze for TransformerOptimizer<T>where
TransformerNetwork<T>: Freeze,
GradientProcessor<T>: Freeze,
LearningRateAdapter<T>: Freeze,
MomentumIntegrator<T>: Freeze,
TransformerRegularizer<T>: Freeze,
TransformerMetaLearner<T>: Freeze,
CurriculumLearner<T>: Freeze,
TransformerEvaluator<T>: Freeze,
SequenceBuffer<T>: Freeze,
impl<T> RefUnwindSafe for TransformerOptimizer<T>where
TransformerNetwork<T>: RefUnwindSafe,
GradientProcessor<T>: RefUnwindSafe,
LearningRateAdapter<T>: RefUnwindSafe,
MomentumIntegrator<T>: RefUnwindSafe,
TransformerRegularizer<T>: RefUnwindSafe,
TransformerMetaLearner<T>: RefUnwindSafe,
CurriculumLearner<T>: RefUnwindSafe,
TransformerEvaluator<T>: RefUnwindSafe,
SequenceBuffer<T>: RefUnwindSafe,
impl<T> Send for TransformerOptimizer<T>where
TransformerNetwork<T>: Send,
GradientProcessor<T>: Send,
LearningRateAdapter<T>: Send,
MomentumIntegrator<T>: Send,
TransformerRegularizer<T>: Send,
TransformerMetaLearner<T>: Send,
CurriculumLearner<T>: Send,
TransformerEvaluator<T>: Send,
SequenceBuffer<T>: Send,
impl<T> Sync for TransformerOptimizer<T>where
TransformerNetwork<T>: Sync,
GradientProcessor<T>: Sync,
LearningRateAdapter<T>: Sync,
MomentumIntegrator<T>: Sync,
TransformerRegularizer<T>: Sync,
TransformerMetaLearner<T>: Sync,
CurriculumLearner<T>: Sync,
TransformerEvaluator<T>: Sync,
SequenceBuffer<T>: Sync,
impl<T> Unpin for TransformerOptimizer<T>where
TransformerNetwork<T>: Unpin,
GradientProcessor<T>: Unpin,
LearningRateAdapter<T>: Unpin,
MomentumIntegrator<T>: Unpin,
TransformerRegularizer<T>: Unpin,
TransformerMetaLearner<T>: Unpin,
CurriculumLearner<T>: Unpin,
TransformerEvaluator<T>: Unpin,
SequenceBuffer<T>: Unpin,
impl<T> UnsafeUnpin for TransformerOptimizer<T>where
TransformerNetwork<T>: UnsafeUnpin,
GradientProcessor<T>: UnsafeUnpin,
LearningRateAdapter<T>: UnsafeUnpin,
MomentumIntegrator<T>: UnsafeUnpin,
TransformerRegularizer<T>: UnsafeUnpin,
TransformerMetaLearner<T>: UnsafeUnpin,
CurriculumLearner<T>: UnsafeUnpin,
TransformerEvaluator<T>: UnsafeUnpin,
SequenceBuffer<T>: UnsafeUnpin,
impl<T> UnwindSafe for TransformerOptimizer<T>where
TransformerNetwork<T>: UnwindSafe,
GradientProcessor<T>: UnwindSafe,
LearningRateAdapter<T>: UnwindSafe,
MomentumIntegrator<T>: UnwindSafe,
TransformerRegularizer<T>: UnwindSafe,
TransformerMetaLearner<T>: UnwindSafe,
CurriculumLearner<T>: UnwindSafe,
TransformerEvaluator<T>: UnwindSafe,
SequenceBuffer<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
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
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 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>
self from the equivalent element of its
superset. Read moreSource§fn is_in_subset(&self) -> bool
fn is_in_subset(&self) -> bool
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
self.to_subset but without any property checks. Always succeeds.Source§fn from_subset(element: &SS) -> SP
fn from_subset(element: &SS) -> SP
self to the equivalent element of its superset.