Skip to main content

SplitSampler

Struct SplitSampler 

Source
pub struct SplitSampler { /* private fields */ }
Expand description

Like RandomSampler, but an epoch is a slice of a data pass.

splits says how finely to cut one pass. The pass permutation is unchanged and still covers every sample exactly once; splitting only decides how much of it one epoch consumes, so splits epochs make one pass and no sample is seen twice along the way.

This is what makes single-pass training (the normal regime for LLM pretraining) workable: everything that keys off the epoch boundary — eval, checkpointing, reporting — gets a boundary to key off, where a naive one-epoch run has none until teardown.

use flodl::SplitSampler;

// One pass over 10k samples, delivered as 20 epochs of 500.
let sampler = SplitSampler::new(10_000, 42, 20);

At splits = 1 it behaves exactly like RandomSampler.

Implementations§

Source§

impl SplitSampler

Source

pub fn new(n: usize, seed: u64, splits: usize) -> Self

Create a split sampler for n samples with the given base seed.

splits is clamped to at least 1.

Source

pub fn splits(&self) -> usize

Slices per data pass.

Trait Implementations§

Source§

impl Sampler for SplitSampler

Source§

fn len(&self) -> usize

Total number of samples. Must match the dataset length.
Source§

fn epoch_len(&self) -> usize

How many indices one epoch visits. Read more
Source§

fn indices(&mut self, epoch: usize) -> Vec<usize>

Generate the index ordering for a given epoch. Read more
Source§

fn is_empty(&self) -> bool

Whether the sampler is empty.

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, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

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

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

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.