pub struct TensorCheckpointScheduler {
pub config: SchedulerConfig,
pub checkpoints: Vec<CheckpointRecord>,
pub next_checkpoint_id: u64,
pub last_checkpoint_step: u64,
pub last_checkpoint_tick: u64,
pub best_loss: f64,
pub stats: SchedulerStats,
}Expand description
Manages automatic scheduling of tensor checkpoint saves.
Evaluates a configurable list of CheckpointTriggers on each call to
advance and records a checkpoint
whenever the first matching trigger fires.
Fields§
§config: SchedulerConfigConfiguration (triggers + retention policy).
checkpoints: Vec<CheckpointRecord>Ordered (oldest-first) list of saved checkpoint records.
next_checkpoint_id: u64Next checkpoint ID to assign (starts at 0, increments after use).
last_checkpoint_step: u64Training step at which the last checkpoint was saved.
last_checkpoint_tick: u64Tick value at which the last checkpoint was saved.
best_loss: f64Best (lowest) loss seen so far; initialised to f64::MAX.
stats: SchedulerStatsRunning statistics.
Implementations§
Source§impl TensorCheckpointScheduler
impl TensorCheckpointScheduler
Sourcepub fn new(config: SchedulerConfig) -> Self
pub fn new(config: SchedulerConfig) -> Self
Create a new scheduler with the given configuration.
Sourcepub fn should_checkpoint(
&self,
current_step: u64,
current_loss: f64,
current_tick: u64,
) -> Option<CheckpointTrigger>
pub fn should_checkpoint( &self, current_step: u64, current_loss: f64, current_tick: u64, ) -> Option<CheckpointTrigger>
Evaluate all configured triggers and return the first one that fires,
or None if no trigger is currently satisfied.
Trigger semantics:
StepInterval { every_n_steps: n }: fires whencurrent_step > 0AND(current_step − last_checkpoint_step) >= n.LossImprovement { min_delta: d }: fires whenbest_loss == f64::MAX(first observation) OR(best_loss − current_loss) >= d.TickInterval { every_n_ticks: n }: fires whencurrent_tick > 0AND(current_tick − last_checkpoint_tick) >= n.
Sourcepub fn record_checkpoint(
&mut self,
step: u64,
loss: f64,
trigger: CheckpointTrigger,
current_tick: u64,
) -> u64
pub fn record_checkpoint( &mut self, step: u64, loss: f64, trigger: CheckpointTrigger, current_tick: u64, ) -> u64
Record a checkpoint save event.
Updates internal state (step/tick cursors, best loss) and statistics,
then prunes the oldest record if the history exceeds max_checkpoints.
Returns the newly assigned checkpoint ID.
Sourcepub fn advance(
&mut self,
step: u64,
loss: f64,
current_tick: u64,
) -> Option<u64>
pub fn advance( &mut self, step: u64, loss: f64, current_tick: u64, ) -> Option<u64>
Advance the scheduler by one observation.
Evaluates triggers; if one fires, records a checkpoint and returns
Some(checkpoint_id). Returns None when no checkpoint is needed.
Sourcepub fn latest_checkpoint(&self) -> Option<&CheckpointRecord>
pub fn latest_checkpoint(&self) -> Option<&CheckpointRecord>
Return a reference to the most recently saved checkpoint record, if any.
Sourcepub fn stats(&self) -> &SchedulerStats
pub fn stats(&self) -> &SchedulerStats
Return a reference to the cumulative statistics.
Auto Trait Implementations§
impl Freeze for TensorCheckpointScheduler
impl RefUnwindSafe for TensorCheckpointScheduler
impl Send for TensorCheckpointScheduler
impl Sync for TensorCheckpointScheduler
impl Unpin for TensorCheckpointScheduler
impl UnsafeUnpin for TensorCheckpointScheduler
impl UnwindSafe for TensorCheckpointScheduler
Blanket Implementations§
impl<T> Allocation for T
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more