pub struct ShardedLoader {
pub total_samples: usize,
pub n_shards: usize,
pub seed: u64,
}Expand description
A loader that partitions a dataset into consistently shuffled shards for multi-process or multi-node distributed training.
Given the same seed, total_samples, and n_shards, every call to
ShardedLoader::get_shard with the same arguments will return the same
DatasetShard, making the assignment deterministic and reproducible across
independent processes.
§Example
use scirs2_datasets::ShardedLoader;
let loader = ShardedLoader::new(100, 4, 42);
assert!(loader.verify_coverage());
let shard0 = loader.get_shard(0);
let shard1 = loader.get_shard(1);
// No overlap between shards.
for &i in &shard0.indices {
assert!(!shard1.indices.contains(&i));
}Fields§
§total_samples: usizeTotal number of samples in the dataset.
n_shards: usizeNumber of shards to partition into.
seed: u64Seed used for the deterministic shuffle.
Implementations§
Source§impl ShardedLoader
impl ShardedLoader
Sourcepub fn new(total_samples: usize, n_shards: usize, seed: u64) -> Self
pub fn new(total_samples: usize, n_shards: usize, seed: u64) -> Self
Create a new ShardedLoader.
total_samples— number of samples in the full dataset.n_shards— number of shards to divide the dataset into.seed— seed for the deterministic Fisher-Yates shuffle.
Sourcepub fn global_permutation(&self) -> Vec<usize>
pub fn global_permutation(&self) -> Vec<usize>
Compute the global shuffled permutation of all sample indices.
Calling this function with the same seed always returns the same
permutation, regardless of which process calls it.
Sourcepub fn get_shard(&self, shard_id: usize) -> DatasetShard
pub fn get_shard(&self, shard_id: usize) -> DatasetShard
Return shard shard_id (0-indexed) from the consistently shuffled
partition of the dataset.
If shard_id >= self.n_shards an empty shard is returned.
Sourcepub fn verify_coverage(&self) -> bool
pub fn verify_coverage(&self) -> bool
Verify that the union of all shard index sets covers every sample index exactly once (no gaps, no duplicates).
Returns true when coverage is complete and disjoint.
Trait Implementations§
Source§impl Clone for ShardedLoader
impl Clone for ShardedLoader
Source§fn clone(&self) -> ShardedLoader
fn clone(&self) -> ShardedLoader
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreAuto Trait Implementations§
impl Freeze for ShardedLoader
impl RefUnwindSafe for ShardedLoader
impl Send for ShardedLoader
impl Sync for ShardedLoader
impl Unpin for ShardedLoader
impl UnsafeUnpin for ShardedLoader
impl UnwindSafe for ShardedLoader
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> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
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 moreSource§impl<T> Pointable for T
impl<T> Pointable for T
Source§impl<T> PolicyExt for Twhere
T: ?Sized,
impl<T> PolicyExt for Twhere
T: ?Sized,
Source§impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
Source§fn to_subset(&self) -> Option<SS>
fn to_subset(&self) -> Option<SS>
self from the equivalent element of its
superset. Read moreSource§fn is_in_subset(&self) -> bool
fn is_in_subset(&self) -> bool
self is actually part of its subset T (and can be converted to it).Source§fn to_subset_unchecked(&self) -> SS
fn to_subset_unchecked(&self) -> SS
self.to_subset but without any property checks. Always succeeds.Source§fn from_subset(element: &SS) -> SP
fn from_subset(element: &SS) -> SP
self to the equivalent element of its superset.