Skip to main content

StatefulTokenBatchSampler

Struct StatefulTokenBatchSampler 

Source
pub struct StatefulTokenBatchSampler { /* private fields */ }
Available on crate feature std only.
Expand description

Greedy contiguous token-budget batches over the actual distributed order.

This changes batch boundaries only. Encoded lengths must describe the actual examples returned by the immutable source. No tokenization, truncation, length sorting, duplicate tail rows or cross-document supervision is inferred. Different DP coordinates can have different batch counts; the caller must use its training coordinator’s actual participation/accumulation contract.

Implementations§

Source§

impl StatefulTokenBatchSampler

Source

pub fn new( sampler: StatefulShardSampler, lengths: Vec<usize>, options: TokenBatchOptions, ) -> Result<Self, SamplerError>

Wrap a committed distributed order with exact original-source lengths.

Source

pub fn from_state(state: TokenBatchState) -> Result<Self, SamplerError>

Restore committed samples; all prefetched-but-unconsumed rows are replayed.

Source

pub fn state(&self) -> TokenBatchState

Capture the committed continuation without saving an issued prefetch cursor.

Source

pub fn load_state(&mut self, state: TokenBatchState) -> Result<(), SamplerError>

Replace a matching continuation; reject silently changed lengths/limits.

Source

pub fn reshard( state: &ConsolidatedTokenBatchState, rank: usize, world_size: usize, ) -> Result<Self, SamplerError>

Assign unconsumed examples to a new data topology and repartition batches.

Source

pub fn sampler(&self) -> &StatefulShardSampler ⓘ

Underlying actual committed/issued order, without mutable aliasing.

Source

pub fn commit(&mut self, examples: usize) -> Result<(), SamplerError>

Commit actual consumed examples, never token slots or prefetched batches.

Source

pub fn rewind_uncommitted(&mut self)

Replay all outstanding prefetch when constructing a fresh loader iterator.

Source

pub fn start_epoch(&mut self, epoch: u64) -> Result<(), SamplerError>

Start the next explicitly selected epoch on the current data topology.

Source

pub fn peek(&self) -> Result<Option<TokenBatchPlan>, SamplerError>

Inspect the next exact batch without advancing either sample cursor.

Source

pub fn next_plan(&mut self) -> Result<Option<TokenBatchPlan>, SamplerError>

Issue the next batch of real indices; no lookahead sample is prematurely issued.

Source

pub fn load_next<I, D: Dataset<I>>( &mut self, dataset: &D, ) -> Result<Option<TokenBatch<I>>, SamplerError>

Available on crate feature dataset only.

Load every actual example before advancing the issued cursor.

Source

pub fn load_batch<B: Backend, I, O, D, F>( &mut self, dataset: &D, batcher: &F, device: &B::Device, ) -> Result<Option<(TokenBatchPlan, O)>, SamplerError>
where D: Dataset<I>, F: Batcher<B, I, O>,

Available on crate feature dataset only.

Batch the loaded actual records on the explicit backend device.

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<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

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> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

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.