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

[Train] LightningTrainer always resumes from the latest AIR checkpoint during restoration. #35617

Conversation

woshiyyya
Copy link
Member

@woshiyyya woshiyyya commented May 22, 2023

Why are these changes needed?

If users provide a ckpt_path in LightningConfigBuilder.fit_param(), when resuming training from a failed run, LightningTrainer will always resume training from ckpt_path again, instead of the latest AIR checkpoint. In that case, the training won't proceed after restored from failures.

Code:

checkpoint = session.get_checkpoint()
if checkpoint and "ckpt_path" not in trainer_fit_params:
with checkpoint.as_directory() as ckpt_dir:
trainer_fit_params["ckpt_path"] = f"{ckpt_dir}/{MODEL_KEY}"
trainer.fit(lightning_module, **trainer_fit_params)
else:
trainer.fit(lightning_module, **trainer_fit_params)

We should always restore from the latest checkpoint from session.get_checkpoint(), otherwise, the training re-start from the beginning after restoration.

Details in #35613.

Related issue number

Close #35613

Checks

  • I've signed off every commit(by using the -s flag, i.e., git commit -s) in this PR.
  • I've run scripts/format.sh to lint the changes in this PR.
  • I've included any doc changes needed for https://docs.ray.io/en/master/.
    • I've added any new APIs to the API Reference. For example, if I added a
      method in Tune, I've added it in doc/source/tune/api/ under the
      corresponding .rst file.
  • I've made sure the tests are passing. Note that there might be a few flaky tests, see the recent failures at https://flakey-tests.ray.io/
  • Testing Strategy
    • Unit tests
    • Release tests
    • This PR is not tested :(

Signed-off-by: woshiyyya <xiaoyunxuan1998@gmail.com>
@woshiyyya woshiyyya marked this pull request as ready for review May 24, 2023 01:21
@ArturNiederfahrenhorst
Copy link
Contributor

@woshiyyya Please make sure to also create the cherry pick PR yourself after this is merged!

woshiyyya added 4 commits May 24, 2023 00:59
Signed-off-by: woshiyyya <xiaoyunxuan1998@gmail.com>
Signed-off-by: woshiyyya <xiaoyunxuan1998@gmail.com>
Signed-off-by: woshiyyya <xiaoyunxuan1998@gmail.com>
Copy link
Member

@gjoliver gjoliver left a comment

Choose a reason for hiding this comment

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

ok, just 1 nit.
thanks.

woshiyyya added 2 commits May 24, 2023 19:23
Signed-off-by: woshiyyya <xiaoyunxuan1998@gmail.com>
@@ -541,7 +541,15 @@ def _lightning_train_loop_per_worker(config):

# Restore from a previously failed run
checkpoint = session.get_checkpoint()
if checkpoint and "ckpt_path" not in trainer_fit_params:
if checkpoint:
logger.info("Restoring LightningTrainer from a failed run. ")
Copy link
Contributor

Choose a reason for hiding this comment

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

Actually is this always true? What happens if the user passes in an AIR checkpoint?

LightningTrainer(..., resume_from_checkpoint=some_checkpoint)

Copy link
Member Author

Choose a reason for hiding this comment

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

It might not be a failed run. Updated the log message.

Signed-off-by: woshiyyya <xiaoyunxuan1998@gmail.com>
Signed-off-by: woshiyyya <xiaoyunxuan1998@gmail.com>
@woshiyyya woshiyyya added the tests-ok The tagger certifies test failures are unrelated and assumes personal liability. label May 25, 2023
@matthewdeng matthewdeng merged commit 3c03523 into ray-project:master May 25, 2023
woshiyyya added a commit to woshiyyya/ray that referenced this pull request May 25, 2023
…t during restoration. (ray-project#35617)


Signed-off-by: woshiyyya <xiaoyunxuan1998@gmail.com>
ArturNiederfahrenhorst pushed a commit that referenced this pull request May 26, 2023
…t during restoration. (#35617) (#35791)

Signed-off-by: woshiyyya <xiaoyunxuan1998@gmail.com>
scv119 pushed a commit to scv119/ray that referenced this pull request Jun 16, 2023
…t during restoration. (ray-project#35617)


Signed-off-by: woshiyyya <xiaoyunxuan1998@gmail.com>
arvind-chandra pushed a commit to lmco/ray that referenced this pull request Aug 31, 2023
…t during restoration. (ray-project#35617)

Signed-off-by: woshiyyya <xiaoyunxuan1998@gmail.com>
Signed-off-by: e428265 <arvind.chandramouli@lmco.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
tests-ok The tagger certifies test failures are unrelated and assumes personal liability.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Train] LightningTrainer failed to auto-restore if ckpt_path provided in LightningConfigbuilder.fit_param()
4 participants