Skip to main content

burn_optim/lr_scheduler/
constant.rs

1use super::{LrScheduler, LrSchedulerRecord};
2use crate::LearningRate;
3
4/// Constant learning rate implementing [learning rate scheduler](LrScheduler).
5///
6/// # Notes
7///
8/// You can also use [learning rate](LearningRate) which the same effect.
9#[derive(new, Clone, Debug)]
10pub struct ConstantLr {
11    lr: LearningRate,
12}
13
14impl From<LearningRate> for ConstantLr {
15    fn from(lr: LearningRate) -> Self {
16        Self { lr }
17    }
18}
19
20impl LrScheduler for ConstantLr {
21    fn step(&mut self) -> LearningRate {
22        self.lr
23    }
24
25    fn to_record(&self) -> LrSchedulerRecord {
26        LrSchedulerRecord::new()
27    }
28
29    fn load_record(&mut self, _record: LrSchedulerRecord) {}
30}
31
32impl LrScheduler for LearningRate {
33    fn step(&mut self) -> LearningRate {
34        *self
35    }
36
37    fn to_record(&self) -> LrSchedulerRecord {
38        LrSchedulerRecord::new()
39    }
40
41    fn load_record(&mut self, _record: LrSchedulerRecord) {}
42}