diff --git a/docs/web/curation/dedupe.mdx b/docs/web/curation/dedupe.mdx index 2e90bc231..ff2f3b3a3 100644 --- a/docs/web/curation/dedupe.mdx +++ b/docs/web/curation/dedupe.mdx @@ -66,7 +66,7 @@ both **squared** L2, not the plain L2 a plain SQL `distance()` call returns. `dedupe` returns one representative row per cluster of records within `distance_threshold` of each other -- rows 10/20 collapse to one, 30/40/50 -collapse to one, and the four distinct rows pass through unchanged, leaving +collapse to one, and the three distinct rows pass through unchanged, leaving ids 10, 30, 60, 70 and 80: diff --git a/docs/web/training/checkpointing.mdx b/docs/web/training/checkpointing.mdx index 99124549a..627aa55a1 100644 --- a/docs/web/training/checkpointing.mdx +++ b/docs/web/training/checkpointing.mdx @@ -15,6 +15,8 @@ terminology from [Distributed Training](/training/distributed-training#paralleli A stored `StreamingDataset` state reflects only round-robin cycles that have been completed across all splits; samples completed partway through a cycle at the time of saving can be replayed. To ensure efficient saving, make sure `global_batch_size` is a multiple of `num_splits`, as in the example below. +Each rank saves its own dataset state to a separate file. Keep the files from every rank at the same checkpoint step to resume across different topologies. + ```py Python icon=Python import torch @@ -43,7 +45,7 @@ for step, batch in enumerate(dataloader): if (step + 1) % checkpoint_interval == 0: torch.save( {"model": model.state_dict(), "dataset": dataset.state_dict()}, - f"checkpoint_{step + 1}.pt", + f"checkpoint_{step + 1}_rank_{rank}.pt", ) ``` @@ -80,7 +82,7 @@ for step, batch in enumerate(dataloader): if (step + 1) % checkpoint_interval == 0: torch.save( {"model": model.state_dict(), "dataset": dataset.state_dict()}, - f"checkpoint_{step + 1}.pt", + f"checkpoint_{step + 1}_rank_{rank}.pt", ) ``` diff --git a/docs/web/training/data-loading.mdx b/docs/web/training/data-loading.mdx index 1db37189c..19b9066a9 100644 --- a/docs/web/training/data-loading.mdx +++ b/docs/web/training/data-loading.mdx @@ -12,6 +12,7 @@ Advanced data loading scenarios can be handled by the `StreamingDataset`. This o ```py Python icon=Python +import lancedb import torch from lancedb.streaming import StreamingDataset diff --git a/docs/web/training/distributed-training.mdx b/docs/web/training/distributed-training.mdx index 12fecda43..bb4312cc6 100644 --- a/docs/web/training/distributed-training.mdx +++ b/docs/web/training/distributed-training.mdx @@ -47,6 +47,11 @@ The following constraints apply: - The filtered row count must be at least `num_splits`. If it is not evenly divisible by `num_splits`, up to `num_splits - 1` surplus rows are dropped so that every split has the same length. +These constraints do not guarantee identical per-rank batches when `num_workers` changes. Workers read +different subgroups of a rank's splits, so changing worker count can change batch composition even if +the remaining rows are the same. For exact batch replay on the same topology, see +[Resuming](/training/resuming#same-topology). + For example, to switch between $8$ and $6$ GPUs, use a common multiple such as $24$ for `num_splits`. Highly composite values can support many layouts; for example, `num_splits = 48` is compatible with $10$ distinct possible GPU counts. Remember to include `num_workers` when checking divisibility. diff --git a/docs/web/training/resuming.mdx b/docs/web/training/resuming.mdx index a80a80a12..4592de346 100644 --- a/docs/web/training/resuming.mdx +++ b/docs/web/training/resuming.mdx @@ -8,7 +8,7 @@ availability: enterprise: available --- -Resuming loads a `StreamingDataset` checkpoint saved by [Checkpointing](/training/checkpointing) back into a fresh dataset and `DataLoader`, so a failed or restarted run picks up where it left off rather than rereading from the start. +Resuming loads a `StreamingDataset` checkpoint saved by [Checkpointing](/training/checkpointing) back into a fresh dataset and loader, so a failed or restarted run picks up where it left off rather than rereading from the start. This page assumes the `rank`, `world_size`, `num_splits` and `shuffle_seed` terminology from [Distributed Training](/training/distributed-training#parallelism-and-elasticity). @@ -18,9 +18,9 @@ terminology from [Distributed Training](/training/distributed-training#paralleli ```py Python icon=Python import torch -from lancedb.streaming import StreamingDataset +from lancedb.streaming import StreamingDataLoader, StreamingDataset -checkpoint = torch.load("checkpoint_100.pt") +checkpoint = torch.load(f"checkpoint_100_rank_{rank}.pt") model.load_state_dict(checkpoint["model"]) dataset_state = checkpoint["dataset"] @@ -34,25 +34,49 @@ dataset = StreamingDataset( ) dataset.load_state_dict(dataset_state) -# The combined batch size across every rank, the same value used when the -# checkpoint was saved; each rank's DataLoader gets its world_size share of it. +# Use the same global batch size as the run that saved the checkpoint. global_batch_size = 48 +batch_size = global_batch_size // world_size +``` + + +Choose the loader that matches the one used to save the checkpoint: + + +```py "Single-process loader" icon=Python dataloader = torch.utils.data.DataLoader( dataset, - batch_size=global_batch_size // world_size, + batch_size=batch_size, num_workers=0, ) +``` +```py "Multi-worker loader" icon=Python +dataloader = StreamingDataLoader( + dataset, + batch_size=batch_size, + num_workers=4, +) +``` + + +Continue training with the selected loader: + + +```py Python icon=Python for batch in dataloader: train_step(batch) ``` -`load_state_dict()` rejects a checkpoint whose `num_splits` or `shuffle_seed` differs from the new dataset. For an -exact resume, also use the same table snapshot, `epoch`, `shuffle`, `filter`, and other data-selection settings, and -keep `world_size` the same -- changing it is a topology change, covered next. The number of DataLoader workers may -still change as long as the batch-size divisibility constraints from -[Distributed Training](/training/distributed-training#parallelism-and-elasticity) hold. +`load_state_dict()` rejects a checkpoint whose `num_splits` or `shuffle_seed` differs from the new dataset. +To reproduce the same ordered batches on each rank, use the same table snapshot, `epoch`, `shuffle`, +`filter`, and other data-selection settings. Keep `world_size`, the loader type, `num_workers`, the batch +size, and collation the same as in the run that saved the checkpoint. + +Changing `num_workers` changes how splits are grouped. A resumed run can recover the same remaining rows +but group or order them differently, even when the +[divisibility constraints](/training/distributed-training#parallelism-and-elasticity) hold. ## Resuming Across Different Topologies {#resuming-across-different-topologies}