vkML 0.1.0

DataLoader

Iterate a dataset in batches, optionally shuffled and augmented.

class DataLoaderpython/vkml/data.py:121

Single-process and synchronous: batches are assembled on the calling thread. Prefetching and worker processes are tracked as future work, not implemented.

transform= takes a callable f(rng, arrays) -> arrays, applied to each batch before it is moved to the device. Two things about that signature are deliberate:

ⓘ Note

Shuffling is seeded, so a run replays. The transform draws from a separate stream: sharing one with the shuffle would make the same seed give different augmentation depending on whether shuffling was on.

The final batch is smaller when the dataset size is not a multiple of the batch size — it is not dropped unless drop_last says so, so every sample is seen exactly once per epoch.

⚠ Warning

Augmentation is real host work: it takes CIFAR-100's batch-production time from 1.7% of a step to 10.6%, measured. That is also the number that decides whether prefetching is worth building — and prefetching turns out not to be a DataLoader change at all, because the bindings hold the GIL through the GPU wait and a producer thread would get only a fifth of the window it needs.

Construction

__init__

def __init__self, dataset: Dataset, batch_size: int, shuffle: bool=False, drop_last: bool=False, seed: int=0, device=None, transform=Nonepython/vkml/data.py:137

Iteration

__iter__

def __iter__self -> Iterator[tuple]python/vkml/data.py:170

__len__

def __len__self -> intpython/vkml/data.py:155

Number of batches one pass yields.

Other members

__repr__

def __repr__self -> strpython/vkml/data.py:217

set_epoch

def set_epochself, epoch: int -> Nonepython/vkml/data.py:162

Pin the shuffle to a specific epoch.

Iteration advances this on its own; setting it explicitly is what lets a run resume mid-training and see the order it would have seen.

See also ArrayDataset, Compose, rand

vkML — Vulkan-first machine learning in C++20. Apache-2.0. Signatures on this page are generated from the installed module.