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

[RLlib; Tune] Fix WandB metric overlap after restore from checkpoint. #46897

Conversation

sven1977
Copy link
Contributor

@sven1977 sven1977 commented Jul 31, 2024

Fix WandB metric overlap after restore from checkpoint.

This PR fixes the following problem:

  • An Algorithm is running through Tuner.fit(), checkpoints every 100 iterations, and uses the WandB integration.
  • Let's assume the algo (trial) crashes at iteration 154 and then the user performs a Tuner.resume() to resume it from the last checkpoint (which would have happened at iteration 100).
  • However, WandB has already logged all the results from iterations 101 to 154. So when restoring, the WandB logger should make sure that the results from the (repeated) 101 to 154 are re-sent and properly logged on the WandB side.

To fix this, we'll make sure to always send the explicit step along with each wandb.log() call.

Note that upon restoring from a checkpoint, RLlib already properly sets Trainable.training_iteration to the value stored in the last checkpoint. Other Trainable subclasses might have to implement a similar logic in their checkpointing behavior or we'll eventually add this to the base Trainable class.

Note also that this PR does NOT affect the behavior for users using the setup_wandb() utility and then log WandB metrics manually (for example in their Ray Train training functions).

Why are these changes needed?

Related issue number

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: sven1977 <[email protected]>
…wandb_metric_overlap_after_restore_from_checkpoint
Signed-off-by: sven1977 <[email protected]>
Signed-off-by: sven1977 <[email protected]>
Signed-off-by: sven1977 <[email protected]>
@sven1977 sven1977 enabled auto-merge (squash) July 31, 2024 13:54
@github-actions github-actions bot added the go add ONLY when ready to merge, run all tests label Jul 31, 2024
@sven1977 sven1977 added the tests-ok The tagger certifies test failures are unrelated and assumes personal liability. label Aug 1, 2024
@github-actions github-actions bot disabled auto-merge August 1, 2024 16:44
@sven1977 sven1977 enabled auto-merge (squash) August 1, 2024 21:53
Copy link
Contributor

@justinvyu justinvyu left a comment

Choose a reason for hiding this comment

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

Makes sense to me!

By the way, this will only fix the issue for the setup_wandb flow where users call that directly in their code. This does not solve the WandbLoggerCallback case -- should we fix it there too?

Nevermind. this is the exact line of code that was changed.

@sven1977
Copy link
Contributor Author

sven1977 commented Aug 2, 2024

Yeah, that's what I thought, too. Thanks for clarifying and for your review @justinvyu ! :)

@sven1977 sven1977 changed the title [RLlib] Fix WandB metric overlap after restore from checkpoint. [RLlib; Tune] Fix WandB metric overlap after restore from checkpoint. Aug 2, 2024
Copy link
Collaborator

@simonsays1980 simonsays1980 left a comment

Choose a reason for hiding this comment

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

LGTM. Great improvement for users imo. Checkpointing is so important and should work as clean as possible for good user experience.

@@ -15,6 +15,7 @@
from ray._private.storage import _load_class
from ray.air import session
from ray.air._internal import usage as air_usage
from ray.air.constants import TRAINING_ITERATION
Copy link
Collaborator

Choose a reason for hiding this comment

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

If air goes anyways shouldn't this class maybe move over to train or tune?

@@ -415,7 +416,7 @@ def run(self):
log, config_update = self._handle_result(item_content)
try:
self._wandb.config.update(config_update, allow_val_change=True)
self._wandb.log(log)
self._wandb.log(log, step=log.get(TRAINING_ITERATION))
Copy link
Collaborator

Choose a reason for hiding this comment

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

Sweet.

@sven1977 sven1977 merged commit 603d552 into ray-project:master Aug 2, 2024
5 of 6 checks passed
@sven1977 sven1977 deleted the fix_wandb_metric_overlap_after_restore_from_checkpoint branch August 2, 2024 09:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
go add ONLY when ready to merge, run all tests 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.

3 participants