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>
impl<T: Float + Debug + Send + Sync + 'static + ScalarOperand + FromPrimitive> TransformerOptimizer<T>
Sourcepub fn new(config: TransformerBasedOptimizerConfig<T>) -> Result<Self>
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.
Sourcepub fn generate_optimization_step(
&mut self,
gradient_history: &Array2<T>,
parameter_history: &Array2<T>,
loss_history: &Array1<T>,
) -> Result<Array1<T>>
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
Sourcepub fn train_on_trajectories(
&mut self,
trajectories: &[OptimizationTrajectory<T>],
) -> Result<TrainingMetrics>
pub fn train_on_trajectories( &mut self, trajectories: &[OptimizationTrajectory<T>], ) -> Result<TrainingMetrics>
Train the transformer on optimization trajectories
Sourcepub fn forward_sequence(&mut self, sequence: &Array2<T>) -> Result<Array2<T>>
pub fn forward_sequence(&mut self, sequence: &Array2<T>) -> Result<Array2<T>>
Forward pass through the transformer for a sequence (inference path).
Sourcepub fn apply_architecture_config(
&mut self,
config: &TransformerBasedOptimizerConfig<T>,
) -> Result<ArchitectureUpdate>
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.
Sourcepub fn config(&self) -> &TransformerBasedOptimizerConfig<T>
pub fn config(&self) -> &TransformerBasedOptimizerConfig<T>
The configuration currently in force.
Sourcepub fn parameter_count(&self) -> usize
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.
Sourcepub fn get_state(&self) -> &TransformerOptimizerState<T>
pub fn get_state(&self) -> &TransformerOptimizerState<T>
Get current state
Sourcepub fn get_performance_metrics(&self) -> &TransformerPerformanceTracker<T>
pub fn get_performance_metrics(&self) -> &TransformerPerformanceTracker<T>
Get performance metrics
Sourcepub fn reset_state(&mut self) -> Result<()>
pub fn reset_state(&mut self) -> Result<()>
Reset optimizer state
Auto Trait Implementations§
impl<T> Freeze for TransformerOptimizer<T>where
TransformerArchitecture<T>: Freeze,
PositionalEncoding<T>: Freeze,
TransformerMetaLearning<T>: Freeze,
OptimizationSequenceProcessor<T>: Freeze,
TransformerMemoryManager<T>: Freeze,
TransformerBasedOptimizerConfig<T>: Freeze,
TransformerPerformanceTracker<T>: Freeze,
TransformerOptimizerState<T>: Freeze,
impl<T> RefUnwindSafe for TransformerOptimizer<T>where
TransformerArchitecture<T>: RefUnwindSafe,
PositionalEncoding<T>: RefUnwindSafe,
TransformerMetaLearning<T>: RefUnwindSafe,
OptimizationSequenceProcessor<T>: RefUnwindSafe,
TransformerMemoryManager<T>: RefUnwindSafe,
TransformerBasedOptimizerConfig<T>: RefUnwindSafe,
TransformerPerformanceTracker<T>: RefUnwindSafe,
TransformerOptimizerState<T>: RefUnwindSafe,
impl<T> Send for TransformerOptimizer<T>where
TransformerArchitecture<T>: Send,
PositionalEncoding<T>: Send,
TransformerMetaLearning<T>: Send,
OptimizationSequenceProcessor<T>: Send,
TransformerMemoryManager<T>: Send,
TransformerBasedOptimizerConfig<T>: Send,
TransformerPerformanceTracker<T>: Send,
TransformerOptimizerState<T>: Send,
impl<T> Sync for TransformerOptimizer<T>where
TransformerArchitecture<T>: Sync,
PositionalEncoding<T>: Sync,
TransformerMetaLearning<T>: Sync,
OptimizationSequenceProcessor<T>: Sync,
TransformerMemoryManager<T>: Sync,
TransformerBasedOptimizerConfig<T>: Sync,
TransformerPerformanceTracker<T>: Sync,
TransformerOptimizerState<T>: Sync,
impl<T> Unpin for TransformerOptimizer<T>where
TransformerArchitecture<T>: Unpin,
PositionalEncoding<T>: Unpin,
TransformerMetaLearning<T>: Unpin,
OptimizationSequenceProcessor<T>: Unpin,
TransformerMemoryManager<T>: Unpin,
TransformerBasedOptimizerConfig<T>: Unpin,
TransformerPerformanceTracker<T>: Unpin,
TransformerOptimizerState<T>: Unpin,
impl<T> UnsafeUnpin for TransformerOptimizer<T>where
TransformerArchitecture<T>: UnsafeUnpin,
PositionalEncoding<T>: UnsafeUnpin,
TransformerMetaLearning<T>: UnsafeUnpin,
OptimizationSequenceProcessor<T>: UnsafeUnpin,
TransformerMemoryManager<T>: UnsafeUnpin,
TransformerBasedOptimizerConfig<T>: UnsafeUnpin,
TransformerPerformanceTracker<T>: UnsafeUnpin,
TransformerOptimizerState<T>: UnsafeUnpin,
impl<T> UnwindSafe for TransformerOptimizer<T>where
TransformerArchitecture<T>: UnwindSafe,
PositionalEncoding<T>: UnwindSafe,
TransformerMetaLearning<T>: UnwindSafe,
OptimizationSequenceProcessor<T>: UnwindSafe,
TransformerMemoryManager<T>: UnwindSafe,
TransformerBasedOptimizerConfig<T>: UnwindSafe,
TransformerPerformanceTracker<T>: UnwindSafe,
TransformerOptimizerState<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.