mosaicml / mosaicml/streaming

Unable to get mid-epoch resumption working

Open
#880 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

bug
Dominant language
Python
Stars
1.6k
Forks
206
PR merge metrics
No merged PRs in 30d

Description

I am using the Streaming in conjunction with pytorch lightning, but loading my dataloaders (including state resumption) separate of the pl logic.

Within my pl.Trainer I have the following to include the training dataloader state dict in the checkpoint:

  def on_save_checkpoint(self, checkpoint):
      dataloader = self.trainer.train_dataloader
      if isinstance(dataloader, list):
          dataloader = dataloader[0]
      checkpoint['dataloader_state'] = dataloader.state_dict()

And then in my dataset class, I implement the logic to load this checkpoint, and specifically get the dataloader state (if resuming). As an example, this is the dict I extract:

self.dataloader_state = {
'epoch': 0, 
'initial_physical_nodes': 1, 
'num_canonical_nodes': 1, 
'sample_in_epoch': 100, 
'shuffle_seed': 9176
}

This is from a checkpoint saved at step 25 w/ a batch size of 4; so far so good. Now I load my dataset + dataloader (same as before), and instantiate from the state dict:

train_dataloader.load_state_dict(self.dataloader_state)

And for debugging purposes:

        for i, batch in enumerate(train_dataloader):
            print(i)

And the prints start from 0. If I understand correctly, with resumption this should not be the case, right?
I ask because when involved in my actual pl lightning code, it does not seem to be resuming from the correct step either.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the PyTorch Lightning on_save_checkpoint hook and the dataloader state_dict/load_state_dict calls shown in the issue. Trace how Streaming restores sample_in_epoch during iteration, then compare the restored loader's first batches with the checkpoint values. Done means mid-epoch iteration resumes at the expected sample or step rather than starting at index 0.

Written by the indexing model from the issue text.

Assessment

Tech stack
python, pytorch
Domain
machine-learning
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.