pub struct TrainingEngine { /* private fields */ }Expand description
Training engine
Implementations§
Source§impl TrainingEngine
impl TrainingEngine
pub fn new() -> Self
pub fn initialize(&mut self) -> Result<(), MLError>
Sourcepub fn register_backend(&mut self, backend: TrainingBackend)
pub fn register_backend(&mut self, backend: TrainingBackend)
Register a training backend under its backend id.
Sourcepub fn get_backend(&self, backend_id: &str) -> Option<&TrainingBackend>
pub fn get_backend(&self, backend_id: &str) -> Option<&TrainingBackend>
Get a registered training backend by id.
Sourcepub fn list_backends(&self) -> Vec<String>
pub fn list_backends(&self) -> Vec<String>
List the ids of all registered training backends.
Sourcepub fn remove_backend(&mut self, backend_id: &str) -> bool
pub fn remove_backend(&mut self, backend_id: &str) -> bool
Remove a registered training backend by id. Returns true if removed.
Sourcepub fn start_training_job(&mut self, _job: &TrainingJob) -> Result<(), MLError>
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.
Sourcepub fn start_training(
&mut self,
model: &mut Model,
training_data: &[f64],
targets: &[f64],
config: &TrainingConfig,
) -> Result<TrainingResult, MLError>
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).
Sourcepub fn start_training_with_pruning_mask(
&mut self,
model: &mut Model,
training_data: &[f64],
targets: &[f64],
config: &TrainingConfig,
pruning_mask: &[u8],
) -> Result<TrainingResult, MLError>
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.
Sourcepub fn compute_mse(predictions: &[f64], targets: &[f64]) -> f64
pub fn compute_mse(predictions: &[f64], targets: &[f64]) -> f64
Mean squared error between predictions and targets: (1/N) * sum (p - t)^2.
Sourcepub fn compute_gradients(
weights: &[f64],
inputs: &[f64],
prediction: f64,
target: f64,
learning_rate: f64,
) -> Vec<f64>
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§
impl Freeze for TrainingEngine
impl RefUnwindSafe for TrainingEngine
impl Send for TrainingEngine
impl Sync for TrainingEngine
impl Unpin for TrainingEngine
impl UnsafeUnpin for TrainingEngine
impl UnwindSafe for TrainingEngine
Blanket Implementations§
§impl<S, A> Aggregate<Result<S, Error>> for Awhere
A: Aggregate<S>,
impl<S, A> Aggregate<Result<S, Error>> for Awhere
A: Aggregate<S>,
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<T> Instrument for T
impl<T> Instrument for T
§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
§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