Skip to main content

ModelCompression

Struct ModelCompression 

Source
pub struct ModelCompression { /* private fields */ }
Expand description

Model compression

Implementations§

Source§

impl ModelCompression

Source

pub fn new() -> Self

Source

pub fn initialize(&mut self) -> Result<(), MLError>

Source

pub fn register_algorithm( &mut self, name: &str, algorithm: CompressionAlgorithm, )

Register a compression algorithm under the given name.

Source

pub fn get_algorithm(&self, name: &str) -> Option<&CompressionAlgorithm>

Get a registered compression algorithm by name.

Source

pub fn list_algorithms(&self) -> Vec<String>

List the names of all registered compression algorithms.

Source

pub const fn pruning_mask_bytes(weight_count: usize) -> usize

Number of bytes needed for a packed one-bit-per-weight pruning mask.

Source

pub fn mask_keeps(mask: &[u8], weight_index: usize) -> bool

Return whether weight_index is present in a packed pruning mask.

Source

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.

Source

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.

Source

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.

Source

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.

Source

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.

Source

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.

Source

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.

Source

pub fn get_quality_metrics(&self) -> &CompressionQualityMetrics

Access the aggregate compression quality metrics.

Source

pub fn get_compression_statistics(&self) -> &CompressionStatistics

Access byte counts and the ratio from the most recent real compression.

Source

pub fn compression_ratio(&self) -> f64

Return the overall compression ratio recorded so far.

Auto Trait Implementations§

Blanket Implementations§

§

impl<S, A> Aggregate<Result<S, Error>> for A
where A: Aggregate<S>,

§

fn from_shares<T>(iter: T) -> Result<A, Error>
where T: IntoIterator<Item = Result<S, Error>>,

Aggregate shares in an MPC protocol.
Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
§

impl<T> Downcast<T> for T

§

fn downcast(&self) -> &T

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

§

impl<T> Instrument for T

§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided [Span], returning an Instrumented wrapper. Read more
§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

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
§

impl<T> Pointable for T

§

const ALIGN: usize

The alignment of pointer.
§

type Init = T

The type for initializers.
§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
§

impl<T> PolicyExt for T
where T: ?Sized,

§

fn and<P, B, E>(self, other: P) -> And<T, P>
where T: Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns [Action::Follow] only if self and other return Action::Follow. Read more
§

fn or<P, B, E>(self, other: P) -> Or<T, P>
where T: Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns [Action::Follow] if either self or other returns Action::Follow. Read more
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
§

impl<T> Upcast<T> for T

§

fn upcast(&self) -> Option<&T>

§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

§

fn vzip(self) -> V

§

impl<T> WithSubscriber for T

§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a [WithDispatch] wrapper. Read more
§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a [WithDispatch] wrapper. Read more
§

impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

§

impl<T> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

§

impl<T> WasmNotSend for T
where T: Send,

§

impl<T> WasmNotSendSync for T
where T: WasmNotSend + WasmNotSync,

§

impl<T> WasmNotSync for T
where T: Sync,