burn_train/renderer/
cli.rs1use burn_core::data::dataloader::Progress;
2
3use crate::{
4 logger::{EvaluationProgressLogger, ProgressSnapshot, TrainingProgressLogger},
5 renderer::{MetricState, MetricsRenderer, MetricsRendererEvaluation, MetricsRendererTraining},
6};
7
8pub struct CliMetricsRenderer {
10 label: String,
11 training_progress: ProgressSnapshot,
12 eval_progress: ProgressSnapshot,
13}
14
15#[allow(clippy::new_without_default)]
16impl CliMetricsRenderer {
17 pub fn new() -> Self {
19 let init = Progress::new(0, 0, Some(String::new()));
20 Self {
21 training_progress: ProgressSnapshot::new(init.clone(), init.clone()),
22 eval_progress: ProgressSnapshot::new(init.clone(), init),
23 label: String::from("training"),
24 }
25 }
26}
27
28impl MetricsRendererTraining for CliMetricsRenderer {
29 fn update_train(&mut self, _state: MetricState) {}
30
31 fn update_valid(&mut self, _state: MetricState) {}
32}
33
34impl TrainingProgressLogger for CliMetricsRenderer {
35 fn start(
36 &mut self,
37 total_epochs: usize,
38 starting_epoch: usize,
39 total_items: Option<usize>,
40 label: Option<&str>,
41 ) {
42 self.training_progress.global =
43 Progress::new(starting_epoch, total_epochs, Some("epochs".to_string()));
44 if let Some(items) = total_items {
45 self.training_progress.split = Progress::new(0, items, Some("items".to_string()));
46 }
47 self.label = label.unwrap_or("training").to_string();
48 println!("Starting {} for {} epochs.", self.label, total_epochs);
49 }
50
51 fn start_split(&mut self, split_name: &str, total_items: usize) {
52 self.training_progress.split = Progress::new(0, total_items, Some("items".to_string()));
53 println!("Starting split '{split_name}' with {total_items} items.");
54 }
55
56 fn update_split(&mut self, items_processed: usize) {
57 let total = self.training_progress.split.items_total;
58 let unit = self.training_progress.split.unit.clone();
59 self.training_progress.split = Progress::new(items_processed, total, unit);
60
61 if self.training_progress.global.items_total == 0 {
63 self.training_progress.global = self.training_progress.split.clone();
64 }
65 println!("{:?}", self.training_progress);
66 }
67
68 fn update_epoch(&mut self, epoch: usize) {
69 let total = self.training_progress.global.items_total;
70 let unit = self.training_progress.global.unit.clone();
71 self.training_progress.global = Progress::new(epoch + 1, total, unit);
72 }
73
74 fn end_split(&mut self) {
75 println!("Split ended.");
76 }
77
78 fn end(&mut self) {
79 println!("{} ended.", self.label);
80 }
81
82 fn log_event_training(&mut self, _event: String) {}
83}
84
85impl EvaluationProgressLogger for CliMetricsRenderer {
86 fn start_global_progress(&mut self, total_tests: usize) {
87 self.eval_progress.global = Progress::new(0, total_tests, Some("tests".to_string()));
88 println!("Starting evaluation with {total_tests} test(s).");
89 }
90
91 fn start_test(&mut self, name: &str, total_items: usize) {
92 let current = self.eval_progress.global.items_processed + 1;
93 let total = self.eval_progress.global.items_total;
94 self.eval_progress.global = Progress::new(current, total, Some("tests".to_string()));
95 self.eval_progress.split = Progress::new(0, total_items, Some("items".to_string()));
96 println!("Starting test '{name}' with {total_items} items.");
97 }
98
99 fn update_test_progress(&mut self, items_processed: usize) {
100 let total = self.eval_progress.split.items_total;
101 let unit = self.eval_progress.split.unit.clone();
102 self.eval_progress.split = Progress::new(items_processed, total, unit);
103 println!("{:?}", self.eval_progress);
104 }
105
106 fn end_test(&mut self) {}
107
108 fn end_global_progress(&mut self) {}
109
110 fn log_event_evaluation(&mut self, _event: String) {}
111}
112
113impl MetricsRendererEvaluation for CliMetricsRenderer {
114 fn update_test(&mut self, _name: super::EvaluationName, _state: MetricState) {}
115}
116
117impl MetricsRenderer for CliMetricsRenderer {
118 fn manual_close(&mut self) {}
119
120 fn register_metric(&mut self, _definition: crate::metric::MetricDefinition) {}
121}