pub struct FeatureDistiller {
pub layers: Vec<(f32, DistilLoss)>,
}Expand description
Feature-based knowledge distillation.
Maintains a list of (weight, DistilLoss) pairs, one per distillation layer.
Fields§
§layers: Vec<(f32, DistilLoss)>Per-layer distillation configuration: (weight, loss).
Implementations§
Source§impl FeatureDistiller
impl FeatureDistiller
Sourcepub fn uniform_mse(n_layers: usize) -> Self
pub fn uniform_mse(n_layers: usize) -> Self
Create a feature distiller with equal-weight MSE loss for each layer.
§Parameters
n_layers— number of intermediate layers to distil.
Sourcepub fn with_weights(weights: Vec<f32>, loss: DistilLoss) -> Self
pub fn with_weights(weights: Vec<f32>, loss: DistilLoss) -> Self
Create a feature distiller with custom per-layer weights and a shared loss.
Sourcepub fn compute_layer_loss(
&self,
layer_index: usize,
teacher_feat: &[f32],
student_feat: &[f32],
) -> QuantResult<f32>
pub fn compute_layer_loss( &self, layer_index: usize, teacher_feat: &[f32], student_feat: &[f32], ) -> QuantResult<f32>
Compute the distillation loss for a single layer pair.
§Errors
QuantError::DimensionMismatch—layer_indexout of range.- Propagates errors from the underlying
DistilLoss.
Sourcepub fn compute_total_loss(
&self,
teacher_feats: &[&[f32]],
student_feats: &[&[f32]],
) -> QuantResult<f32>
pub fn compute_total_loss( &self, teacher_feats: &[&[f32]], student_feats: &[&[f32]], ) -> QuantResult<f32>
Compute the total feature distillation loss across all layers.
teacher_feats[l] and student_feats[l] must have matching lengths.
§Errors
QuantError::DimensionMismatch— wrong number of feature arrays.- Propagates per-layer errors.
Sourcepub fn normalise_weights(&mut self)
pub fn normalise_weights(&mut self)
Normalise layer weights so they sum to 1.
Trait Implementations§
Source§impl Clone for FeatureDistiller
impl Clone for FeatureDistiller
Source§fn clone(&self) -> FeatureDistiller
fn clone(&self) -> FeatureDistiller
Returns a duplicate of the value. Read more
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreAuto Trait Implementations§
impl Freeze for FeatureDistiller
impl RefUnwindSafe for FeatureDistiller
impl Send for FeatureDistiller
impl Sync for FeatureDistiller
impl Unpin for FeatureDistiller
impl UnsafeUnpin for FeatureDistiller
impl UnwindSafe for FeatureDistiller
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