Expand description
Model weight pruning with magnitude, structured, and gradual scheduling strategies.
This module implements several classical and modern neural-network pruning approaches:
- Magnitude pruning — zero out individual weights whose absolute value falls below a fixed threshold.
- Percentile-magnitude pruning — zero out the bottom X% of weights ranked by absolute magnitude.
- Structured L1 pruning — remove entire neurons / output channels whose mean L1 norm is below a threshold (structured sparsity that directly speeds up inference on most hardware).
- Random pruning — stochastically mask out X% of weights using a
deterministic xorshift64 PRNG seeded from
PrunerConfig::seed. - Gradual pruning — linearly ramp sparsity from an initial value to a final value over a user-specified step window (Zhu & Gupta 2018 style).
An optional binary mask is maintained alongside each LayerWeights
tensor so that sparse structure can be preserved across optimiser updates.
§Example
use ipfrs_tensorlogic::{
ModelPruner, PrunerConfig, PruningStrategy, LayerWeights,
};
let cfg = PrunerConfig {
strategy: PruningStrategy::Magnitude(0.1),
seed: 42,
update_mask: true,
};
let mut pruner = ModelPruner::new(cfg);
let mut layer = LayerWeights {
name: "fc1".to_string(),
weights: vec![0.05, -0.2, 0.0, 0.3, -0.08],
mask: None,
};
let result = pruner.prune_layer(&mut layer);
assert!(result.sparsity > 0.0);Structs§
- Layer
Weights - A named layer’s weight tensor together with an optional sparsity mask.
- Model
Pruner - Stateful weight pruner. Advance the step counter with
ModelPruner::advance_stepbetween training iterations. - Pruner
Config - Configuration bundle passed to
ModelPruner::new. - Pruner
Stats - Cumulative statistics tracked by a
ModelPruneracross all layers and all pruning steps. - Pruning
Result - Per-layer summary returned by each call to
ModelPruner::prune_layer.
Enums§
- Pruning
Strategy - Selects the algorithm used to decide which weights to prune.