Skip to main content

TrainingEngine

Struct TrainingEngine 

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

Training engine

Implementations§

Source§

impl TrainingEngine

Source

pub fn new() -> Self

Source

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

Source

pub fn register_backend(&mut self, backend: TrainingBackend)

Register a training backend under its backend id.

Source

pub fn get_backend(&self, backend_id: &str) -> Option<&TrainingBackend>

Get a registered training backend by id.

Source

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

List the ids of all registered training backends.

Source

pub fn remove_backend(&mut self, backend_id: &str) -> bool

Remove a registered training backend by id. Returns true if removed.

Source

pub fn start_training_job(&mut self, _job: &TrainingJob) -> Result<(), MLError>

Start a training job (the catalog/scheduler path). This records the job with the scheduler but performs no weight updates; use [start_training] for the real SGD loop that mutates a model’s weights.

Source

pub fn start_training( &mut self, model: &mut Model, training_data: &[f64], targets: &[f64], config: &TrainingConfig, ) -> Result<TrainingResult, MLError>

Run a real stochastic gradient descent (SGD) training loop on a linear model.

This implements basic batch SGD for a single Linear layer with no activation (i.e. linear regression). For each epoch the samples are deterministically shuffled (a fixed-seed Fisher–Yates, so runs are reproducible), then processed in batches: a forward pass computes predictions, the MSE loss and its gradients are computed, and the weights are updated as W -= learning_rate * gradient.

training_data is a flat buffer of inputs laid out as [s0_i0, s0_i1, ..., s1_i0, ...] with input_size = architecture.layers[0].input_shape[0]. targets is laid out as [s0_o0, s0_o1, ..., s1_o0, ...] with output_size = architecture.layers[0].output_shape[0].

Only TrainingAlgorithm::SGD is implemented here; other optimizers return a clear error rather than silently degrading. Only a single Linear layer with no activation is supported (the explicit scope of this training backend).

Source

pub fn start_training_with_pruning_mask( &mut self, model: &mut Model, training_data: &[f64], targets: &[f64], config: &TrainingConfig, pruning_mask: &[u8], ) -> Result<TrainingResult, MLError>

Run SGD recovery while preserving an unstructured pruning mask.

Masked weights are forced to zero before training and skipped during every optimizer update, so recovery cannot silently regrow them.

Source

pub fn compute_mse(predictions: &[f64], targets: &[f64]) -> f64

Mean squared error between predictions and targets: (1/N) * sum (p - t)^2.

Source

pub fn compute_gradients( weights: &[f64], inputs: &[f64], prediction: f64, target: f64, learning_rate: f64, ) -> Vec<f64>

Compute the MSE gradient (scaled by learning_rate) for a single linear sample.

For a linear model y = W·x + b with weights = [W (out×in), b (out)], the MSE loss for one sample is L = sum_j (pred_j - target_j)^2. The returned vector has the same layout as weights and contains learning_rate * dL/dweight, i.e. the amount to subtract from each weight. (For a single-output model pred and target are scalars and inputs is the input vector.)

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,