pub struct UnstructuredPruner { /* private fields */ }Expand description
Unstructured pruner for element-wise weight removal
This is the main orchestrator for unstructured pruning operations, supporting various importance methods, mask creation modes, and advanced features like lottery ticket rewinding.
Implementations§
Source§impl UnstructuredPruner
impl UnstructuredPruner
Sourcepub fn new(config: PruningConfig, importance_method: ImportanceMethod) -> Self
pub fn new(config: PruningConfig, importance_method: ImportanceMethod) -> Self
Creates a new unstructured pruner
Sourcepub fn with_mask_mode(self, mode: MaskCreationMode) -> Self
pub fn with_mask_mode(self, mode: MaskCreationMode) -> Self
Sets the mask creation mode
Sourcepub fn enable_lottery_ticket(&mut self, initial_weights: Vec<WeightTensor>)
pub fn enable_lottery_ticket(&mut self, initial_weights: Vec<WeightTensor>)
Enables lottery ticket hypothesis support
Sourcepub fn disable_lottery_ticket(&mut self)
pub fn disable_lottery_ticket(&mut self)
Disables lottery ticket support
Sourcepub fn masks(&self) -> &[PruningMask]
pub fn masks(&self) -> &[PruningMask]
Returns the current masks
Sourcepub fn current_iteration(&self) -> usize
pub fn current_iteration(&self) -> usize
Returns the current iteration
Sourcepub fn lottery_ticket_state(&self) -> Option<&LotteryTicketState>
pub fn lottery_ticket_state(&self) -> Option<&LotteryTicketState>
Returns the lottery ticket state if enabled
Sourcepub fn rewind_to_initial(&self) -> Option<Vec<WeightTensor>>
pub fn rewind_to_initial(&self) -> Option<Vec<WeightTensor>>
Rewinds to initial weights with current masks (lottery ticket)
Sourcepub fn compute_importance(
&mut self,
weights: &WeightTensor,
gradient_info: Option<&GradientInfo>,
) -> Vec<f32>
pub fn compute_importance( &mut self, weights: &WeightTensor, gradient_info: Option<&GradientInfo>, ) -> Vec<f32>
Sourcepub fn create_mask(&self, importance: &[f32], shape: &[usize]) -> PruningMask
pub fn create_mask(&self, importance: &[f32], shape: &[usize]) -> PruningMask
Creates a pruning mask based on importance scores and mask mode
§Arguments
importance- Importance scores for each weightshape- Shape of the weight tensor
Sourcepub fn prune_tensor(
&mut self,
weights: &WeightTensor,
) -> Result<(WeightTensor, PruningMask)>
pub fn prune_tensor( &mut self, weights: &WeightTensor, ) -> Result<(WeightTensor, PruningMask)>
Sourcepub fn prune_tensor_with_gradients(
&mut self,
weights: &WeightTensor,
gradient_info: Option<&GradientInfo>,
) -> Result<(WeightTensor, PruningMask)>
pub fn prune_tensor_with_gradients( &mut self, weights: &WeightTensor, gradient_info: Option<&GradientInfo>, ) -> Result<(WeightTensor, PruningMask)>
Sourcepub fn prune_tensors_global(
&mut self,
tensors: &[WeightTensor],
) -> Result<(Vec<WeightTensor>, Vec<PruningMask>)>
pub fn prune_tensors_global( &mut self, tensors: &[WeightTensor], ) -> Result<(Vec<WeightTensor>, Vec<PruningMask>)>
Sourcepub fn prune_tensors_global_with_gradients(
&mut self,
tensors: &[WeightTensor],
gradient_infos: &[GradientInfo],
) -> Result<(Vec<WeightTensor>, Vec<PruningMask>)>
pub fn prune_tensors_global_with_gradients( &mut self, tensors: &[WeightTensor], gradient_infos: &[GradientInfo], ) -> Result<(Vec<WeightTensor>, Vec<PruningMask>)>
Sourcepub fn prune_tensors_layerwise(
&mut self,
tensors: &[WeightTensor],
) -> Result<(Vec<WeightTensor>, Vec<PruningMask>)>
pub fn prune_tensors_layerwise( &mut self, tensors: &[WeightTensor], ) -> Result<(Vec<WeightTensor>, Vec<PruningMask>)>
Sourcepub fn prune_tensors_layerwise_with_gradients(
&mut self,
tensors: &[WeightTensor],
gradient_infos: &[GradientInfo],
) -> Result<(Vec<WeightTensor>, Vec<PruningMask>)>
pub fn prune_tensors_layerwise_with_gradients( &mut self, tensors: &[WeightTensor], gradient_infos: &[GradientInfo], ) -> Result<(Vec<WeightTensor>, Vec<PruningMask>)>
Sourcepub fn current_sparsity(&self) -> f32
pub fn current_sparsity(&self) -> f32
Returns the current overall sparsity
Sourcepub fn iterative_prune<F: FineTuneCallback>(
&mut self,
initial_weights: Vec<WeightTensor>,
callback: &mut F,
) -> Result<(Vec<WeightTensor>, Vec<PruningMask>)>
pub fn iterative_prune<F: FineTuneCallback>( &mut self, initial_weights: Vec<WeightTensor>, callback: &mut F, ) -> Result<(Vec<WeightTensor>, Vec<PruningMask>)>
Sourcepub fn compute_stats(&self, original_tensors: &[WeightTensor]) -> PruningStats
pub fn compute_stats(&self, original_tensors: &[WeightTensor]) -> PruningStats
Computes pruning statistics
Auto Trait Implementations§
impl Freeze for UnstructuredPruner
impl RefUnwindSafe for UnstructuredPruner
impl Send for UnstructuredPruner
impl Sync for UnstructuredPruner
impl Unpin for UnstructuredPruner
impl UnsafeUnpin for UnstructuredPruner
impl UnwindSafe for UnstructuredPruner
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> 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>
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