use std::sync::Arc;
use tokio_postgres::Client;
#[async_trait::async_trait]
pub trait Trainer: Send + Sync + Sized {
fn client(&self) -> &Arc<Client>;
async fn sync(self);
async fn step(&mut self);
async fn epoch(&self) -> usize;
async fn summary(&self) -> String;
async fn checkpoint(&self) -> Option<String>;
async fn train(mut self) {
log::info!("training blueprint");
log::info!("press 'Q + ↵' to stop gracefully");
loop {
self.step().await;
self.checkpoint().await.map(|s| log::info!("{}", s));
if rbp_core::interrupted() {
log::info!("{}", self.summary().await);
break;
}
}
self.sync().await;
}
}