• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

wildjames / predictive_coding_rs / 26030244354

18 May 2026 11:19AM UTC coverage: 89.597% (+1.0%) from 88.629%
26030244354

Pull #18

github

web-flow
Merge 84aa8ae92 into ab068c7f4
Pull Request #18: Implement the remaining GPU kernels

255 of 275 new or added lines in 12 files covered. (92.73%)

6 existing lines in 2 files now uncovered.

2067 of 2307 relevant lines covered (89.6%)

14.3 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

87.84
/src/training/handlers/singlethreaded.rs
1
//! Runtime-agnostic single-threaded training handler.
2

3
use crate::{
4
    data_handling::TrainingDataset,
5
    error::Result,
6
    model::{ModelSnapshot, PredictiveCodingModelConfig, TrainableModelRuntime},
7
    training::{TrainConfig, TrainingHandler},
8
};
9

10
use chrono::TimeDelta;
11
use std::sync::Arc;
12
use std::time::Instant;
13
use tracing::{debug, info};
14

15
use super::super::StepProfile;
16

17
pub struct SingleThreadTrainHandler<R: TrainableModelRuntime> {
18
    config: TrainConfig,
19
    runtime: R,
20
    data: Arc<dyn TrainingDataset>,
21
    file_output_prefix: String,
22
}
23

24
impl<R: TrainableModelRuntime> SingleThreadTrainHandler<R> {
25
    pub fn new(
4✔
26
        config: TrainConfig,
4✔
27
        runtime: R,
4✔
28
        data: Arc<dyn TrainingDataset>,
4✔
29
        file_output_prefix: String,
4✔
30
    ) -> Self {
4✔
31
        SingleThreadTrainHandler {
4✔
32
            config,
4✔
33
            runtime,
4✔
34
            data,
4✔
35
            file_output_prefix,
4✔
36
        }
4✔
37
    }
4✔
38

NEW
39
    pub fn runtime(&self) -> &R {
×
NEW
40
        &self.runtime
×
NEW
41
    }
×
42

NEW
43
    pub fn runtime_mut(&mut self) -> &mut R {
×
NEW
44
        &mut self.runtime
×
NEW
45
    }
×
46
}
47

48
impl<R: TrainableModelRuntime> TrainingHandler for SingleThreadTrainHandler<R> {
49
    fn get_config(&self) -> &TrainConfig {
6✔
50
        &self.config
6✔
51
    }
6✔
52
    fn model_snapshot(&mut self) -> Result<ModelSnapshot> {
6✔
53
        self.runtime.snapshot()
6✔
54
    }
6✔
55
    fn model_config(&self) -> PredictiveCodingModelConfig {
3✔
56
        self.runtime.config()
3✔
57
    }
3✔
58
    fn pin_input(&mut self) -> Result<()> {
1✔
59
        self.runtime.pin_input()
1✔
60
    }
1✔
61
    fn pin_output(&mut self) -> Result<()> {
1✔
62
        self.runtime.pin_output()
1✔
63
    }
1✔
64
    fn get_data(&self) -> &dyn TrainingDataset {
×
65
        self.data.as_ref()
×
66
    }
×
67
    fn get_file_output_prefix(&self) -> &String {
11✔
68
        &self.file_output_prefix
11✔
69
    }
11✔
70

71
    fn pre_training_hook(&mut self) -> Result<()> {
3✔
72
        info!(
3✔
73
            "Starting single-threaded training on {:?} backend",
74
            self.runtime.backend()
2✔
75
        );
76
        Ok(())
3✔
77
    }
3✔
78

79
    fn profiled_train_step(&mut self, _step: u32) -> Result<StepProfile> {
7✔
80
        let mut profile = StepProfile::new();
7✔
81

82
        let t = Instant::now();
7✔
83
        let (input, output) = self.data.get_random_input_and_output();
7✔
84
        self.runtime
7✔
85
            .set_input(input.as_slice().expect("contiguous input array"))?;
7✔
86
        self.runtime
7✔
87
            .set_output(output.as_slice().expect("contiguous output array"))?;
7✔
88
        profile.record("set_data", t.elapsed());
7✔
89

90
        let t = Instant::now();
7✔
91
        self.runtime.reinitialise_latents()?;
7✔
92
        profile.record("reinitialise_latents", t.elapsed());
7✔
93

94
        let t = Instant::now();
7✔
95
        self.runtime.converge_values()?;
7✔
96
        profile.record("converge_values", t.elapsed());
7✔
97

98
        let t = Instant::now();
7✔
99
        self.runtime.update_weights()?;
7✔
100
        profile.record("update_weights", t.elapsed());
7✔
101

102
        Ok(profile)
7✔
103
    }
7✔
104

105
    fn report_hook(&mut self, step: u32, mean_step_time: TimeDelta) -> Result<()> {
2✔
106
        debug!(
2✔
107
            "After step {}: mean step duration = {:.2?}",
108
            step, mean_step_time
109
        );
110

111
        let est_time_to_finish = mean_step_time * (self.config.training_steps - step) as i32;
2✔
112
        let est_finish_time = chrono::Utc::now() + est_time_to_finish;
2✔
113

114
        let energy = self.runtime.total_energy()?;
2✔
115
        info!(
2✔
116
            "Step {}: Current model state: energy = {:.2}\tEstimated finish time: {}",
117
            step,
118
            energy,
119
            est_finish_time.format("%Y-%m-%d %H:%M:%S")
2✔
120
        );
121
        Ok(())
2✔
122
    }
2✔
123
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc