burn_train/logger/progress.rs
1use burn_core::data::dataloader::Progress;
2
3/// Trait for logging training progress at each step and end of epoch.
4///
5/// # Call sequence
6///
7/// Implementors can expect the following sequence of calls for a complete training run:
8///
9/// ```text
10/// start(total_epochs, total_items)
11/// for each epoch:
12/// start_split("train", total_items_train)
13/// update_split(items_processed) // called once per batch
14/// ...
15/// end_split()
16/// start_split("valid", total_items_valid)
17/// update_split(items_processed) // called once per batch
18/// ...
19/// end_split()
20/// update_epoch(epoch)
21/// end()
22/// ```
23///
24/// `end()` is called whether training completes normally or is interrupted early.
25///
26/// Implementors are responsible for tracking `total_items` and epoch state in order
27/// to reconstruct the full progress picture when `update_split` is called.
28pub trait TrainingProgressLogger: Send {
29 /// Called once at the start of training, providing the total number of epochs and the starting epoch.
30 ///
31 /// The total number of items of the training can optionally be provided if it is known.
32 fn start(
33 &mut self,
34 total_epochs: usize,
35 starting_epoch: usize,
36 total_items: Option<usize>,
37 label: Option<&str>,
38 );
39
40 /// Called at the end of each full epoch (after both train and valid splits complete).
41 fn update_epoch(&mut self, epoch: usize);
42
43 /// Called at the start of a training split, providing the split name and total number of items.
44 fn start_split(&mut self, split: &str, total_items: usize);
45
46 /// Log the progress of the current training step.
47 fn update_split(&mut self, items_processed: usize);
48
49 /// Called at the end of a training split.
50 fn end_split(&mut self);
51
52 /// Called at the end of training, whether it completed successfully or was interrupted.
53 fn end(&mut self);
54
55 /// Log a custom named event that falls outside the standard training lifecycle callbacks.
56 fn log_event_training(&mut self, event: String);
57}
58
59/// Trait for logging evaluation progress at each step and end of evaluation.
60///
61/// # Call sequence
62///
63/// Implementors can expect the following sequence of calls for a complete evaluation run:
64///
65/// ```text
66/// start_global_progress(total_tests)
67/// for each test split:
68/// start_test(name, total_items)
69/// update_test_progress(items_processed) // called once per batch
70/// ...
71/// end_test()
72/// end_global_progress()
73/// ```
74///
75/// `end_global_progress()` is called whether evaluation completes normally or is interrupted early.
76///
77/// Implementors are responsible for tracking `total_tests` and `total_items` (stored from
78/// `start_global_progress` and `start_test`) to reconstruct the full progress picture.
79pub trait EvaluationProgressLogger: Send {
80 /// Called once at the start of evaluation, providing the total number of test splits.
81 fn start_global_progress(&mut self, total_tests: usize);
82
83 /// Called at the start of a test split, providing the split name and total number of items.
84 fn start_test(&mut self, name: &str, total_items: usize);
85
86 /// Log the progress of the current test step.
87 fn update_test_progress(&mut self, items_processed: usize);
88
89 /// Called at the end of a test split.
90 fn end_test(&mut self);
91
92 /// Called at the end of evaluation.
93 fn end_global_progress(&mut self);
94
95 /// Log a custom named event that falls outside the standard evaluation lifecycle callbacks.
96 fn log_event_evaluation(&mut self, event: String);
97}
98
99/// Two-level progress snapshot combining run-level and phase-level tracking.
100///
101/// `global_progress` spans the full training run (e.g., epochs completed out of total),
102/// while `split_progress` tracks the current phase (e.g., batches within the current epoch).
103#[derive(Debug, Clone)]
104pub struct ProgressSnapshot {
105 /// Progress across the entire training run.
106 pub global: Progress,
107 /// Progress within the current phase (epoch or evaluation split).
108 pub split: Progress,
109}
110
111impl ProgressSnapshot {
112 /// Create a new overall progress snapshot.
113 pub fn new(global: Progress, split: Progress) -> Self {
114 Self { global, split }
115 }
116}