pub struct ModelCompression { /* private fields */ }Expand description
Model compression
Implementations§
Source§impl ModelCompression
impl ModelCompression
pub fn new() -> Self
pub fn initialize(&mut self) -> Result<(), MLError>
Sourcepub fn register_algorithm(
&mut self,
name: &str,
algorithm: CompressionAlgorithm,
)
pub fn register_algorithm( &mut self, name: &str, algorithm: CompressionAlgorithm, )
Register a compression algorithm under the given name.
Sourcepub fn get_algorithm(&self, name: &str) -> Option<&CompressionAlgorithm>
pub fn get_algorithm(&self, name: &str) -> Option<&CompressionAlgorithm>
Get a registered compression algorithm by name.
Sourcepub fn list_algorithms(&self) -> Vec<String>
pub fn list_algorithms(&self) -> Vec<String>
List the names of all registered compression algorithms.
Sourcepub const fn pruning_mask_bytes(weight_count: usize) -> usize
pub const fn pruning_mask_bytes(weight_count: usize) -> usize
Number of bytes needed for a packed one-bit-per-weight pruning mask.
Sourcepub fn mask_keeps(mask: &[u8], weight_index: usize) -> bool
pub fn mask_keeps(mask: &[u8], weight_index: usize) -> bool
Return whether weight_index is present in a packed pruning mask.
Sourcepub fn quantize_symmetric_int8_into(
&mut self,
weights: &[f64],
out: &mut [i8],
) -> Result<QuantizationReport, MLError>
pub fn quantize_symmetric_int8_into( &mut self, weights: &[f64], out: &mut [i8], ) -> Result<QuantizationReport, MLError>
Run per-tensor symmetric signed-int8 post-training quantization.
out is caller-owned and receives the complete compressed payload.
The returned scale is the only side metadata required to dequantize it.
Sourcepub fn dequantize_symmetric_int8_into(
quantized: &[i8],
parameters: QuantizationParameters,
out: &mut [f64],
) -> Result<usize, MLError>
pub fn dequantize_symmetric_int8_into( quantized: &[i8], parameters: QuantizationParameters, out: &mut [f64], ) -> Result<usize, MLError>
Dequantize a symmetric-int8 tensor into caller-owned floating-point storage.
Sourcepub fn prune_unstructured_into(
&mut self,
weights: &[f64],
sparsity: f64,
mask_out: &mut [u8],
values_out: &mut [f64],
scratch_indices: &mut [usize],
) -> Result<PruningReport, MLError>
pub fn prune_unstructured_into( &mut self, weights: &[f64], sparsity: f64, mask_out: &mut [u8], values_out: &mut [f64], scratch_indices: &mut [usize], ) -> Result<PruningReport, MLError>
Exact unstructured magnitude pruning.
The smallest-magnitude weights are removed. The result is a real sparse
representation: a packed keep-mask and the retained values in original
index order. scratch_indices is caller-provided sorting workspace.
Sourcepub fn prune_output_channels_into(
&mut self,
weights: &[f64],
rows: usize,
columns: usize,
sparsity: f64,
row_mask_out: &mut [u8],
values_out: &mut [f64],
score_scratch: &mut [f64],
index_scratch: &mut [usize],
) -> Result<PruningReport, MLError>
pub fn prune_output_channels_into( &mut self, weights: &[f64], rows: usize, columns: usize, sparsity: f64, row_mask_out: &mut [u8], values_out: &mut [f64], score_scratch: &mut [f64], index_scratch: &mut [usize], ) -> Result<PruningReport, MLError>
Structured output-channel pruning for a row-major rows × columns matrix.
Entire rows with the smallest L2 norm are removed and packed contiguously.
row_mask_out contains one keep bit per row.
Sourcepub fn unpack_pruned_weights_into(
mask: &[u8],
packed_values: &[f64],
out: &mut [f64],
) -> Result<usize, MLError>
pub fn unpack_pruned_weights_into( mask: &[u8], packed_values: &[f64], out: &mut [f64], ) -> Result<usize, MLError>
Reconstruct an unstructured sparse tensor into caller-owned dense storage.
Sourcepub fn distill_linear_student(
&mut self,
training_engine: &mut TrainingEngine,
teacher: &Model,
student: &mut Model,
training_data: &[f64],
hard_targets: Option<&[f64]>,
distillation: DistillationConfig,
training: &TrainingConfig,
target_buffer: &mut [f64],
) -> Result<DistillationReport, MLError>
pub fn distill_linear_student( &mut self, training_engine: &mut TrainingEngine, teacher: &Model, student: &mut Model, training_data: &[f64], hard_targets: Option<&[f64]>, distillation: DistillationConfig, training: &TrainingConfig, target_buffer: &mut [f64], ) -> Result<DistillationReport, MLError>
Distil any inference-supported teacher MLP into the existing single-linear
SGD student. Teacher outputs are generated from real forward passes and
optionally blended with hard targets in target_buffer.
Sourcepub fn record_compression(
&mut self,
algorithm_name: &str,
original_size: usize,
compressed_size: usize,
accuracy_before: f64,
accuracy_after: f64,
) -> Result<(), MLError>
pub fn record_compression( &mut self, algorithm_name: &str, original_size: usize, compressed_size: usize, accuracy_before: f64, accuracy_after: f64, ) -> Result<(), MLError>
Record the result of a compression operation and update the aggregate quality metrics.
Sourcepub fn get_quality_metrics(&self) -> &CompressionQualityMetrics
pub fn get_quality_metrics(&self) -> &CompressionQualityMetrics
Access the aggregate compression quality metrics.
Sourcepub fn get_compression_statistics(&self) -> &CompressionStatistics
pub fn get_compression_statistics(&self) -> &CompressionStatistics
Access byte counts and the ratio from the most recent real compression.
Sourcepub fn compression_ratio(&self) -> f64
pub fn compression_ratio(&self) -> f64
Return the overall compression ratio recorded so far.
Auto Trait Implementations§
impl Freeze for ModelCompression
impl RefUnwindSafe for ModelCompression
impl Send for ModelCompression
impl Sync for ModelCompression
impl Unpin for ModelCompression
impl UnsafeUnpin for ModelCompression
impl UnwindSafe for ModelCompression
Blanket Implementations§
§impl<S, A> Aggregate<Result<S, Error>> for Awhere
A: Aggregate<S>,
impl<S, A> Aggregate<Result<S, Error>> for Awhere
A: Aggregate<S>,
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<T> Instrument for T
impl<T> Instrument for T
§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
§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