Skip to main content

TransformerOptimizer

Struct TransformerOptimizer 

Source
pub struct TransformerOptimizer<T: Float + Debug + ScalarOperand + Send + Sync + 'static> { /* private fields */ }
Expand description

Transformer-based meta-learning optimizer

Implementations§

Source§

impl<T: Float + Debug + Send + Sync + 'static + ScalarOperand + FromPrimitive> TransformerOptimizer<T>

Source

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

Create new transformer optimizer.

§Errors

Returns OptimError::InvalidConfig if config (or any of its three sub-configurations — memory, meta-learning, performance) is inconsistent.

F46: TransformerBasedOptimizerConfig::validate and the three sub-config validators it delegates to existed and were correct, but nothing in the crate ever called them. A model_dimension of 0, an attention_head_dimension · num_attention_heads that did not equal model_dimension, a dropout_rate of 2.0 or a zero batch_size were all accepted here and then produced either a wrong answer or a panic several layers down. The check now runs before anything is allocated.

Source

pub fn generate_optimization_step( &mut self, gradient_history: &Array2<T>, parameter_history: &Array2<T>, loss_history: &Array1<T>, ) -> Result<Array1<T>>

Generate optimization step using transformer

Source

pub fn train_on_trajectories( &mut self, trajectories: &[OptimizationTrajectory<T>], ) -> Result<TrainingMetrics>

Train the transformer on optimization trajectories

Source

pub fn forward_sequence(&mut self, sequence: &Array2<T>) -> Result<Array2<T>>

Forward pass through the transformer for a sequence (inference path).

Source

pub fn apply_architecture_config( &mut self, config: &TransformerBasedOptimizerConfig<T>, ) -> Result<ArchitectureUpdate>

Adopt a new architecture configuration.

The return value says exactly what happened, because the two cases differ in a way callers must not be left guessing about:

  • ArchitectureUpdate::Unchanged — the proposal matched the live configuration; nothing was touched.
  • ArchitectureUpdate::InPlace — only non-structural fields differed (learning_rate, dropout_rate, clipping, weight decay). They were adopted and all learned weights were kept.
  • ArchitectureUpdate::Rebuilt — a structural dimension differed (model_dimension, num_transformer_layers, num_attention_heads, attention_head_dimension, feedforward_dimension, sequence_length, activation_function, positional_encoding_type). Weights of one shape cannot be reinterpreted at another, so the transformer stack, positional encoding, meta-learning networks and optimizer state were rebuilt from a fresh initialization — every learned parameter was discarded.

That last case is destructive, which is why it is reported rather than signalled by a bare true. AdaptiveTransformerEnhancement’s architecture proposal is a function of the measured landscape rather than of the current architecture, so repeated enhancement converges and stops rebuilding instead of wiping the weights on every call.

This is also what makes AdaptiveTransformerEnhancement::enhance_optimizer actually enhance the optimizer it is given; before, its &mut TransformerOptimizer argument was never touched.

§Errors

Propagates construction errors from the new configuration (e.g. a head count that does not divide the model dimension), leaving self unchanged.

Source

pub fn config(&self) -> &TransformerBasedOptimizerConfig<T>

The configuration currently in force.

Source

pub fn parameter_count(&self) -> usize

Total number of learnable parameters this optimizer owns.

Exactly the transformer architecture plus the meta-learning adaptation networks — the only two subsystems that hold weights.

Source

pub fn get_state(&self) -> &TransformerOptimizerState<T>

Get current state

Source

pub fn get_performance_metrics(&self) -> &TransformerPerformanceTracker<T>

Get performance metrics

Source

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

Reset optimizer state

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