Struct TrainingConfig

Source
pub struct TrainingConfig {
    pub batch_size: usize,
    pub shuffle: bool,
    pub num_workers: usize,
    pub learning_rate: f64,
    pub epochs: usize,
    pub verbose: usize,
    pub validation: Option<ValidationSettings>,
    pub gradient_accumulation: Option<GradientAccumulationConfig>,
    pub mixed_precision: Option<MixedPrecisionConfig>,
}
Expand description

Configuration for neural network training

This structure contains all the parameters needed to configure a training session, including batch size, learning rate, optimization settings, and advanced features like gradient accumulation and mixed precision training.

§Examples

§Basic Configuration

use scirs2_neural::training::TrainingConfig;

let config = TrainingConfig {
    batch_size: 64,
    epochs: 20,
    learning_rate: 0.001,
    shuffle: true,
    verbose: 1,
    ..Default::default()
};

§Configuration for Large Models (with gradient accumulation)

use scirs2_neural::training::{TrainingConfig, GradientAccumulationConfig};

let config = TrainingConfig {
    batch_size: 8,  // Small batch due to memory constraints
    gradient_accumulation: Some(GradientAccumulationConfig {
        accumulation_steps: 8,  // Effective batch size: 64
        clip_gradients: true,
        average_gradients: true,
        zero_gradients_after_update: true,
        max_gradient_norm: Some(1.0),
        log_gradient_stats: false,
    }),
    ..Default::default()
};

Fields§

§batch_size: usize

Number of samples in each training batch

Larger batch sizes provide more stable gradients but require more memory. Typical values range from 16 to 512 depending on model size and hardware.

§shuffle: bool

Whether to shuffle the training data between epochs

Shuffling helps prevent the model from learning the order of data presentation and generally improves training stability and generalization.

§num_workers: usize

Number of parallel workers for data loading

Setting this to 0 uses the main thread for data loading. Higher values can speed up training if data loading is a bottleneck.

§learning_rate: f64

Base learning rate for the optimizer

This is the step size used for parameter updates. Too high values can cause training instability, while too low values lead to slow convergence. Typical values range from 1e-5 to 1e-1 depending on the optimizer and model.

§epochs: usize

Number of complete passes through the training dataset

One epoch means seeing each training example exactly once. More epochs allow for better learning but risk overfitting.

§verbose: usize

Verbosity level for training output

  • 0: Silent mode (no output)
  • 1: Progress bar with metrics (default)
  • 2: One line per epoch with detailed metrics
§validation: Option<ValidationSettings>

Validation configuration

If provided, enables validation during training with the specified settings. Validation helps monitor overfitting and model generalization.

§gradient_accumulation: Option<GradientAccumulationConfig>

Gradient accumulation configuration

Enables accumulating gradients over multiple batches before applying updates. Useful for simulating larger batch sizes when memory is limited.

§mixed_precision: Option<MixedPrecisionConfig>

Mixed precision training configuration

Enables training with mixed precision (FP16/FP32) to reduce memory usage and potentially speed up training on compatible hardware.

Trait Implementations§

Source§

impl Clone for TrainingConfig

Source§

fn clone(&self) -> TrainingConfig

Returns a duplicate of the value. Read more
1.0.0 · Source§

const fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for TrainingConfig

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for TrainingConfig

Source§

fn default() -> Self

Returns the “default value” for a type. Read more

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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. 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> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. 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.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V