Skip to main content

SteTrainer

Struct SteTrainer 

Source
pub struct SteTrainer {
    pub w1_latent: Vec<f32>,
    pub w2_latent: Vec<f32>,
    pub in_features: usize,
    pub hidden_size: usize,
    pub out_features: usize,
    pub config: QatConfig,
}
Expand description

Maintains latent f32 shadow weights for a 2-layer MLP. During each training step:

  1. Quantize latent weights → ternary {-1, 0, +1}
  2. Forward pass (f32 arithmetic on quantized weights)
  3. MSE loss + backprop through STE
  4. SGD update on latent weights

Fields§

§w1_latent: Vec<f32>§w2_latent: Vec<f32>§in_features: usize§hidden_size: usize§out_features: usize§config: QatConfig

Implementations§

Source§

impl SteTrainer

Source

pub fn from_mlp(mlp: &TernaryMLP, config: QatConfig) -> Self

Initialise from an existing TernaryMLP’s quantized weights. The ternary {-1,0,+1} values become the initial latent floats.

Source

pub fn from_f32( in_features: usize, hidden_size: usize, out_features: usize, w1_f32: Vec<f32>, w2_f32: Vec<f32>, config: QatConfig, ) -> Self

Initialise from raw f32 weights (quantization happens at first step).

Source

pub fn train_step(&mut self, input: &[f32], target: &[f32]) -> f32

One SGD step on a single sample.

input — flat f32 row vector, length in_features target — flat f32 row vector, length out_features

Returns the MSE loss for this sample.

Source

pub fn train(&mut self, samples: &[(Vec<f32>, Vec<f32>)]) -> QatResult

Run the full training loop over a dataset.

samples — slice of (input, target) pairs

Source

pub fn finalize(&self) -> TernaryMLP

Finalise training: quantize latent weights and return a TernaryMLP.

Auto Trait Implementations§

Blanket Implementations§

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

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

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

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

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

Initializes a with the given initializer. Read more
Source§

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

Dereferences the given pointer. Read more
Source§

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

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
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.