pub struct WandaImportance { /* private fields */ }Expand description
Wanda (Weights and Activations) importance estimator.
Combines weight magnitudes with input activation norms to identify important weights. This method is from Sun et al. (2023) and achieves strong results with no retraining needed.
§Formula
importance = |w| * sqrt(activation_norm)
Where activation_norm is the L2 norm of input activations across
calibration samples for each input channel.
§Advantages
- No gradient computation needed
- No retraining required after pruning
- Works well at moderate sparsity (50%)
- Very fast (single forward pass for calibration)
§Requirements
- Calibration data (128 samples typically sufficient)
- Activation statistics for target layer
Implementations§
Source§impl WandaImportance
impl WandaImportance
Sourcepub fn new(layer_name: impl Into<String>) -> Self
pub fn new(layer_name: impl Into<String>) -> Self
Create Wanda importance estimator for a specific layer.
§Arguments
layer_name- Layer identifier to look up inCalibrationContext
Sourcepub fn with_pattern(self, pattern: SparsityPattern) -> Self
pub fn with_pattern(self, pattern: SparsityPattern) -> Self
Sourcepub fn with_eps(self, eps: f32) -> Self
pub fn with_eps(self, eps: f32) -> Self
Set epsilon for numerical stability.
§Arguments
eps- Small value to prevent division by zero (default: 1e-8)
Sourcepub fn layer_name(&self) -> &str
pub fn layer_name(&self) -> &str
Get the layer name.
Sourcepub fn pattern(&self) -> Option<SparsityPattern>
pub fn pattern(&self) -> Option<SparsityPattern>
Get the pattern if set.
Sourcepub fn compute_from_tensors(
&self,
weights: &Tensor,
activation_norms: &Tensor,
) -> Result<Tensor, PruningError>
pub fn compute_from_tensors( &self, weights: &Tensor, activation_norms: &Tensor, ) -> Result<Tensor, PruningError>
Trait Implementations§
Source§impl Clone for WandaImportance
impl Clone for WandaImportance
Source§fn clone(&self) -> WandaImportance
fn clone(&self) -> WandaImportance
Returns a duplicate of the value. Read more
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreSource§impl Debug for WandaImportance
impl Debug for WandaImportance
Source§impl Importance for WandaImportance
impl Importance for WandaImportance
Source§fn compute(
&self,
module: &dyn Module,
context: Option<&CalibrationContext>,
) -> Result<ImportanceScores, PruningError>
fn compute( &self, module: &dyn Module, context: Option<&CalibrationContext>, ) -> Result<ImportanceScores, PruningError>
Compute importance scores for a module’s parameters. Read more
Source§fn requires_calibration(&self) -> bool
fn requires_calibration(&self) -> bool
Whether this method requires calibration data. Read more
Auto Trait Implementations§
impl Freeze for WandaImportance
impl RefUnwindSafe for WandaImportance
impl Send for WandaImportance
impl Sync for WandaImportance
impl Unpin for WandaImportance
impl UnwindSafe for WandaImportance
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
Mutably borrows from an owned value. Read more
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
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>
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 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>
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