pub enum TrainingSession {}Expand description
A persistent device session, whichever backend is behind it.
Epoch-at-a-time training exists because a campaign checkpoints and
early-stops after every epoch. Calling fit_with_backend once per epoch
would rebuild the device context, the compiled kernels, and every buffer
each time; a session keeps all of that, and the training set, resident.
Implementations§
Source§impl TrainingSession
impl TrainingSession
Sourcepub fn new(
network: &Network,
dataset: &Dataset,
config: TrainConfig,
backend: TrainingBackend,
) -> Result<Option<Self>, NetworkError>
pub fn new( network: &Network, dataset: &Dataset, config: TrainConfig, backend: TrainingBackend, ) -> Result<Option<Self>, NetworkError>
Opens a session for backend, or Ok(None) when the request is
TrainingBackend::Cpu and the caller should use Network::fit.
Sourcepub fn from_checkpoint(
checkpoint: CudaTrainingCheckpoint,
dataset: &Dataset,
config: TrainConfig,
backend: TrainingBackend,
) -> Result<Option<Self>, NetworkError>
pub fn from_checkpoint( checkpoint: CudaTrainingCheckpoint, dataset: &Dataset, config: TrainConfig, backend: TrainingBackend, ) -> Result<Option<Self>, NetworkError>
Resumes a session from a host checkpoint, replaying the shuffle so the resumed run sees the same batches it would have seen without the crash.
pub fn train_epoch(&mut self) -> Result<f32, NetworkError>
pub fn checkpoint(&mut self) -> Result<CudaTrainingCheckpoint, NetworkError>
Sourcepub fn synchronize_network(
&mut self,
network: &mut Network,
) -> Result<(), NetworkError>
pub fn synchronize_network( &mut self, network: &mut Network, ) -> Result<(), NetworkError>
Copies device state back into network, so host-side validation and
campaign checkpoints see the weights this epoch produced.
pub fn stats(&self) -> &AcceleratorStats
pub fn epoch(&self) -> usize
Sourcepub fn supports_device_validation(&self) -> bool
pub fn supports_device_validation(&self) -> bool
True only for backends with a device-side validation path (CUDA
today). Callers should keep using the host evaluate_loss
round-trip on any backend this returns false for, Metal included:
it has no prepare_validation/validate_epoch implementation.
Sourcepub fn prepare_validation(
&mut self,
dataset: &Dataset,
budget_mib: usize,
) -> Result<bool, NetworkError>
pub fn prepare_validation( &mut self, dataset: &Dataset, budget_mib: usize, ) -> Result<bool, NetworkError>
Uploads dataset once so validate_epoch can score it on-device.
Only call when supports_device_validation() is true. Returns
Ok(false) (not an error) when it would not fit the device budget
alongside what training already uses; the caller should fall back to
host-side validation for the whole session in that case.
Sourcepub fn validate_epoch(&mut self) -> Result<f32, NetworkError>
pub fn validate_epoch(&mut self) -> Result<f32, NetworkError>
Device-side validation loss over the set uploaded by
prepare_validation, using the weights currently resident on the
device. No host copy of the model is needed to compute it.
Auto Trait Implementations§
impl Freeze for TrainingSession
impl RefUnwindSafe for TrainingSession
impl Send for TrainingSession
impl Sync for TrainingSession
impl Unpin for TrainingSession
impl UnsafeUnpin for TrainingSession
impl UnwindSafe for TrainingSession
Blanket Implementations§
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
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