pub struct LotteryTicketPruner { /* private fields */ }Expand description
Lottery Ticket Hypothesis pruner.
Implements Iterative Magnitude Pruning (IMP) with weight rewinding to find sparse, trainable subnetworks.
Implementations§
Source§impl LotteryTicketPruner
impl LotteryTicketPruner
Sourcepub fn new() -> Self
pub fn new() -> Self
Create a new LTH pruner with default configuration. Default: 90% sparsity over 10 rounds with init rewinding.
Sourcepub fn with_config(config: LotteryTicketConfig) -> Self
pub fn with_config(config: LotteryTicketConfig) -> Self
Create a pruner with custom configuration.
Sourcepub fn builder() -> LotteryTicketPrunerBuilder
pub fn builder() -> LotteryTicketPrunerBuilder
Get a builder for configuring the pruner.
Sourcepub fn config(&self) -> &LotteryTicketConfig
pub fn config(&self) -> &LotteryTicketConfig
Get the configuration.
Sourcepub fn find_ticket(
&self,
module: &dyn Module,
) -> Result<WinningTicket, PruningError>
pub fn find_ticket( &self, module: &dyn Module, ) -> Result<WinningTicket, PruningError>
Find a winning ticket from the given module.
This performs iterative magnitude pruning:
- Compute importance scores
- Generate mask for current round’s pruning rate
- Accumulate into overall mask
- Record weight state for rewinding
Note: This is a simplified version that doesn’t require training.
For full LTH, use find_ticket_with_training.
Sourcepub fn apply_ticket(
&self,
module: &mut dyn Module,
ticket: &WinningTicket,
) -> Result<PruningResult, PruningError>
pub fn apply_ticket( &self, module: &mut dyn Module, ticket: &WinningTicket, ) -> Result<PruningResult, PruningError>
Apply a winning ticket mask to a module.
This zeros out the pruned weights according to the mask.
Trait Implementations§
Source§impl Clone for LotteryTicketPruner
impl Clone for LotteryTicketPruner
Source§fn clone(&self) -> LotteryTicketPruner
fn clone(&self) -> LotteryTicketPruner
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 LotteryTicketPruner
impl Debug for LotteryTicketPruner
Source§impl Default for LotteryTicketPruner
impl Default for LotteryTicketPruner
§impl Pruner for LotteryTicketPruner
impl Pruner for LotteryTicketPruner
§fn generate_mask(
&self,
scores: &ImportanceScores,
target_sparsity: f32,
pattern: SparsityPattern,
) -> Result<SparsityMask, PruningError>
fn generate_mask( &self, scores: &ImportanceScores, target_sparsity: f32, pattern: SparsityPattern, ) -> Result<SparsityMask, PruningError>
Generate a sparsity mask based on importance scores. Read more
§fn apply_mask(
&self,
module: &mut dyn Module,
mask: &SparsityMask,
) -> Result<PruningResult, PruningError>
fn apply_mask( &self, module: &mut dyn Module, mask: &SparsityMask, ) -> Result<PruningResult, PruningError>
Apply a sparsity mask to a module, zeroing pruned weights. Read more
§fn importance(&self) -> &dyn Importance
fn importance(&self) -> &dyn Importance
Get the importance estimator used by this pruner.
Auto Trait Implementations§
impl Freeze for LotteryTicketPruner
impl RefUnwindSafe for LotteryTicketPruner
impl Send for LotteryTicketPruner
impl Sync for LotteryTicketPruner
impl Unpin for LotteryTicketPruner
impl UnsafeUnpin for LotteryTicketPruner
impl UnwindSafe for LotteryTicketPruner
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