pub struct StructuredPruner {
pub target_sparsity: f32,
pub granularity: PruneGranularity,
}Expand description
Removes structural units based on L2 norm importance.
Each unit (channel / filter / head) receives a scalar importance score
equal to the L2 norm of its weights. The bottom target_sparsity fraction
of units are pruned.
Fields§
§target_sparsity: f32Fraction of structural units to prune ∈ [0, 1).
granularity: PruneGranularityStructural granularity.
Implementations§
Source§impl StructuredPruner
impl StructuredPruner
Sourcepub fn new(target_sparsity: f32, granularity: PruneGranularity) -> Self
pub fn new(target_sparsity: f32, granularity: PruneGranularity) -> Self
Sourcepub fn compute_mask(&self, weights: &[f32]) -> QuantResult<SparseMask>
pub fn compute_mask(&self, weights: &[f32]) -> QuantResult<SparseMask>
Compute the pruning mask for weights.
Returns a flat mask the same length as weights.
§Errors
QuantError::EmptyInput—weightsis empty.QuantError::DimensionMismatch—weights.len()is inconsistent with the granularity.QuantError::AllZeroPruning— all units would be pruned.
Sourcepub fn prune(&self, weights: &mut [f32]) -> QuantResult<SparseMask>
pub fn prune(&self, weights: &mut [f32]) -> QuantResult<SparseMask>
Apply structured pruning in-place.
Returns the mask applied.
§Errors
Propagates errors from compute_mask.
Trait Implementations§
Source§impl Clone for StructuredPruner
impl Clone for StructuredPruner
Source§fn clone(&self) -> StructuredPruner
fn clone(&self) -> StructuredPruner
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 moreAuto Trait Implementations§
impl Freeze for StructuredPruner
impl RefUnwindSafe for StructuredPruner
impl Send for StructuredPruner
impl Sync for StructuredPruner
impl Unpin for StructuredPruner
impl UnsafeUnpin for StructuredPruner
impl UnwindSafe for StructuredPruner
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