Skip to main content

TransformerOptimizer

Struct TransformerOptimizer 

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

Source

pub fn new(config: TransformerOptimizerConfig) -> Result<Self>

Create new transformer optimizer

Source

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.

Source

pub fn get_statistics(&self) -> HashMap<String, f64>

Get current optimization statistics

Source

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.

Source

pub fn set_learning_rate(&mut self, lr: T)

Override the base learning rate used by the adapter.

Source

pub fn current_learning_rate(&self) -> T

Current (post-adaptation) learning rate.

Source

pub fn step_count(&self) -> usize

Number of steps taken so far.

Source

pub fn config(&self) -> &TransformerOptimizerConfig

Configuration in use.

Source

pub fn lr_adapter_mut(&mut self) -> &mut LearningRateAdapter<T>

Mutable access to the learning rate adapter.

Source

pub fn gradient_processor_mut(&mut self) -> &mut GradientProcessor<T>

Mutable access to the gradient processor.

Source

pub fn momentum_integrator_mut(&mut self) -> &mut MomentumIntegrator<T>

Mutable access to the momentum integrator.

Source

pub fn regularizer_mut(&mut self) -> &mut TransformerRegularizer<T>

Mutable access to the regularizer.

Source

pub fn meta_learner_mut(&mut self) -> &mut TransformerMetaLearner<T>

Mutable access to the meta-learner.

Source

pub fn evaluator_mut(&mut self) -> &mut TransformerEvaluator<T>

Mutable access to the evaluator.

Source

pub fn reset(&mut self) -> Result<()>

Reset optimizer state

Trait Implementations§

Source§

impl<T: Debug + Float + Debug + Default + Clone + Sum + ScalarOperand + Send + Sync + 'static> Debug for TransformerOptimizer<T>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl<T> Freeze for TransformerOptimizer<T>

§

impl<T> RefUnwindSafe for TransformerOptimizer<T>

§

impl<T> Send for TransformerOptimizer<T>

§

impl<T> Sync for TransformerOptimizer<T>

§

impl<T> Unpin for TransformerOptimizer<T>

§

impl<T> UnsafeUnpin for TransformerOptimizer<T>

§

impl<T> UnwindSafe for TransformerOptimizer<T>

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<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

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> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<SS, SP> SupersetOf<SS> for SP
where SS: SubsetOf<SP>,

Source§

fn to_subset(&self) -> Option<SS>

The inverse inclusion map: attempts to construct self from the equivalent element of its superset. Read more
Source§

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

Use with care! Same as self.to_subset but without any property checks. Always succeeds.
Source§

fn from_subset(element: &SS) -> SP

The inclusion map: converts self to the equivalent element of its superset.
Source§

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

Source§

type Error = !

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

fn try_from(value: U) -> Result<T, !>

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