Skip to content

[train] Fix broken tune tests and support ray storage #38950

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

Merged
merged 8 commits into from
Aug 27, 2023

Conversation

justinvyu
Copy link
Contributor

@justinvyu justinvyu commented Aug 26, 2023

Why are these changes needed?

This PR re-introduces support for ray storage ray.init(storage="s3://...") and fixes a broken tune controller test.

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: Justin Yu <justinvyu@anyscale.com>
Signed-off-by: Justin Yu <justinvyu@anyscale.com>
…pens

Signed-off-by: Justin Yu <justinvyu@anyscale.com>
Signed-off-by: Justin Yu <justinvyu@anyscale.com>
Signed-off-by: Justin Yu <justinvyu@anyscale.com>
Comment on lines 1812 to 1819
# If a decision is already cached, don't override it for CONTINUE/NOOP
# decisions. Only escalate the cached decision to a STOP/PAUSE if requested.
# This is only very relevant for pausing trials, since we cache a PAUSE
# decision to happen after a save finishes.
# We need to make sure that we don't override it in the
# time between the save operation starting and finishing.
if decision in [TrialScheduler.STOP, TrialScheduler.PAUSE]:
self._cached_trial_decisions[trial.trial_id] = decision
Copy link
Contributor Author

Choose a reason for hiding this comment

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

this is pretty confusing -- we do pause + save checkpoint as 2 steps:

  1. first time we try to schedule a pause, we schedule a save instead. then we CACHE a pause decision.
  2. then, once the save finishes, we pop the cached decision and execute it, which should be a PAUSE again, in which case we enter the should_checkpoint=False condition and just stop the trial and set the status to PAUSED.

In between these 2 steps, if the scheduler outputs some decision that's not PAUSED (ex: NOOP), then this thing will just hang forever. So we need to make sure that the cached PAUSE decision is not overriden by something random while the save is happening.

I allow STOP decisions to override, but unclear if this ever happens..

Copy link
Contributor

Choose a reason for hiding this comment

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

Hm, the _cached_trial_decision is only updated on saves. The scheduler actions only affect _queued_trial_decision. (I know the naming is confusing... happy to rename it).

Does this still come up? Is this like a double triggered save? In that case, should we have this line:

            if trial.temporary_state.saving_to:
                # If a save is already in progress, don't schedule another one.
                return trial.temporary_state.saving_to

in the new storage path _schedule_trial_save as well?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I see, you're right. The problem is a little different from what I described above. Here's what's actually happening to cause that unit test to fail:

  1. The test defines a scheduler that manually calls tune_controller.pause_trial(trial) during the on_trial_result hook
  2. should_checkpoint=True by default, so this will schedule a SAVE and set the cached trial decision here:

self._cached_trial_decisions[trial.trial_id] = TrialScheduler.PAUSE

  1. At this point, we return a NOOP trial scheduler decision (since we paused manually) and end up here:

decision = self._scheduler_alg.on_trial_result(
self._wrapped(), trial, flat_result

  1. The trial IS SAVING at this point, so we enter this block:

if trial.is_saving:
logger.debug(f"Caching trial decision for trial {trial}: {decision}")
# Cache decision to execute on after the save is processed.
# This prevents changing the trial's state or kicking off
# another training step prematurely.
# If a decision is already cached, don't override it for CONTINUE/NOOP
# decisions. Only escalate the cached decision to a STOP/PAUSE if requested.
# This is only very relevant for pausing trials, since we cache a PAUSE
# decision to happen after a save finishes.
# We need to make sure that we don't override it in the
# time between the save operation starting and finishing.
if decision in [TrialScheduler.STOP, TrialScheduler.PAUSE]:
self._cached_trial_decisions[trial.trial_id] = decision
return None

  1. We overwrite the PAUSE cached decision with the NOOP, leading to an infinite hang.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The conclusion: Calling pause_trial(should_checkpoint=True) directly inside a scheduler's on_trial_result leads to a hang.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

PBT doesn't run into this problem because it calls pause_trial(should_checkpoint=False)

Comment on lines 171 to 174
trial.set_status(Trial.PAUSED)
trial.update_resources(dict(cpu=4, gpu=0))
trial.set_status(orig_status)

Copy link
Contributor Author

@justinvyu justinvyu Aug 26, 2023

Choose a reason for hiding this comment

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

this thing errors since it's still RUNNING (even if you put it after pause_trial)

Signed-off-by: Justin Yu <justinvyu@anyscale.com>
Comment on lines +169 to +175
# NOTE: This is a hack to get around the new pausing logic,
# which doesn't set the trial status to PAUSED immediately.
orig_status = trial.status
trial.set_status(Trial.PAUSED)
trial.update_resources(dict(cpu=4, gpu=0))
trial.set_status(orig_status)
return TrialScheduler.PAUSE
Copy link
Contributor Author

@justinvyu justinvyu Aug 26, 2023

Choose a reason for hiding this comment

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

I've reverted the tune controller changes and updated the test to pass, but calling pause_trial within on_trial_result is still an issue.

Signed-off-by: Justin Yu <justinvyu@anyscale.com>
@justinvyu justinvyu added the tests-ok The tagger certifies test failures are unrelated and assumes personal liability. label Aug 27, 2023
@krfricke krfricke merged commit b19bcab into ray-project:master Aug 27, 2023
matthewdeng pushed a commit to matthewdeng/ray that referenced this pull request Aug 30, 2023
)

