mirror of
https://github.com/lancedb/lancedb.git
synced 2026-12-03 07:45:17 +00:00
## Summary - Save per-rank dataset checkpoints to separate files and load the matching file when resuming. - Add the missing LanceDB import to the data loader example. - Correct the count of distinct rows in the deduplication example. ## Validation - `git diff --check` - Parsed the Python snippets in the affected training pages with `ast.parse`. --------- Co-authored-by: Haocheng Liu <haocheng.liu@general-int.com>
121 lines
4.1 KiB
Plaintext
121 lines
4.1 KiB
Plaintext
---
|
|
title: "Resuming"
|
|
sidebarTitle: "Resuming"
|
|
description: "Load a saved StreamingDataset checkpoint back, on the same topology or a different one."
|
|
icon: rotate-left
|
|
availability:
|
|
embedded: available
|
|
enterprise: available
|
|
---
|
|
|
|
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).
|
|
|
|
## Resuming on the same topology {#same-topology}
|
|
|
|
<CodeGroup>
|
|
```py Python icon=Python
|
|
import torch
|
|
from lancedb.streaming import StreamingDataLoader, StreamingDataset
|
|
|
|
checkpoint = torch.load(f"checkpoint_100_rank_{rank}.pt")
|
|
model.load_state_dict(checkpoint["model"])
|
|
|
|
dataset_state = checkpoint["dataset"]
|
|
dataset = StreamingDataset(
|
|
table,
|
|
num_splits=dataset_state["num_splits"],
|
|
shuffle_seed=dataset_state["shuffle_seed"],
|
|
epoch=dataset_state["epoch"],
|
|
rank=rank,
|
|
world_size=world_size, # same as the run that saved the checkpoint
|
|
)
|
|
dataset.load_state_dict(dataset_state)
|
|
|
|
# Use the same global batch size as the run that saved the checkpoint.
|
|
global_batch_size = 48
|
|
batch_size = global_batch_size // world_size
|
|
```
|
|
</CodeGroup>
|
|
|
|
Choose the loader that matches the one used to save the checkpoint:
|
|
|
|
<CodeGroup>
|
|
```py "Single-process loader" icon=Python
|
|
dataloader = torch.utils.data.DataLoader(
|
|
dataset,
|
|
batch_size=batch_size,
|
|
num_workers=0,
|
|
)
|
|
```
|
|
|
|
```py "Multi-worker loader" icon=Python
|
|
dataloader = StreamingDataLoader(
|
|
dataset,
|
|
batch_size=batch_size,
|
|
num_workers=4,
|
|
)
|
|
```
|
|
</CodeGroup>
|
|
|
|
Continue training with the selected loader:
|
|
|
|
<CodeGroup>
|
|
```py Python icon=Python
|
|
for batch in dataloader:
|
|
train_step(batch)
|
|
```
|
|
</CodeGroup>
|
|
|
|
`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}
|
|
|
|
When training across ranks, each rank owns its own subset of splits and only its own splits have exact progress. To
|
|
resume on a different `world_size`, collect the `state_dict()` from every rank of the previous run and merge them with
|
|
`StreamingDataset.merge_state_dicts` before calling `load_state_dict()` on the new run. The merge is topology-agnostic:
|
|
pass the full list of per-rank states in, and hand the identical merged dict to every rank of the resumed job,
|
|
regardless of whether the topology grew, shrank, or stayed the same.
|
|
|
|
<CodeGroup>
|
|
```py Python icon=Python
|
|
# On each rank of the previous run:
|
|
state = dataset.state_dict()
|
|
# ...gather `state` from every rank into a single list `states` (for example
|
|
# via torch.distributed all-gather or by saving one file per rank).
|
|
|
|
merged = StreamingDataset.merge_state_dicts(states)
|
|
|
|
# On each rank of the resumed run (world_size may differ):
|
|
dataset = StreamingDataset(
|
|
table,
|
|
num_splits=merged["num_splits"],
|
|
shuffle_seed=merged["shuffle_seed"],
|
|
epoch=merged["epoch"],
|
|
rank=rank,
|
|
world_size=new_world_size,
|
|
)
|
|
dataset.load_state_dict(merged)
|
|
```
|
|
</CodeGroup>
|
|
|
|
## Next steps {#next}
|
|
|
|
<CardGroup cols={2}>
|
|
<Card title="Checkpointing" icon="floppy-disk" href="/training/checkpointing">
|
|
Save progress, including with multiple DataLoader workers.
|
|
</Card>
|
|
<Card title="Distributed Training" icon="server" href="/training/distributed-training">
|
|
The rank, world size and split terminology resuming builds on.
|
|
</Card>
|
|
</CardGroup>
|