pub struct SmoothQuantCalibrator { /* private fields */ }Expand description
Online per-channel activation calibrator for SmoothQuant.
Feed batches of activations for each named linear layer via
record_activation, then call
smooth_factors to obtain the SmoothQuant
smoothing vector for that layer’s weight matrix.
Implementations§
Source§impl SmoothQuantCalibrator
impl SmoothQuantCalibrator
Sourcepub fn new(config: SmoothQuantConfig) -> Self
pub fn new(config: SmoothQuantConfig) -> Self
Create a new calibrator using the given SmoothQuant config.
Sourcepub fn record_activation(
&mut self,
layer_name: &str,
activations: &[f32],
in_features: usize,
)
pub fn record_activation( &mut self, layer_name: &str, activations: &[f32], in_features: usize, )
Record one batch of activations for a named layer.
activations is a [num_tokens × in_features] row-major flat slice.
If this is the first call for layer_name, a new per-channel accumulator
is created. For subsequent calls the running per-channel max-abs is updated.
§Panics
Panics if in_features changes between calls for the same layer_name.
Sourcepub fn smooth_factors(
&self,
layer_name: &str,
weights: &[f32],
out_features: usize,
) -> Result<Vec<f32>, SmoothQuantError>
pub fn smooth_factors( &self, layer_name: &str, weights: &[f32], out_features: usize, ) -> Result<Vec<f32>, SmoothQuantError>
Compute SmoothQuant smoothing factors for a named layer.
Uses the running per-channel activation max accumulated via
record_activation together with the supplied
weight matrix to derive per-input-feature smoothing factors.
weights is [out_features × in_features] row-major.
Returns a Vec<f32> of length in_features.
Sourcepub fn layer_count(&self) -> usize
pub fn layer_count(&self) -> usize
Number of distinct layers recorded by this calibrator.
Auto Trait Implementations§
impl Freeze for SmoothQuantCalibrator
impl RefUnwindSafe for SmoothQuantCalibrator
impl Send for SmoothQuantCalibrator
impl Sync for SmoothQuantCalibrator
impl Unpin for SmoothQuantCalibrator
impl UnsafeUnpin for SmoothQuantCalibrator
impl UnwindSafe for SmoothQuantCalibrator
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
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
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