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
impl Clone for TrainingConfig
Source§fn clone(&self) -> TrainingConfig
fn clone(&self) -> TrainingConfig
1.0.0 · Source§const fn clone_from(&mut self, source: &Self)
const fn clone_from(&mut self, source: &Self)
source
. Read moreSource§impl Debug for TrainingConfig
impl Debug for TrainingConfig
Auto Trait Implementations§
impl Freeze for TrainingConfig
impl RefUnwindSafe for TrainingConfig
impl Send for TrainingConfig
impl Sync for TrainingConfig
impl Unpin for TrainingConfig
impl UnwindSafe for TrainingConfig
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
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
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