pub struct BlockSparseGradient {
pub blocks: Vec<Vec<f32>>,
pub block_indices: Vec<(usize, usize)>,
pub block_size: usize,
pub shape: Vec<usize>,
pub block_shape: Vec<usize>,
pub block_sparsity_ratio: f32,
}Expand description
Block-sparse gradient for structured sparsity
Fields§
§blocks: Vec<Vec<f32>>Non-zero blocks
block_indices: Vec<(usize, usize)>Block indices (row, col) for 2D or flat index for 1D
block_size: usizeBlock size
shape: Vec<usize>Shape of the original gradient
block_shape: Vec<usize>Number of blocks in each dimension
block_sparsity_ratio: f32Sparsity ratio at block level
Implementations§
Source§impl BlockSparseGradient
impl BlockSparseGradient
Sourcepub fn from_dense(
gradient: &[f32],
shape: Vec<usize>,
block_size: usize,
threshold: f32,
) -> Result<Self>
pub fn from_dense( gradient: &[f32], shape: Vec<usize>, block_size: usize, threshold: f32, ) -> Result<Self>
Create block-sparse gradient from dense gradient
Only rank-1 and rank-2 gradients have a block-sparse layout defined here; higher-rank gradients (e.g. 4-D convolution weights) are reported as unsupported so the caller can fall back to a dense update. A sparse-update optimisation must degrade to correct dense behaviour, never abort.
§Errors
Returns TorshError::UnsupportedOperation if shape is not rank 1 or 2.
Sourcepub fn is_worth_block_sparse(&self, min_sparsity_ratio: f32) -> bool
pub fn is_worth_block_sparse(&self, min_sparsity_ratio: f32) -> bool
Check if block representation is beneficial
Trait Implementations§
Source§impl Clone for BlockSparseGradient
impl Clone for BlockSparseGradient
Source§fn clone(&self) -> BlockSparseGradient
fn clone(&self) -> BlockSparseGradient
Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · 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 BlockSparseGradient
impl RefUnwindSafe for BlockSparseGradient
impl Send for BlockSparseGradient
impl Sync for BlockSparseGradient
impl Unpin for BlockSparseGradient
impl UnsafeUnpin for BlockSparseGradient
impl UnwindSafe for BlockSparseGradient
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
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> ⓘ
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