Skip to content
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

Fix auto-resume training from checkpoint #9822

Merged
merged 2 commits into from
Jan 27, 2021
Merged

Fix auto-resume training from checkpoint #9822

merged 2 commits into from
Jan 27, 2021

Conversation

jncasey
Copy link
Contributor

@jncasey jncasey commented Jan 27, 2021

What does this PR do?

This fixes a few minor issues with training auto-resume, as discussed here

  1. checkpoints = [path for path in content if _re_checkpoint.search(path) is not None and os.path.isdir(path)] was returning empty. I changed os.path.isdir(path) to os.path.isdir(os.path.join(folder, path)) and now it returns a list of the checkpoint folders as expected.
  2. Similarly, the get_last_checkpoint function was returning the basename of the checkpoint folder, not the full path, which seems to be expected based on the updates to the example scripts. I changed the last line of the function to return os.path.join(folder, max(checkpoints, key=lambda x: int(_re_checkpoint.search(x).groups()[0])))
  3. After I made those update, it was resuming from the oldest checkpoint, not the newest. I noticed the checkpoint regex was only capturing the final digit in the directory name. I changed it to _re_checkpoint = re.compile(r"^" + PREFIX_CHECKPOINT_DIR + r"\-(\d+)$") with the + inside the capture group, and now get_last_checkpoint is giving me the newest checkpoint as expected.

Who can review?

Copy link
Collaborator

@sgugger sgugger left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for all the fixes!

@sgugger
Copy link
Collaborator

sgugger commented Jan 27, 2021

Oh you need to run make style on your branch for the styling test to pass. Let me know if you run into any issue doing that!

@sgugger sgugger requested a review from LysandreJik January 27, 2021 00:38
@jncasey
Copy link
Contributor Author

jncasey commented Jan 27, 2021

Sorry! I'm pretty rusty on the software dev stuff - college was 16 years ago. I think I've fixed it now.

Copy link
Member

@LysandreJik LysandreJik left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great, thanks for fixing @jncasey!

@LysandreJik LysandreJik merged commit f4bf0de into huggingface:master Jan 27, 2021
@jncasey jncasey deleted the fix_auto_resume_training branch January 27, 2021 14:28
Qbiwan pushed a commit to Qbiwan/transformers that referenced this pull request Jan 31, 2021
* Fix auto-resume training from checkpoint

* style fixes
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.

3 participants