Repository navigation
Description
SDK
Python
Problem
StreamingDataset.state_dict() currently records shuffle seed, split count, epoch, and per-split progress. load_state_dict() validates only num_splits and shuffle_seed before applying the cursor:
lancedb/python/python/lancedb/streaming.py
Lines 763 to 825 in f39a7a4
| def state_dict(self) -> dict: | |
| """Snapshot the dataset's consumption state. | |
| The returned dict is topology-independent: at global step boundaries | |
| every split has been consumed the same number of times (by the | |
| round-robin design), so the per-split count is a single uniform value | |
| that is identical across all ranks and DataLoader workers. | |
| ``positions_consumed_per_split`` records how far into each split's | |
| permutation iteration has advanced. It only differs from | |
| ``samples_consumed_per_split`` when ``on_transform_error`` skipped | |
| rows, in which case entries are exact for the splits this instance | |
| iterated and a lower bound (the sample count) for splits owned by | |
| other ranks or workers. Combine the state dicts from all ranks with | |
| [merge_state_dicts][lancedb.streaming.StreamingDataset.merge_state_dicts] | |
| to recover the exact value for every split before resuming on a | |
| different topology. | |
| """ | |
| positions = [ | |
| self._resume_positions.get(split, self._resume_offset) | |
| for split in range(self._num_splits) | |
| ] | |
| return { | |
| "shuffle_seed": self._shuffle_seed, | |
| "num_splits": self._num_splits, | |
| "epoch": self._epoch, | |
| "samples_consumed_per_split": [self._resume_offset] * self._num_splits, | |
| "positions_consumed_per_split": positions, | |
| } | |
| def load_state_dict(self, state: dict) -> None: | |
| """Resume from a previously snapshotted state. | |
| Raises ``ValueError`` if ``num_splits`` or ``shuffle_seed`` differ | |
| from the checkpoint, since a different split structure or shuffle order | |
| makes mid-epoch resumption meaningless. | |
| """ | |
| if state["num_splits"] != self._num_splits: | |
| raise ValueError( | |
| f"num_splits mismatch: checkpoint has {state['num_splits']}, " | |
| f"current dataset has {self._num_splits}" | |
| ) | |
| if state["shuffle_seed"] != self._shuffle_seed: | |
| raise ValueError( | |
| f"shuffle_seed mismatch: checkpoint has {state['shuffle_seed']}, " | |
| f"current dataset has {self._shuffle_seed}" | |
| ) | |
| consumed = state["samples_consumed_per_split"] | |
| # All entries are equal at step boundaries; use the first. | |
| if isinstance(consumed, list): | |
| self._resume_offset = consumed[0] if consumed else 0 | |
| else: | |
| self._resume_offset = int(consumed) | |
| # Older checkpoints predate positions_consumed_per_split; without | |
| # skipped rows positions equal sample counts, so falling back to | |
| # _resume_offset (the .get default in __iter__) is exact. | |
| positions = state.get("positions_consumed_per_split") | |
| if positions is None: | |
| self._resume_positions = {} | |
| else: | |
| self._resume_positions = { | |
| split: int(pos) for split, pos in enumerate(positions) | |
| } |
It does not bind the cursor to the base-table identity/version, filter, projected columns/schema, shuffle mode/clump size, transform identity, or relevant batch/topology configuration. A checkpoint can therefore be applied to a different dataset configuration without a clear incompatibility error.
Multi-process parent visibility is tracked separately in #3967 (and the older overlapping #3751). This issue is about validating what a cursor means once it is visible.
Desired behavior
Make a checkpoint self-describing enough to reject incompatible resume attempts instead of silently applying a valid cursor to a different training sequence.
Acceptance criteria
- Record base-table identity and pinned version or immutable reference.
- Record filter, selected columns, output-schema fingerprint, shuffle mode, seed, epoch, clump size, and permutation/occurrence-plan identity.
- Record split count and any topology or accumulation fields that affect emitted batch boundaries.
load_state_dict()compares compatibility fields and raises a descriptive error on a mismatch.- Resuming an unchanged configuration yields the exact remaining sample-ID sequence.
- Define checkpoint schema versioning and backward-compatibility behavior.
- Add tests for table-version, filter, projection/schema, epoch, shuffle/clump, plan, worker, and topology mismatches.
Scope boundary
The loader need not invent application policy. It may accept caller-provided policy fingerprints for duration boundaries, tail policy, transforms, or accumulation settings that LanceDB cannot derive itself.
Activity
akshitkhokhani commentedon Oct 23, 2026
I'd like to work on the checkpoint provenance contract here, coordinating with #4144's persisted plans and preserving #4597's existing split-strategy checks.
I reproduced the gap on
a9535684cc1d9901c54c852f103dd0d492d61c3fwith a current-source native build and authored local tables. After consuming IDs 0–1, unchanged restore returns exactly 2–7. Applying that checkpoint to a different same-shaped table is accepted and returns 102–107; changing the filter toid >= 4returns 6–7, and changing the projection is also accepted. These are single-process CPU checks, not distributed-training validation.The lower permutation reader already pins its recorded branch/version. The gap above is applying saved progress to a newly constructed dataset and plan, rather than an existing saved plan drifting to latest.
One compatibility decision matters before settling the public contract: ordinary checkpoints currently allow compaction between save and restore. My local sequential and seeded-shuffle controls retained the exact remaining rows after compaction changed both table version and physical row IDs. A strict version check would reject that too; table name, row count or physical row IDs cannot establish logical equivalence. Would you prefer strict snapshot provenance with an explicit compatibility path, or an explicit caller-owned immutable data revision for compaction-compatible restores?
I plan to prototype a versioned descriptor, configuration/policy identity checks, validation before any restore mutation, and order-independent cross-rank descriptor checks. Legacy checkpoints must remain explicitly unverified rather than acquiring the target dataset's identity during restore. Elastic rank/worker changes should remain supported when they preserve the logical stream. I would keep global-batch planning out of this work.
Is anyone already implementing this contract, and is there a preferred migration/default policy I should align with?