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] Cleanup examples folder #14: Add example script for how to resume a tune.Tuner.fit() experiment from a checkpoint. #45681

Conversation

sven1977
Copy link
Contributor

@sven1977 sven1977 commented Jun 3, 2024

Cleanup examples folder #14: Add example script for how to resume a tune.Tuner.fit() experiment from a checkpoint.

  • Contains also a bug fix for MetricsLogger and Stats and a small API change wrt. MetricsLogger.peek() (key instead of *key to unify signature with all the other methods of MetricsLogger).

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]>
…nup_examples_folder_14_continue_training_from_checkpoint
Signed-off-by: sven1977 <[email protected]>
Signed-off-by: sven1977 <[email protected]>
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. Invaluable example for users!

tuner = tune.Tuner(
trainable=config.algo_class,
param_space=config,
run_config=air.RunConfig(
Copy link
Collaborator

Choose a reason for hiding this comment

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

In regard to the future deprecation of air: Can we use ray.train.RunConfig here instead?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done

param_space=config,
run_config=air.RunConfig(
callbacks=tune_callbacks,
checkpoint_config=air.CheckpointConfig(
Copy link
Collaborator

Choose a reason for hiding this comment

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

Same here: can we use ray.train.CheckpointConfig?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done

results = tuner.fit()
experiment_name = Path(results.experiment_path).name

# Extract the latest checkpoint from the results and confirm it's the right one.
Copy link
Collaborator

Choose a reason for hiding this comment

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

Let's state this comment differently. The get_best_result gets us only in this specific setup and only with a checkpoint frequency of 1 the latest checkpoint, otherwise we get the one with the highest episode_return_mean from whenever this happened.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ah, good catch! Yes, in this example, we should probably just use the last checkpoint, not necessarily the best. ...

# TODO (simon): Change to -800 once the metrics are fixed. Currently
# the combined return is not correctly computed.
f"{ENV_RUNNER_RESULTS}/episode_return_mean": -400,
f"{ENV_RUNNER_RESULTS}/{EPISODE_RETURN_MEAN}": -800,
Copy link
Collaborator

Choose a reason for hiding this comment

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

Great catch!

Signed-off-by: sven1977 <[email protected]>
…nup_examples_folder_14_continue_training_from_checkpoint
@sven1977 sven1977 enabled auto-merge (squash) June 3, 2024 10:08
@github-actions github-actions bot disabled auto-merge June 3, 2024 10:08
@github-actions github-actions bot added the go add ONLY when ready to merge, run all tests label Jun 3, 2024
@sven1977 sven1977 enabled auto-merge (squash) June 3, 2024 10:18
Signed-off-by: sven1977 <[email protected]>
@github-actions github-actions bot disabled auto-merge June 3, 2024 11:38
@sven1977 sven1977 enabled auto-merge (squash) June 3, 2024 13:28
@sven1977 sven1977 merged commit 440aa81 into ray-project:master Jun 3, 2024
7 checks passed
@sven1977 sven1977 deleted the cleanup_examples_folder_14_continue_training_from_checkpoint branch June 3, 2024 14:44
richardsliu pushed a commit to richardsliu/ray that referenced this pull request Jun 12, 2024
…r how to resume a tune.Tuner.fit() experiment from a checkpoint. (ray-project#45681)

Signed-off-by: Richard Liu <[email protected]>
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
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants