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

[tune] reuse_actors per default for function trainables #24040

Merged
merged 10 commits into from
Apr 22, 2022

Conversation

krfricke
Copy link
Contributor

Why are these changes needed?

Function trainables don't carry state, so they should be reused per default for performance optimization.

Related issue number

Would e.g. simplify issues for frequently pausing trials like in #23470

Checks

  • 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 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 :(

Comment on lines -64 to -88
def create_resettable_function(num_resets: defaultdict):
def trainable(config, checkpoint_dir=None):
if checkpoint_dir:
with open(os.path.join(checkpoint_dir, "chkpt"), "rb") as fp:
step = pickle.load(fp)
else:
step = 0

while step < 2:
step += 1
with tune.checkpoint_dir(step) as checkpoint_dir:
with open(os.path.join(checkpoint_dir, "chkpt"), "wb") as fp:
pickle.dump(step, fp)
tune.report(**{"done": step >= 2, "iter": step, "id": config["id"]})

trainable = wrap_function(trainable)

class ResetCountTrainable(trainable):
def reset_config(self, new_config):
num_resets[self.trial_id] += 1
return super().reset_config(new_config)

return ResetCountTrainable


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 test never worked, as num_resets was local to each remote actor.

There is no great way to count the number of resets for function trainables so I've removed this for now

)
self.assertEqual([t.last_result["id"] for t in trials], [0, 1, 2, 3])
self.assertEqual([t.last_result["iter"] for t in trials], [2, 2, 2, 2])
self.assertEqual([num_resets[t.trial_id] for t in trials], [0, 0, 0, 0])
Copy link
Contributor Author

Choose a reason for hiding this comment

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

As you can see, this test doesn't work - the number of resets should have been 4, 5, 6, 7

@xwjiang2010
Copy link
Contributor

Is there concern if these function trainables use GPU?

Copy link
Member

@Yard1 Yard1 left a comment

Choose a reason for hiding this comment

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

Looks good to me. CI seems to be failing though, unsure if related or not

python/ray/tune/tune.py Outdated Show resolved Hide resolved
@krfricke
Copy link
Contributor Author

krfricke commented Apr 21, 2022

@xwjiang2010 thanks, that is indeed a concern, so lets default to False here (note that it doesn't mean it definitely happens, just that we should default to False to be sure)

@krfricke
Copy link
Contributor Author

Updated, PTAL

@krfricke krfricke merged commit 0e2dd40 into ray-project:master Apr 22, 2022
@krfricke krfricke deleted the tune/fn-always-reuse-actors branch April 22, 2022 09:53
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