1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
//! The training configuration for the training process.

use crate::{prelude::*, LearningRate, Optimizer};

/// The training configuration for the training process.
#[derive(Debug, Serialize, Deserialize)]
pub struct Training {
    /// The optimizer to use for the training process.
    pub optimizer: Optimizer,
    /// The learning rate to use for the training process.
    pub learning_rate: LearningRate
}

impl Default for Training {
    fn default() -> Self {
        let optimizer = Optimizer::Adafactor;
        let learning_rate = LearningRate::default();
        Training { optimizer, learning_rate }
    }
}

impl Training {
    /// Create a new training configuration.
    pub fn new() -> Self {
        Default::default()
    }

    /// Set the optimizer for the training process.
    pub fn with_optimizer(mut self, optimizer: Optimizer) -> Self {
        self.optimizer = optimizer;
        self
    }

    /// Set the learning rate for the training process.
    pub fn with_learning_rate(mut self, learning_rate: LearningRate) -> Self {
        self.learning_rate = learning_rate;
        self
    }
}