pub trait TrainingControl:
Debug
+ Send
+ Sync {
// Required methods
fn reset_gradients(&mut self) -> Result<()>;
fn reduce_learning_rate(&mut self, factor: f64) -> Result<()>;
fn clip_gradients(&mut self, max_norm: f64) -> Result<()>;
fn restart_optimizer(&mut self) -> Result<()>;
fn skip_batch(&mut self) -> Result<()>;
fn reset_weights(&mut self, layer_name: &str) -> Result<()>;
fn apply_weight_decay(&mut self, rate: f64) -> Result<()>;
fn emergency_stop(&mut self) -> Result<()>;
}Expand description
A live handle into the training loop that AnomalyDetector can drive
automatic recovery actions through.
Implementations perform the real mutation (clip gradients, reduce the
learning rate, restart the optimizer, …) against whatever optimizer or
model state the caller owns. Without a TrainingControl attached via
AnomalyDetector::set_training_control, AnomalyDetector never
claims a recovery action succeeded: every action honestly reports “not
performed” instead of the old unconditional Ok(true).
Each method returns Err (propagated into the recorded
RecoveryAttempt::error_message, never swallowed) if the underlying
mutation could not be carried out.
Required Methods§
Sourcefn reset_gradients(&mut self) -> Result<()>
fn reset_gradients(&mut self) -> Result<()>
Zero out (or otherwise reset) the current gradients.
Sourcefn reduce_learning_rate(&mut self, factor: f64) -> Result<()>
fn reduce_learning_rate(&mut self, factor: f64) -> Result<()>
Multiply the optimizer’s learning rate by factor.
Sourcefn clip_gradients(&mut self, max_norm: f64) -> Result<()>
fn clip_gradients(&mut self, max_norm: f64) -> Result<()>
Clip gradients to max_norm (e.g. global-norm clipping).
Sourcefn restart_optimizer(&mut self) -> Result<()>
fn restart_optimizer(&mut self) -> Result<()>
Reset the optimizer’s internal state (momentum buffers, etc.).
Sourcefn skip_batch(&mut self) -> Result<()>
fn skip_batch(&mut self) -> Result<()>
Skip the batch currently being processed.
Sourcefn reset_weights(&mut self, layer_name: &str) -> Result<()>
fn reset_weights(&mut self, layer_name: &str) -> Result<()>
Reset a specific layer’s weights to their initialization.
Sourcefn apply_weight_decay(&mut self, rate: f64) -> Result<()>
fn apply_weight_decay(&mut self, rate: f64) -> Result<()>
Apply weight decay at rate to the current weights.
Sourcefn emergency_stop(&mut self) -> Result<()>
fn emergency_stop(&mut self) -> Result<()>
Immediately halt training.
Dyn Compatibility§
This trait is dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".