pub struct ModelPruner { /* private fields */ }Expand description
Stateful weight pruner. Advance the step counter with
ModelPruner::advance_step between training iterations.
Implementations§
Source§impl ModelPruner
impl ModelPruner
Sourcepub fn new(config: PrunerConfig) -> Self
pub fn new(config: PrunerConfig) -> Self
Create a new pruner from the supplied configuration.
The PRNG seed is initialised to config.seed, falling back to 1 if
the seed is zero (xorshift64 must not start from zero).
Sourcepub fn prune_layer(&mut self, layer: &mut LayerWeights) -> PruningResult
pub fn prune_layer(&mut self, layer: &mut LayerWeights) -> PruningResult
Prune a single layer in-place according to the configured strategy.
The layer.weights vector is mutated directly; the mask (if enabled)
is created or updated.
Sourcepub fn prune_all(&mut self, layers: &mut [LayerWeights]) -> Vec<PruningResult>
pub fn prune_all(&mut self, layers: &mut [LayerWeights]) -> Vec<PruningResult>
Prune every layer in layers and return one result per layer.
Sourcepub fn current_sparsity_target(&self) -> f64
pub fn current_sparsity_target(&self) -> f64
Compute the sparsity target for the current step.
For PruningStrategy::GradualPruning this linearly interpolates
between initial_sparsity and final_sparsity. For all other
strategies it returns the equivalent fixed fraction.
Sourcepub fn compute_threshold(weights: &[f64], percentile: f64) -> f64
pub fn compute_threshold(weights: &[f64], percentile: f64) -> f64
Return the weight value at the given percentile (0–100) of the
absolute-magnitude distribution.
Uses a partial sort to avoid allocating a fully sorted copy when only
the boundary value is needed. Returns 0.0 for empty slices.
Sourcepub fn compute_sparsity(weights: &[f64]) -> f64
pub fn compute_sparsity(weights: &[f64]) -> f64
Fraction of elements in weights that are exactly zero.
Sourcepub fn compute_l1_norm(weights: &[f64]) -> f64
pub fn compute_l1_norm(weights: &[f64]) -> f64
Sum of absolute values of weights.
Sourcepub fn advance_step(&mut self)
pub fn advance_step(&mut self)
Advance the step counter by one.
Sourcepub fn next_uniform_prng(&mut self) -> f64
pub fn next_uniform_prng(&mut self) -> f64
Generate the next pseudo-random float in [0, 1) using xorshift64.
The internal state is updated in-place so successive calls yield independent values.
Sourcepub fn apply_mask(layer: &mut LayerWeights)
pub fn apply_mask(layer: &mut LayerWeights)
Zero out entries in layer.weights where the corresponding mask entry
is false. If no mask is present this is a no-op.
Sourcepub fn stats(&self) -> &PrunerStats
pub fn stats(&self) -> &PrunerStats
Immutable access to the accumulated statistics.
Auto Trait Implementations§
impl Freeze for ModelPruner
impl RefUnwindSafe for ModelPruner
impl Send for ModelPruner
impl Sync for ModelPruner
impl Unpin for ModelPruner
impl UnsafeUnpin for ModelPruner
impl UnwindSafe for ModelPruner
Blanket Implementations§
impl<T> Allocation for T
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
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
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