data.from_loader
data.from_loader(loader, /, prepare=None, n_data=None)Wrap an iterable of raw items, one batch each.
Parameters
| Name | Type | Description | Default |
|---|---|---|---|
| loader | Iterable[Any] | A re-iterable of items, such as a list or a DataLoader. It is iterated once per pass. |
required |
| prepare | Callable[[Any, torch.Generator], Batch] | None | None: each item is a Batch or an (inputs, targets) pair, and the pass’s generator is unused. Otherwise each item becomes prepare(item, generator), with a fresh generator for that item on the device of the item’s first tensor (the CPU when it has none). It is lk.core.generator_for_batch(pass_gen, count), where pass_gen is lk.core.spawn_generator of the pass’s generator and count the examples before the item in this pass, so it draws the same numbers on every rerun. |
None |
| n_data | int | None | The number of examples the data stand for. lk.laplace scales the curvature and the data fit to it, so a fit on a subsample stands for all n_data examples. On several ranks, pass the global count, not this rank’s. None means the examples seen. |
None |
Returns
| Name | Type | Description |
|---|---|---|
| Data | The Data source. |
Raises
| Name | Type | Description |
|---|---|---|
| TypeError | loader is its own iterator (a generator, say), so it can’t be iterated again. During a pass: an item is neither a Batch nor a pair, or prepare returns something other than a Batch. |