Skip to main content

DriftMask

Struct DriftMask 

Source
pub struct DriftMask { /* private fields */ }
Available on crate feature 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(&params, &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 10

Implementations§

Source§

impl DriftMask

Source

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 manage
  • freeze_fraction – fraction of currently unfrozen params to freeze on drift
  • importance_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].

Source

pub fn with_defaults(n_params: usize) -> Self

Create a new DriftMask with default hyperparameters.

Defaults: freeze_fraction = 0.3, importance_alpha = 0.99.

Source

pub fn is_frozen(&self, idx: usize) -> bool

Check if a specific parameter is frozen.

§Panics

Panics if idx >= n_params().

Source

pub fn n_frozen(&self) -> usize

Number of currently frozen parameters.

Source

pub fn frozen_fraction(&self) -> f64

Fraction of parameters currently frozen.

Source

pub fn importance(&self) -> &[f64]

Current importance values.

Source

pub fn unfreeze_all(&mut self)

Unfreeze all parameters (fresh start for isolation).

Trait Implementations§

Source§

impl ContinualStrategy for DriftMask

Source§

fn pre_update(&mut self, _params: &[f64], gradients: &mut [f64])

Modify gradients before weight update. Called before each parameter update. params = current parameter values, gradients = computed gradients (modified in-place).
Source§

fn post_update(&mut self, _params: &[f64])

Called after weight update with the new parameter values.
Source§

fn on_drift(&mut self, _params: &[f64], signal: DriftSignal)

React to a drift signal. E.g., update anchor point, recompute masks.
Source§

fn n_params(&self) -> usize

Number of parameters this strategy covers.
Source§

fn reset(&mut self)

Reset to initial state.

Auto Trait Implementations§

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<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, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

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

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

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.