pub struct IncoherenceTransform { /* private fields */ }Expand description
Aggregate root for incoherence processing in quantization pipelines
This struct manages the lifecycle of incoherence transforms, including:
- Transform creation and caching
- Forward/inverse transform application
- Statistics collection
- Domain event emission
§Example
use ruvllm::quantize::incoherence::{IncoherenceTransform, IncoherenceConfig};
// Create transform with default config
let mut transform = IncoherenceTransform::new(IncoherenceConfig::default())?;
// Apply before quantization
let mut weights = vec![1.0, 2.0, 100.0, 4.0]; // Note the outlier
transform.apply_before_quantization(&mut weights)?;
// ... quantize weights here ...
// Restore after dequantization
transform.restore_after_dequantization(&mut weights)?;Implementations§
Source§impl IncoherenceTransform
impl IncoherenceTransform
Sourcepub fn new(config: IncoherenceConfig) -> Result<Self>
pub fn new(config: IncoherenceConfig) -> Result<Self>
Create a new IncoherenceTransform with the given configuration
Sourcepub fn with_defaults() -> Result<Self>
pub fn with_defaults() -> Result<Self>
Create with default configuration
Sourcepub fn restore_after_dequantization(
&mut self,
data: &mut Vec<f32>,
original_len: Option<usize>,
) -> Result<()>
pub fn restore_after_dequantization( &mut self, data: &mut Vec<f32>, original_len: Option<usize>, ) -> Result<()>
Restore original data distribution after dequantization
This applies the inverse transform to recover the original
weight distribution. The data must have the same length as
after apply_before_quantization.
§Arguments
data- Mutable slice of dequantized values to restoreoriginal_len- Original length before padding (optional, for truncation)
Sourcepub fn apply_batch(
&mut self,
data: &mut [f32],
dim: usize,
batch_size: usize,
) -> Result<()>
pub fn apply_batch( &mut self, data: &mut [f32], dim: usize, batch_size: usize, ) -> Result<()>
Apply incoherence to a batch of weight vectors
More efficient than individual transforms due to better cache utilization.
§Arguments
data- Flat buffer containingbatch_sizevectors ofdimelements eachdim- Dimension of each vector (must be power of 2)batch_size- Number of vectors
Sourcepub fn restore_batch(
&mut self,
data: &mut [f32],
dim: usize,
batch_size: usize,
) -> Result<()>
pub fn restore_batch( &mut self, data: &mut [f32], dim: usize, batch_size: usize, ) -> Result<()>
Restore a batch of weight vectors after dequantization
Sourcepub fn stats(&self) -> &IncoherenceStats
pub fn stats(&self) -> &IncoherenceStats
Get accumulated statistics
Sourcepub fn take_events(&mut self) -> Vec<IncoherenceEvent>
pub fn take_events(&mut self) -> Vec<IncoherenceEvent>
Take and clear emitted events
Sourcepub fn events(&self) -> &[IncoherenceEvent]
pub fn events(&self) -> &[IncoherenceEvent]
Peek at emitted events without clearing
Sourcepub fn config(&self) -> &IncoherenceConfig
pub fn config(&self) -> &IncoherenceConfig
Get configuration
Sourcepub fn reset_stats(&mut self)
pub fn reset_stats(&mut self)
Reset statistics
Sourcepub fn clear_cache(&mut self)
pub fn clear_cache(&mut self)
Clear cached transforms (useful for memory management)
Auto Trait Implementations§
impl Freeze for IncoherenceTransform
impl RefUnwindSafe for IncoherenceTransform
impl Send for IncoherenceTransform
impl Sync for IncoherenceTransform
impl Unpin for IncoherenceTransform
impl UnsafeUnpin for IncoherenceTransform
impl UnwindSafe for IncoherenceTransform
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
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>
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