pub struct DriftMask { /* private fields */ }alloc only.Expand description
Drift-triggered parameter isolation.
When drift is detected, computes an importance mask from the accumulated gradient magnitudes and freezes the most important parameters (setting their gradients to zero). The remaining parameters are free to adapt.
This is a streaming version of PackNet (Mallya & Lazebnik, 2018): instead of task boundaries, irithyll’s drift detectors trigger mask updates.
§Example
use irithyll_core::continual::{DriftMask, ContinualStrategy};
use irithyll_core::drift::DriftSignal;
let mut mask = DriftMask::with_defaults(10);
// Train for a while, accumulating importance
for _ in 0..100 {
let params = vec![0.0; 10];
let mut grads = vec![0.1; 10];
mask.pre_update(¶ms, &mut grads);
}
// Drift detected: freeze top 30% of params
mask.on_drift(&[0.0; 10], DriftSignal::Drift);
assert_eq!(mask.n_frozen(), 3); // 30% of 10Implementations§
Source§impl DriftMask
impl DriftMask
Sourcepub fn new(n_params: usize, freeze_fraction: f64, importance_alpha: f64) -> Self
pub fn new(n_params: usize, freeze_fraction: f64, importance_alpha: f64) -> Self
Create a new DriftMask with explicit hyperparameters.
§Arguments
n_params– number of parameters to managefreeze_fraction– fraction of currently unfrozen params to freeze on driftimportance_alpha– EWMA decay for importance; closer to 1.0 = longer memory
§Panics
Panics if freeze_fraction is not in [0.0, 1.0] or importance_alpha
is not in [0.0, 1.0].
Sourcepub fn with_defaults(n_params: usize) -> Self
pub fn with_defaults(n_params: usize) -> Self
Create a new DriftMask with default hyperparameters.
Defaults: freeze_fraction = 0.3, importance_alpha = 0.99.
Sourcepub fn frozen_fraction(&self) -> f64
pub fn frozen_fraction(&self) -> f64
Fraction of parameters currently frozen.
Sourcepub fn importance(&self) -> &[f64]
pub fn importance(&self) -> &[f64]
Current importance values.
Sourcepub fn unfreeze_all(&mut self)
pub fn unfreeze_all(&mut self)
Unfreeze all parameters (fresh start for isolation).
Trait Implementations§
Source§impl ContinualStrategy for DriftMask
impl ContinualStrategy for DriftMask
Source§fn pre_update(&mut self, _params: &[f64], gradients: &mut [f64])
fn pre_update(&mut self, _params: &[f64], gradients: &mut [f64])
params = current parameter values, gradients = computed gradients (modified in-place).Source§fn post_update(&mut self, _params: &[f64])
fn post_update(&mut self, _params: &[f64])
Source§fn on_drift(&mut self, _params: &[f64], signal: DriftSignal)
fn on_drift(&mut self, _params: &[f64], signal: DriftSignal)
Auto Trait Implementations§
impl Freeze for DriftMask
impl RefUnwindSafe for DriftMask
impl Send for DriftMask
impl Sync for DriftMask
impl Unpin for DriftMask
impl UnsafeUnpin for DriftMask
impl UnwindSafe for DriftMask
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
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 more