Skip to main content

TrainingSession

Enum TrainingSession 

Source
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

Source

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.

Source

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.

Source

pub fn train_epoch(&mut self) -> Result<f32, NetworkError>

Source

pub fn checkpoint(&mut self) -> Result<CudaTrainingCheckpoint, NetworkError>

Source

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.

Source

pub fn stats(&self) -> &AcceleratorStats

Source

pub fn epoch(&self) -> usize

Source

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.

Source

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.

Source

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§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ

Converts 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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
where F: FnOnce(&Self) -> bool,

Converts 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
Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V