-
Notifications
You must be signed in to change notification settings - Fork 5.8k
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
[tune] reuse_actors per default for function trainables #24040
Conversation
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 | ||
|
||
|
There was a problem hiding this comment.
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]) |
There was a problem hiding this comment.
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
Is there concern if these function trainables use GPU? |
There was a problem hiding this 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
@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) |
Updated, PTAL |
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
scripts/format.sh
to lint the changes in this PR.