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] Keep resource specifications when nesting with_resources in with_parameters #29740

Merged

Conversation

justinvyu
Copy link
Contributor

Why are these changes needed?

Order of nesting matters

The order of nesting matters when using tune.with_parameters and tune.with_resources together. When tune.with_resources is nested inside a tune.with_parameters, the resource specification is dropped and not considered when launching the trials.

def train_func(config, extra_data=None):
    pass

# This works (resources assigned correctly)
trainable = tune.with_resources(
    tune.with_parameters(train_func, extra_data=1),
    {"cpu": 1.0, "gpu": 1.0}
)
results = Tuner(trainable).fit()

# This doesn't work!
trainable = tune.with_parameters(
    tune.with_resources(train_func, {"cpu": 1.0, "gpu": 1.0}),
    extra_data=1
)
results = Tuner(trainable).fit()

This PR introduces a fix for both cases above to work.

tune.with_parameters on a training function with a return value

Another issue addressed in this PR (let me know if this should be its own PR) is allowing tune.with_parameters to work with custom training functions that return a value.

def train_func(config, extra_data=None):
    return {"metric": 1}  # train function returns a "final result"

# The return value gets dropped after wrapping with `tune.with_parameters`
trainable = tune.with_parameters(train_func, extra_data=1)

This PR returns the original training function's return value instead of dropping it.

Open questions

  1. If we introduce any more trainable wrapper utils, we will need to maintain compatibility by passing around the _resource attribute. Is there a better way to keep the resource specification information around?

Related issue number

Closes #29235

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

…parameters

Signed-off-by: Justin Yu <justinvyu@berkeley.edu>
…nction)

Signed-off-by: Justin Yu <justinvyu@berkeley.edu>
Signed-off-by: Justin Yu <justinvyu@berkeley.edu>
Signed-off-by: Justin Yu <justinvyu@berkeley.edu>
@justinvyu justinvyu added bug Something that is supposed to be working; but isn't tune Tune-related issues labels Oct 27, 2022
@justinvyu justinvyu requested a review from krfricke October 27, 2022 00:29
Copy link
Contributor

@krfricke krfricke left a comment

Choose a reason for hiding this comment

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

Great, thanks!

@krfricke krfricke merged commit e1dedb3 into ray-project:master Oct 27, 2022
WeichenXu123 pushed a commit to WeichenXu123/ray that referenced this pull request Dec 19, 2022
…`with_parameters` (ray-project#29740)

The order of nesting matters when using `tune.with_parameters` and `tune.with_resources` together. When `tune.with_resources` is nested inside a `tune.with_parameters`, the resource specification is dropped and not considered when launching the trials.

Signed-off-by: Justin Yu <justinvyu@berkeley.edu>
Signed-off-by: Weichen Xu <weichen.xu@databricks.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something that is supposed to be working; but isn't tune Tune-related issues
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Tune] Not Utilize GPU when Wrap Trainble with both with_resources and with_parameters
2 participants