pub struct DistillationTrainer {
pub config: DistillationConfig,
}Expand description
Knowledge distillation trainer
Fields§
§config: DistillationConfigTraining configuration
Implementations§
Source§impl DistillationTrainer
impl DistillationTrainer
Sourcepub fn new(config: DistillationConfig) -> Self
pub fn new(config: DistillationConfig) -> Self
Creates a new distillation trainer
Sourcepub fn default_trainer() -> Self
pub fn default_trainer() -> Self
Creates a trainer with default configuration
Sourcepub fn compute_distillation_loss(
&self,
teacher_logits: &[f32],
student_logits: &[f32],
) -> f32
pub fn compute_distillation_loss( &self, teacher_logits: &[f32], student_logits: &[f32], ) -> f32
Computes the distillation loss for a single sample
Sourcepub fn compute_combined_loss(
&self,
teacher_logits: &[f32],
student_logits: &[f32],
hard_label: usize,
) -> f32
pub fn compute_combined_loss( &self, teacher_logits: &[f32], student_logits: &[f32], hard_label: usize, ) -> f32
Computes the combined loss (distillation + hard label)
Sourcepub fn compute_loss_gradient(
&self,
teacher_logits: &[f32],
student_logits: &[f32],
hard_label: usize,
) -> Vec<f32>
pub fn compute_loss_gradient( &self, teacher_logits: &[f32], student_logits: &[f32], hard_label: usize, ) -> Vec<f32>
Computes gradient of combined loss w.r.t. student logits
Sourcepub fn train_with_teacher_outputs(
&self,
teacher_outputs: &[Vec<f32>],
training_inputs: &[Vec<f32>],
training_labels: &[usize],
initial_weights: &[f32],
) -> Result<DistillationStats>
pub fn train_with_teacher_outputs( &self, teacher_outputs: &[Vec<f32>], training_inputs: &[Vec<f32>], training_labels: &[usize], initial_weights: &[f32], ) -> Result<DistillationStats>
Trains a student model using pre-computed teacher outputs
Trait Implementations§
Source§impl Clone for DistillationTrainer
impl Clone for DistillationTrainer
Source§fn clone(&self) -> DistillationTrainer
fn clone(&self) -> DistillationTrainer
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 DistillationTrainer
impl RefUnwindSafe for DistillationTrainer
impl Send for DistillationTrainer
impl Sync for DistillationTrainer
impl Unpin for DistillationTrainer
impl UnsafeUnpin for DistillationTrainer
impl UnwindSafe for DistillationTrainer
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
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
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>
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 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>
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