Skip to content

Preserve multi-dataset sampler checkpoints when restoring - #1557

Open
YueshenZ wants to merge 1 commit into
meta-pytorch:mainfrom
YueshenZ:fix/sampler-checkpoint-ownership
Open

YueshenZ wants to merge 1 commit into
meta-pytorch:mainfrom
YueshenZ:fix/sampler-checkpoint-ownership

Conversation

@YueshenZ

Copy link
Copy Markdown

Changes

Source inspection found that restoring MultiNodeWeightedSampler or MultiNodeRoundRobinSampler aliases the checkpoint's exhaustion flags. Exhausting the resumed iterator then changes the caller's saved state. Loading that same in-memory checkpoint again can skip the remaining samples (restart_on_stop_iteration=False) or restart from the beginning (the default), instead of returning the saved tail.

Copy the boolean exhaustion containers on reset in both samplers. Add public Loader.state_dict() / load_state_dict() regressions for repeated restoration across the three finite stopping criteria and both restart settings. The checkpoint format and sampling order are unchanged.

Validation

  • All 12 new regression cases fail on unmodified main ee79a399d3a53676544e0d3f0e826ffa58d1fec9.
  • PYTEST_DISABLE_PLUGIN_AUTOLOAD=1 python3 -m pytest -q test/nodes/test_multi_node_weighted_sampler.py test/nodes/test_multi_node_round_robin_sampler.py: 187 passed with the fix.
  • Repository pre-commit hooks on the four changed Python files and git diff --check: passed.
  • Pinned mypy 1.8.0 reported no issues in the two changed implementation files, with a warning about the upstream quoted python_version setting. The full repository type check and upstream CI are not validated.
  • A separate public-API CPU probe covers fresh-loader and same-loader retries, multiple loaders sharing one checkpoint, and exhausted-checkpoint controls. The patched samplers preserve the input checkpoint and replay the expected samples.

Environment: macOS arm64, Python 3.13.15, PyTorch 2.14.0, NumPy 2.5.3. This is a deterministic data-pipeline reproduction; no production training incident or GPU validation is claimed. Re-reading a serialized checkpoint into a fresh Python object for every restore does not hit the shared-object case.

AI assistance was used for investigation, implementation, and validation.

@meta-cla

meta-cla Bot commented Oct 16, 2026

Copy link
Copy Markdown

Hi @YueshenZ!

Thank you for your pull request and welcome to our community.

Action Required

In order to merge any pull request (code, docs, etc.), we require contributors to sign our Contributor License Agreement, and we don't seem to have one on file for you.

Process

In order for us to review and merge your suggested changes, please sign at https://code.facebook.com/cla. If you are contributing on behalf of someone else (eg your employer), the individual CLA may not be sufficient and your employer may need to sign the corporate CLA.

Once the CLA is signed, our tooling will perform checks and validations. Afterwards, the pull request will be tagged with CLA signed. The tagging process may take up to 1 hour after signing. Please give it that time before contacting us about it.

If you have received this in error or have any questions, please contact us at cla@meta.com. Thanks!

@meta-cla

meta-cla Bot commented Oct 16, 2026

Copy link
Copy Markdown

Thank you for signing our Contributor License Agreement. We can now accept your code for this (and any) Meta Open Source project. Thanks!

@meta-cla meta-cla Bot added the CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. label Oct 16, 2026

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant