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

[train] support memory per worker #42999

Merged
merged 10 commits into from
Feb 23, 2024

Conversation

matthewdeng
Copy link
Contributor

@matthewdeng matthewdeng commented Feb 6, 2024

Why are these changes needed?

This enables scheduling Ray Train Workers by specifying "memory" in ScalingConfig.resources_per_worker. This additional logic is necessary because Ray Actors require the special memory kwarg rather than a "memory" entry in the resources dictionary.

As part of this change, I am also changing the interface of BackendExecutor and WorkerGroup to simply take a dictionary for all resources. This matches the interface of ScalingConfig and PlacementGroup, and centralizes all logic to convert to Ray Actor/Task kwargs in WorkerGroup.

Example:

from ray.train import ScalingConfig
from ray.train.torch import TorchTrainer


scaling_config = ScalingConfig(num_workers=2, resources_per_worker={"memory": 10_000})


def train_func(): 
    ...


trainer = TorchTrainer(train_func, scaling_config=scaling_config)
trainer.fit()

Before:

ValueError: The resources dictionary must not contain the key 'memory' or 'object_store_memory'

After:


(TorchTrainer pid=67598) Started distributed worker processes: 
(TorchTrainer pid=67598) - (ip=127.0.0.1, pid=67604) world_rank=0, local_rank=0, node_rank=0
(TorchTrainer pid=67598) - (ip=127.0.0.1, pid=67605) world_rank=1, local_rank=1, node_rank=0
(RayTrainWorker pid=67604) Setting up process group for: env:// [rank=0, world_size=2]

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: Matthew Deng <[email protected]>
Signed-off-by: Matthew Deng <[email protected]>
Signed-off-by: Matthew Deng <[email protected]>
@matthewdeng matthewdeng marked this pull request as ready for review February 6, 2024 18:03
Copy link
Contributor

@justinvyu justinvyu left a comment

Choose a reason for hiding this comment

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

Thanks! See the comment about also needing to update ScalingConfig.as_placement_group_factory, and also a request for the unit test.

python/ray/train/tests/test_worker_group.py Outdated Show resolved Hide resolved
Signed-off-by: Matthew Deng <[email protected]>
Signed-off-by: Matthew Deng <[email protected]>
Signed-off-by: Matthew Deng <[email protected]>
Signed-off-by: Matthew Deng <[email protected]>
Signed-off-by: Matthew Deng <[email protected]>
@matthewdeng matthewdeng marked this pull request as ready for review February 7, 2024 15:28
Copy link
Member

@woshiyyya woshiyyya left a comment

Choose a reason for hiding this comment

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

Good to Go!

Also Thanks for cleaning up the redundant input arguments.

@matthewdeng matthewdeng merged commit 6908b12 into ray-project:master Feb 23, 2024
9 checks passed
@matthewdeng matthewdeng deleted the train-worker-memory branch February 23, 2024 18:47
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.

4 participants