Skip to content

fix(iterable): ensure MappedExamplesIterable supports state_dict for resume #7656

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

ArjunJagdale
Copy link
Contributor

Fixes #7630

Problem

When calling .map() on an IterableDataset, resuming from a checkpoint skips a large number of samples. This is because MappedExamplesIterable did not implement state_dict() or load_state_dict(), so checkpointing was not properly delegated to the underlying iterable.

What This PR Does

This patch adds:

def state_dict(self):
    return self.ex_iterable.state_dict()

def load_state_dict(self, state):
    self.ex_iterable.load_state_dict(state)

to MappedExamplesIterable, so the wrapped base iterable's state can be saved and restored as expected.

Result
Using .map() no longer causes sample skipping after checkpoint resume.

Let me know if a dedicated test case is required — happy to add one!

…resume

Fixes huggingface#7630

### Problem
When calling `.map()` on an `IterableDataset`, resuming from a checkpoint skips a large number of samples. This is because `MappedExamplesIterable` did not implement `state_dict()` or `load_state_dict()`, so checkpointing was not properly delegated to the underlying iterable.

### What This PR Does
This patch adds:
```python
def state_dict(self):
    return self.ex_iterable.state_dict()

def load_state_dict(self, state):
    self.ex_iterable.load_state_dict(state)
to MappedExamplesIterable, so the wrapped base iterable's state can be saved and restored as expected.

Result
Using .map() no longer causes sample skipping after checkpoint resume.

Tested manually using the reproducer script in huggingface#7630. The resumed iterator now yields the correct samples.

Let me know if a dedicated test case is required — happy to add one!
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[bug] resume from ckpt skips samples if .map is applied
1 participant