mirror of
https://github.com/lancedb/lancedb.git
synced 2026-11-13 14:16:54 +00:00
A broad documentation pass across the areas LanceDB Enterprise and Embedded diverge on most: **Data Curation** -- GPU Function execution, Slurm scheduling (and what Slurm is, for readers new to it), blob late materialization as its own page, joins, aggregation/profiling, sampling, near-duplicate detection, chunking, distributed shuffle, and IVF-partition clustering. **Feature Engineering** -- computed columns and materialized views, restructured to lead with the Function-based path and show the SQL form side by side with Python throughout; a single Auto Refresh page instead of duplicating scheduling details on every refresh page; adaptive execution; checkpointing; GPU and Slurm placement for refresh workers; a Training Cache page for the PyTorch data loader's automatic cache benefit. **Security & Governance** -- an Audit Log reference (schema, access, grants), Secrets promoted to an ordinary catalog object with their own SQL DDL and a vending/rotation guide, and privilege-table fixes verified against the authorization source. **Deployment & Maintenance** -- Horizontal Scaling and OpenTelemetry moved into a real Deployment area; Automated Cleanup folded into Intelligent Auto-Maintenance (every other maintenance decision already lived there); RTE Compaction and Advanced Conflict Resolution documented in depth. **Landing page** -- the Enterprise feature comparison table reorganized (several redundant or stale rows removed, several new areas added), and the "why Enterprise" bullets replaced with ones tied to a concrete page (Performance, Scale, Fault tolerance, Multicloud deployment, Simplify operations) instead of vague promises. Plus a full pass addressing lancedb-gatekeeper's review: a real test-safety bug (a quickstart test could silently overwrite and delete a deployment's own `frames` table), a fabricated SQL statement with no backing implementation, an actual dedup-guarantee bug in `take_row_ids`, and dozens of documentation-accuracy fixes verified against source rather than taken on faith -- each either fixed, or left with an explicit note on why it needs a feature or deployment owner's sign-off instead of being guessed at. 🤖 Generated with [Claude Code](https://claude.com/claude-code) https://claude.ai/code/session_018PXMCbRH6i5w47TsjeEUMT --------- Co-authored-by: Claude Sonnet 5 <noreply@anthropic.com>
107 lines
4.2 KiB
Plaintext
107 lines
4.2 KiB
Plaintext
---
|
|
title: "Checkpointing"
|
|
sidebarTitle: "Checkpointing"
|
|
description: "Save StreamingDataset's read position alongside your model, so a failed run can pick back up."
|
|
icon: floppy-disk
|
|
availability:
|
|
embedded: available
|
|
enterprise: available
|
|
---
|
|
|
|
[`StreamingDataset`](/training/data-loading) provides checkpointing in case your model training fails partway through a run. Use `StreamingDataset.state_dict()` to capture the current number of samples consumed from each split in a Python dictionary, save it alongside your model weights, and `load_state_dict()` to restore the last saved position -- see [Resuming](/training/resuming) for the load side.
|
|
|
|
This page assumes the `rank`, `world_size`, `num_splits` and `shuffle_seed`
|
|
terminology from [Distributed Training](/training/distributed-training#parallelism-and-elasticity).
|
|
|
|
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.
|
|
|
|
<CodeGroup>
|
|
```py Python icon=Python
|
|
import torch
|
|
from lancedb.streaming import StreamingDataset
|
|
|
|
global_batch_size = 48 # one sample per split in each global step
|
|
batch_size = global_batch_size // world_size
|
|
|
|
dataset = StreamingDataset(
|
|
table,
|
|
num_splits=48,
|
|
shuffle_seed=42,
|
|
epoch=current_epoch,
|
|
rank=rank,
|
|
world_size=world_size,
|
|
)
|
|
dataloader = torch.utils.data.DataLoader(
|
|
dataset,
|
|
batch_size=batch_size,
|
|
num_workers=0,
|
|
)
|
|
|
|
for step, batch in enumerate(dataloader):
|
|
train_step(batch)
|
|
|
|
if (step + 1) % checkpoint_interval == 0:
|
|
torch.save(
|
|
{"model": model.state_dict(), "dataset": dataset.state_dict()},
|
|
f"checkpoint_{step + 1}.pt",
|
|
)
|
|
```
|
|
</CodeGroup>
|
|
|
|
## Checkpointing with Multiple DataLoader Workers {#checkpointing-with-multiple-dataloader-workers}
|
|
|
|
Python's built-in `torch.utils.data.DataLoader` produces a safe checkpoint when `num_workers = 0`. With `num_workers > 0`, calling `state_dict()` often raises `RuntimeError`. In this case, use `StreamingDataLoader` for multi-worker prefetch and exact resumability. It carries a state snapshot
|
|
alongside every internal batch and commits it to the parent `StreamingDataset` only when that batch is returned to the
|
|
trainer. The trainer receives the same collated batch it would receive from a standard `DataLoader`.
|
|
|
|
<CodeGroup>
|
|
```py Python icon=Python
|
|
from lancedb.streaming import StreamingDataset, StreamingDataLoader
|
|
|
|
dataset = StreamingDataset(
|
|
table,
|
|
num_splits=48,
|
|
shuffle_seed=42,
|
|
epoch=current_epoch,
|
|
rank=rank,
|
|
world_size=world_size,
|
|
)
|
|
dataloader = StreamingDataLoader(
|
|
dataset,
|
|
batch_size=batch_size,
|
|
num_workers=4,
|
|
)
|
|
|
|
for step, batch in enumerate(dataloader):
|
|
train_step(batch)
|
|
|
|
if (step + 1) % checkpoint_interval == 0:
|
|
torch.save(
|
|
{"model": model.state_dict(), "dataset": dataset.state_dict()},
|
|
f"checkpoint_{step + 1}.pt",
|
|
)
|
|
```
|
|
</CodeGroup>
|
|
|
|
`StreamingDataLoader` accepts the same arguments as `torch.utils.data.DataLoader`, with a few restrictions:
|
|
|
|
- `dataset` must be a `StreamingDataset` (subclasses that override `__iter__` are not supported).
|
|
- `in_order = True` is required so that consumer-committed checkpoints stay deterministic.
|
|
- `persistent_workers = True` is not supported, because prefetched worker copies cannot be restored from parent-committed state.
|
|
- `drop_last = True` is not supported, because incomplete tails discarded by worker replicas cannot be checkpointed topology-independently.
|
|
|
|
With more than one worker, call `state_dict()` at a complete logical step boundary where every split assigned to the
|
|
rank has the same consumed-sample count. Calling it mid-step raises `RuntimeError` asking you to consume more batches
|
|
first.
|
|
|
|
## Next steps {#next}
|
|
|
|
<CardGroup cols={2}>
|
|
<Card title="Resuming" icon="rotate-left" href="/training/resuming">
|
|
Load a saved checkpoint back, on the same or a different topology.
|
|
</Card>
|
|
<Card title="Distributed Training" icon="server" href="/training/distributed-training">
|
|
The rank, world size and split terminology checkpointing builds on.
|
|
</Card>
|
|
</CardGroup>
|