pub struct AttentionMask {
pub num_heads: usize,
pub num_layers: usize,
pub mask: Vec<Vec<bool>>,
pub layer_sparsity: Vec<f32>,
pub overall_sparsity: f32,
}Expand description
A mask indicating which attention heads to compute
Fields§
§num_heads: usizeNumber of heads
num_layers: usizeNumber of layers
mask: Vec<Vec<bool>>Mask values: true = compute, false = skip
Indexed as [layer][head]
layer_sparsity: Vec<f32>Per-layer sparsity (fraction of heads skipped)
overall_sparsity: f32Overall sparsity
Implementations§
Source§impl AttentionMask
impl AttentionMask
Sourcepub fn all_active(num_heads: usize, num_layers: usize) -> Self
pub fn all_active(num_heads: usize, num_layers: usize) -> Self
Create a mask with all heads active
Sourcepub fn random(num_heads: usize, num_layers: usize, sparsity: f32) -> Self
pub fn random(num_heads: usize, num_layers: usize, sparsity: f32) -> Self
Create a mask with uniform random sparsity
Sourcepub fn set_active(&mut self, layer: usize, head: usize, active: bool)
pub fn set_active(&mut self, layer: usize, head: usize, active: bool)
Set head activity
Sourcepub fn active_heads(&self, layer: usize) -> Vec<usize>
pub fn active_heads(&self, layer: usize) -> Vec<usize>
Get active head indices for a layer
Sourcepub fn inactive_heads(&self, layer: usize) -> Vec<usize>
pub fn inactive_heads(&self, layer: usize) -> Vec<usize>
Get inactive head indices for a layer
Sourcepub fn active_count(&self, layer: usize) -> usize
pub fn active_count(&self, layer: usize) -> usize
Number of active heads in a layer
Sourcepub fn merge_and(&self, other: &AttentionMask) -> Result<Self>
pub fn merge_and(&self, other: &AttentionMask) -> Result<Self>
Merge with another mask (AND operation - both must be active)
Sourcepub fn merge_or(&self, other: &AttentionMask) -> Result<Self>
pub fn merge_or(&self, other: &AttentionMask) -> Result<Self>
Merge with another mask (OR operation - either can be active)
Sourcepub fn ensure_minimum(&mut self, min_active: usize)
pub fn ensure_minimum(&mut self, min_active: usize)
Ensure minimum active heads per layer
Sourcepub fn from_bytes(bytes: &[u8]) -> Result<Self>
pub fn from_bytes(bytes: &[u8]) -> Result<Self>
Deserialize from bytes
Trait Implementations§
Source§impl Clone for AttentionMask
impl Clone for AttentionMask
Source§fn clone(&self) -> AttentionMask
fn clone(&self) -> AttentionMask
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 moreSource§impl Debug for AttentionMask
impl Debug for AttentionMask
Source§impl Default for AttentionMask
impl Default for AttentionMask
Source§impl<'de> Deserialize<'de> for AttentionMask
impl<'de> Deserialize<'de> for AttentionMask
Source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
Deserialize this value from the given Serde deserializer. Read more
Auto Trait Implementations§
impl Freeze for AttentionMask
impl RefUnwindSafe for AttentionMask
impl Send for AttentionMask
impl Sync for AttentionMask
impl Unpin for AttentionMask
impl UnsafeUnpin for AttentionMask
impl UnwindSafe for AttentionMask
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