pub struct StatefulTokenBatchSampler { /* private fields */ }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
impl StatefulTokenBatchSampler
Sourcepub fn new(
sampler: StatefulShardSampler,
lengths: Vec<usize>,
options: TokenBatchOptions,
) -> Result<Self, SamplerError>
pub fn new( sampler: StatefulShardSampler, lengths: Vec<usize>, options: TokenBatchOptions, ) -> Result<Self, SamplerError>
Wrap a committed distributed order with exact original-source lengths.
Sourcepub fn from_state(state: TokenBatchState) -> Result<Self, SamplerError>
pub fn from_state(state: TokenBatchState) -> Result<Self, SamplerError>
Restore committed samples; all prefetched-but-unconsumed rows are replayed.
Sourcepub fn state(&self) -> TokenBatchState
pub fn state(&self) -> TokenBatchState
Capture the committed continuation without saving an issued prefetch cursor.
Sourcepub fn load_state(&mut self, state: TokenBatchState) -> Result<(), SamplerError>
pub fn load_state(&mut self, state: TokenBatchState) -> Result<(), SamplerError>
Replace a matching continuation; reject silently changed lengths/limits.
Sourcepub fn reshard(
state: &ConsolidatedTokenBatchState,
rank: usize,
world_size: usize,
) -> Result<Self, SamplerError>
pub fn reshard( state: &ConsolidatedTokenBatchState, rank: usize, world_size: usize, ) -> Result<Self, SamplerError>
Assign unconsumed examples to a new data topology and repartition batches.
Sourcepub fn sampler(&self) -> &StatefulShardSampler ⓘ
pub fn sampler(&self) -> &StatefulShardSampler ⓘ
Underlying actual committed/issued order, without mutable aliasing.
Sourcepub fn commit(&mut self, examples: usize) -> Result<(), SamplerError>
pub fn commit(&mut self, examples: usize) -> Result<(), SamplerError>
Commit actual consumed examples, never token slots or prefetched batches.
Sourcepub fn rewind_uncommitted(&mut self)
pub fn rewind_uncommitted(&mut self)
Replay all outstanding prefetch when constructing a fresh loader iterator.
Sourcepub fn start_epoch(&mut self, epoch: u64) -> Result<(), SamplerError>
pub fn start_epoch(&mut self, epoch: u64) -> Result<(), SamplerError>
Start the next explicitly selected epoch on the current data topology.
Sourcepub fn peek(&self) -> Result<Option<TokenBatchPlan>, SamplerError>
pub fn peek(&self) -> Result<Option<TokenBatchPlan>, SamplerError>
Inspect the next exact batch without advancing either sample cursor.
Sourcepub fn next_plan(&mut self) -> Result<Option<TokenBatchPlan>, SamplerError>
pub fn next_plan(&mut self) -> Result<Option<TokenBatchPlan>, SamplerError>
Issue the next batch of real indices; no lookahead sample is prematurely issued.
Sourcepub fn load_next<I, D: Dataset<I>>(
&mut self,
dataset: &D,
) -> Result<Option<TokenBatch<I>>, SamplerError>
Available on crate feature dataset only.
pub fn load_next<I, D: Dataset<I>>( &mut self, dataset: &D, ) -> Result<Option<TokenBatch<I>>, SamplerError>
dataset only.Load every actual example before advancing the issued cursor.
Sourcepub fn load_batch<B: Backend, I, O, D, F>(
&mut self,
dataset: &D,
batcher: &F,
device: &B::Device,
) -> Result<Option<(TokenBatchPlan, O)>, SamplerError>
Available on crate feature dataset only.
pub fn load_batch<B: Backend, I, O, D, F>( &mut self, dataset: &D, batcher: &F, device: &B::Device, ) -> Result<Option<(TokenBatchPlan, O)>, SamplerError>
dataset only.Batch the loaded actual records on the explicit backend device.