pub struct SparseGPTImportance { /* private fields */ }Expand description
SparseGPT importance estimator using Hessian-based saliency.
Computes importance scores based on the Optimal Brain Surgeon (OBS)
saliency metric: saliency = w^2 / H^{-1}_{jj}
This identifies weights whose removal causes minimal output perturbation when compensated by adjusting remaining weights.
§Algorithm
- Compute Hessian H = (1/n) * X^T * X + damp * I
- Compute Hessian inverse via Cholesky decomposition
- Saliency = w^2 / diag(H^{-1})
§Key Insight
Second-order information allows weight updates that minimize the output perturbation caused by pruning.
Implementations§
Source§impl SparseGPTImportance
impl SparseGPTImportance
Sourcepub fn new(layer_name: impl Into<String>) -> SparseGPTImportance
pub fn new(layer_name: impl Into<String>) -> SparseGPTImportance
Create SparseGPT importance estimator for a specific layer.
§Arguments
layer_name- Layer identifier to look up inCalibrationContext
Sourcepub fn with_block_size(self, block_size: usize) -> SparseGPTImportance
pub fn with_block_size(self, block_size: usize) -> SparseGPTImportance
Set block size for block-wise processing.
Smaller blocks use less memory but may be less accurate.
Sourcepub fn with_damp(self, damp: f32) -> SparseGPTImportance
pub fn with_damp(self, damp: f32) -> SparseGPTImportance
Sourcepub fn with_relative_damp(self, damp: f32) -> SparseGPTImportance
pub fn with_relative_damp(self, damp: f32) -> SparseGPTImportance
Sourcepub fn layer_name(&self) -> &str
pub fn layer_name(&self) -> &str
Get the layer name.
Sourcepub fn block_size(&self) -> usize
pub fn block_size(&self) -> usize
Get the block size.
Sourcepub fn compute_hessian(
&self,
activations: &Tensor,
) -> Result<Tensor, PruningError>
pub fn compute_hessian( &self, activations: &Tensor, ) -> Result<Tensor, PruningError>
Sourcepub fn compute_hessian_inverse(
&self,
hessian: &Tensor,
) -> Result<Tensor, PruningError>
pub fn compute_hessian_inverse( &self, hessian: &Tensor, ) -> Result<Tensor, PruningError>
Sourcepub fn compute_saliency(
&self,
weights: &Tensor,
hessian_inv: &Tensor,
) -> Result<Tensor, PruningError>
pub fn compute_saliency( &self, weights: &Tensor, hessian_inv: &Tensor, ) -> Result<Tensor, PruningError>
Compute saliency scores from weights and Hessian inverse.
Saliency = w^2 / H^{-1}_{jj}
Lower saliency means the weight can be pruned with less error.
Sourcepub fn compute_from_activations(
&self,
weights: &Tensor,
activations: &Tensor,
) -> Result<ImportanceScores, PruningError>
pub fn compute_from_activations( &self, weights: &Tensor, activations: &Tensor, ) -> Result<ImportanceScores, PruningError>
Compute importance from weights and activations.
This is the main entry point for SparseGPT importance scoring.
Trait Implementations§
Source§impl Clone for SparseGPTImportance
impl Clone for SparseGPTImportance
Source§fn clone(&self) -> SparseGPTImportance
fn clone(&self) -> SparseGPTImportance
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl Debug for SparseGPTImportance
impl Debug for SparseGPTImportance
Source§impl Importance for SparseGPTImportance
impl Importance for SparseGPTImportance
Source§fn compute(
&self,
module: &dyn Module,
context: Option<&CalibrationContext>,
) -> Result<ImportanceScores, PruningError>
fn compute( &self, module: &dyn Module, context: Option<&CalibrationContext>, ) -> Result<ImportanceScores, PruningError>
Source§fn requires_calibration(&self) -> bool
fn requires_calibration(&self) -> bool
Auto Trait Implementations§
impl Freeze for SparseGPTImportance
impl RefUnwindSafe for SparseGPTImportance
impl Send for SparseGPTImportance
impl Sync for SparseGPTImportance
impl Unpin for SparseGPTImportance
impl UnsafeUnpin for SparseGPTImportance
impl UnwindSafe for SparseGPTImportance
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
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
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> ⓘ
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