Fix Loader restoration before None items - #1552
Conversation
|
Hi @divyanshk, when you have time, could you please review this checkpoint restoration fix? It separates look-ahead occupancy from the cached value so |
sylvesterkaczmarek
left a comment
There was a problem hiding this comment.
One adjacent cache survives reset: _cached_state_dict isn't cleared. If has_next() populated it, then load_state_dict() + iter(loader) resets the root and clears _cached_item/_has_cached_item, but a subsequent state_dict() still returns the pre-reset cached state. Should reset() clear _cached_state_dict as well?
|
@sylvesterkaczmarek Good catch. |
sylvesterkaczmarek
left a comment
There was a problem hiding this comment.
The reset path now clears _cached_state_dict together with the cached item/occupancy flag, and the new regression covers has_next() followed by restore/reset and a subsequent state_dict(). This resolves the stale-checkpoint issue I raised.
|
Thanks for the careful follow-up and for catching the stale checkpoint case. |
|
Thanks, glad it helped. The reset and restore boundary was easy to miss, and the added regression should keep it from coming back. |
Fixes #1551.
Summary
LoaderIteratorusedNoneboth as a valid data value and as the empty look-ahead marker. When a checkpoint resumed immediately before aNoneitem,Loader.__iter__()calledhas_next(), misclassified the item as end-of-input, and reset the pipeline to the beginning. This duplicated all data consumed before the checkpoint.This change tracks cache occupancy separately from the cached value.
Nonecan therefore be cached and returned like any other item, while the existing look-ahead and restart behavior remains unchanged for exhausted iterators.Reset now also clears the cached prefetch state dictionary together with the cached item. This prevents
state_dict()from reporting a position captured before a laterload_state_dict()and iterator reset.The regressions verify that restoring
[0, None, 2]after consuming0yields exactly[None, 2], and that a state request afterhas_next(),load_state_dict(), anditer(loader)reports the restored position.Validation
PYTEST_DISABLE_PLUGIN_AUTOLOAD=1 py -3.13 -m pytest -q test/nodes/test_loader.py(5 passed)py -3.13 -m pre_commit run --files torchdata/nodes/loader.py test/nodes/test_loader.py(passed)git diff --check(passed)python_versionsetting and this source checkout lacks the generatedtorchdata.versionmodule.AI assistance disclosure: AI-assisted development tools were used during investigation and implementation. The reported tests were run against the final diff.