This PR re-introduces support for ray storage ray.init(storage="s3://...") and fixes a broken tune controller test.

Signed-off-by: Justin Yu <justinvyu@anyscale.com>
GeneDer pushed a commit that referenced this pull request Aug 30, 2023
* [train] enable new persistence mode for core and serve tests (#38938)

Signed-off-by: Matthew Deng <matt@anyscale.com>

* [train] New persistence mode: Update 🐠 `ML Libraries w/ Ray Client Examples (Python 3.7)` (#38923)

Signed-off-by: Justin Yu <justinvyu@anyscale.com>

* [train] remove non-URI assertion (#38944)

Signed-off-by: Matthew Deng <matt@anyscale.com>

* [train] New persistence mode: Update 📖 `Doc tests and examples (excluding Ray AIR examples)` (#38940)

Signed-off-by: Justin Yu <justinvyu@anyscale.com>
Signed-off-by: Matthew Deng <matt@anyscale.com>
Co-authored-by: Matthew Deng <matt@anyscale.com>

* disable legacy sync config logic in trainable (#38952)

Signed-off-by: Justin Yu <justinvyu@anyscale.com>

* [2.7 CI][New Persistent Mode][6/n] 📖 ✈️ Ray AIR examples (#38918)

Signed-off-by: woshiyyya <xiaoyunxuan1998@gmail.com>

* [2.7 CI][New Persistent Mode][2/n] 📺 📖 Doc GPU tests and examples (#38905)


Signed-off-by: woshiyyya <xiaoyunxuan1998@gmail.com>

* [2.7 CI][New Persistent Mode][4/n] 📺 🚂 Train GPU tests & 🚂 Datasets Train Integration GPU Tests and Examples (#38910)



Signed-off-by: woshiyyya <xiaoyunxuan1998@gmail.com>
Signed-off-by: Justin Yu <justinvyu@anyscale.com>
Co-authored-by: Justin Yu <justinvyu@anyscale.com>

* [2.7 CI][New Persistent Mode][1/n] 📺 ✈️ AIR GPU tests (ray/air) & ⚡ :python: Lightning 2.0 Train GPU tests  (#38903)


Signed-off-by: woshiyyya <xiaoyunxuan1998@gmail.com>
Signed-off-by: Yunxuan Xiao <xiaoyunxuan1998@gmail.com>

* [train] Fix broken tune tests and support ray storage (#38950)

This PR re-introduces support for ray storage ray.init(storage="s3://...") and fixes a broken tune controller test.

Signed-off-by: Justin Yu <justinvyu@anyscale.com>

* [train] New persistence mode: Finish migrating `xgb`, `lgbm` and `sklearn` trainers, checkpoints + tests (#38959)


Signed-off-by: Justin Yu <justinvyu@anyscale.com>

* [2.7 CI][New Persistent Mode][5/n] 📖 Doc examples for external code (#38915)

Signed-off-by: woshiyyya <xiaoyunxuan1998@gmail.com>

* [train][rllib] temporarily disable new persistence mode for rllib tests (#38965)

Signed-off-by: Matthew Deng <matt@anyscale.com>

* [2.7 CI][New Persistent Mode][8/n] ✈️ AIR tests (ray/air) (#38932)

Signed-off-by: woshiyyya <xiaoyunxuan1998@gmail.com>

* [tune] Storage: 🐙 🧠 Tune tests and examples {using RLlib} migration (#38895)

Signed-off-by: Kai Fricke <kai@anyscale.com>
Co-authored-by: matthewdeng <matt@anyscale.com>

* [train] Fix MosaicTrainer example and unit test (#38970)

Signed-off-by: Justin Yu <justinvyu@anyscale.com>

* [air/release] Fix dreambooth example image preprocessing logic (#39020)

Signed-off-by: Justin Yu <justinvyu@anyscale.com>

* [train] clean up ray.train._checkpoint imports (#38951)

Signed-off-by: Matthew Deng <matt@anyscale.com>

* [train] high level cleanup of Ray Train docs (#38971)

Signed-off-by: Matthew Deng <matt@anyscale.com>

* [wip][docs] update FrameworkPredictor examples (#38634)


Signed-off-by: Matthew Deng <matt@anyscale.com>
Signed-off-by: matthewdeng <matt@anyscale.com>

* [train] Add documentation for using metadata argument to save preprocessors (#38701)

* [Train] Restructure Ray Train Example Page (#38814)

Signed-off-by: woshiyyya <xiaoyunxuan1998@gmail.com>

* [air] Deprecate some fields/classes that are supposed to be gone in 2.6. (#38794)

Signed-off-by: xwjiang2010 <xwjiang2010@gmail.com>

* [tune/storage] Fix Tune multinode tests (#39050)

Fixes multinode tests by using the new train.report() API.

Signed-off-by: Kai Fricke <kai@anyscale.com>

* [tune] Fix BOHB example for new storage (#38983)

The new storage path does not create "empty" checkpoints per default anymore. Previously, when no checkpoint is saved, PAUSEing a trial would create a dummy checkpoint that only contains trial metadata (such as the iteration number). This is not the case anymore.

Examples now have to implement checkpointing to properly restore previous state. This was also true previously - but some of our simple examples (e.g. the one in this PR) didn't implement it and still "worked".

I think it's fine to keep the functionality as is and require our examples to show checkpointing implementations. This will ensure that users don't shoot their feet trying to use e.g. BOHB.

Separately, BOHB was malfunctioning as trials were repeatedly PAUSED and restarted as they've never been removed from `bracket.trials_to_unpause`. @justinvyu mentioned this in the review where it was introduced and I believed at the time it wasn't necessary - turns out it is, as we can end up in a situation where a bracket is never finished because trials are constantly running. This was not caught by any tests. We should add one in a follow-up - for now we can proceed with this PR to pick onto Ray 2.7.

Signed-off-by: Kai Fricke <kai@anyscale.com>

* [Release Test] Fix `long_running_horovod_tune_test`. (#39012)

Signed-off-by: Yunxuan Xiao <yunxuanx@anyscale.com>
Signed-off-by: Yunxuan Xiao <xiaoyunxuan1998@gmail.com>

* [train] New persistence mode: `StorageContext` unit tests (#39023)

Signed-off-by: Justin Yu <justinvyu@anyscale.com>

* [train] enable train + tune tests and examples (#39021)

Signed-off-by: Matthew Deng <matt@anyscale.com>

* [rllib] Fix storage-path related tests (#38947)

This PR fixes rllib-related tests that didn't pass changes related to the new storage context.

Signed-off-by: Kai Fricke <kai@anyscale.com>
Signed-off-by: matthewdeng <matt@anyscale.com>
Co-authored-by: matthewdeng <matt@anyscale.com>

* [train] New persistence mode: Migrate 🐙 `Tune tests and examples (medium)` (#39081)

Signed-off-by: Justin Yu <justinvyu@anyscale.com>

---------

Signed-off-by: Matthew Deng <matt@anyscale.com>
Signed-off-by: Justin Yu <justinvyu@anyscale.com>
Signed-off-by: woshiyyya <xiaoyunxuan1998@gmail.com>
Signed-off-by: Yunxuan Xiao <xiaoyunxuan1998@gmail.com>
Signed-off-by: Kai Fricke <kai@anyscale.com>
Signed-off-by: matthewdeng <matt@anyscale.com>
Signed-off-by: xwjiang2010 <xwjiang2010@gmail.com>
Signed-off-by: Yunxuan Xiao <yunxuanx@anyscale.com>
Co-authored-by: Justin Yu <justinvyu@anyscale.com>
Co-authored-by: Yunxuan Xiao <yunxuanx@anyscale.com>
Co-authored-by: Kai Fricke <krfricke@users.noreply.github.com>
Co-authored-by: Eric Liang <ekhliang@gmail.com>
Co-authored-by: xwjiang2010 <87673679+xwjiang2010@users.noreply.github.com>
arvind-chandra pushed a commit to lmco/ray that referenced this pull request Aug 31, 2023
)

This PR re-introduces support for ray storage ray.init(storage="s3://...") and fixes a broken tune controller test.

Signed-off-by: Justin Yu <justinvyu@anyscale.com>
Signed-off-by: e428265 <arvind.chandramouli@lmco.com>
LeonLuttenberger pushed a commit to jaidisido/ray that referenced this pull request Sep 5, 2023
)

This PR re-introduces support for ray storage ray.init(storage="s3://...") and fixes a broken tune controller test.

Signed-off-by: Justin Yu <justinvyu@anyscale.com>
jimthompson5802 pushed a commit to jimthompson5802/ray that referenced this pull request Sep 12, 2023
)

This PR re-introduces support for ray storage ray.init(storage="s3://...") and fixes a broken tune controller test.

Signed-off-by: Justin Yu <justinvyu@anyscale.com>
Signed-off-by: Jim Thompson <jimthompson5802@gmail.com>
vymao pushed a commit to vymao/ray that referenced this pull request Oct 11, 2023
)

This PR re-introduces support for ray storage ray.init(storage="s3://...") and fixes a broken tune controller test.

Signed-off-by: Justin Yu <justinvyu@anyscale.com>
Signed-off-by: Victor <vctr.y.m@example.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.

3 participants