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

[air] Don't set rank-specific local directories for Train workers #38007

Merged
merged 4 commits into from
Aug 2, 2023

Conversation

justinvyu
Copy link
Contributor

Why are these changes needed?

This PR is based on the REP here: ray-project/enhancements#35

We don't want to force train workers to have separated working directories (rank_x). Instead, this can be configured by the user themselves.

This auto chdir behavior led to issues in the past, where certain frameworks expect a common working directory for each worker (#35894).

# Before
def train_loop_per_worker():
    assert os.getcwd() == "{storage_path}/{exp_name}/{trial_name}/rank_x

# After
def train_loop_per_worker():
    assert os.getcwd() == "{storage_path}/{exp_name}/{trial_name}

    # Write to a unique rank dir yourself if you want to.
    rank_dir = f"rank_{train.get_context().get_world_rank()}"
    os.makedirs(rank_dir, exist_ok=True)
    with open(os.path.join(rank_dir, "artifact.txt")) as f:
        f.write("asdfsadf")

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>
Signed-off-by: Justin Yu <justinvyu@anyscale.com>
Signed-off-by: Justin Yu <justinvyu@anyscale.com>
# Change the working directory to the local trial directory.
# -> All workers on the same node share a working directory.
os.makedirs(storage.trial_local_path, exist_ok=True)
os.chdir(storage.trial_local_path)
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Note: Ray actors don't inherit the working directory of their parent. Even though the Trainable actor changes its directory by default to the trial dir, the worker actor still starts at the original working dir.

@justinvyu justinvyu added the tests-ok The tagger certifies test failures are unrelated and assumes personal liability. label Aug 2, 2023
@ericl ericl merged commit 50e4d4c into ray-project:master Aug 2, 2023
49 of 54 checks passed
@justinvyu justinvyu deleted the air/persistence/no_chdir branch August 2, 2023 18:23
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.

Thank you Justin! It looks good to me. I love this change and it would resolve many inconsistency issues for lightning/deepspeed.

NripeshN pushed a commit to NripeshN/ray that referenced this pull request Aug 15, 2023
harborn pushed a commit to harborn/ray that referenced this pull request Aug 17, 2023
arvind-chandra pushed a commit to lmco/ray that referenced this pull request Aug 31, 2023
vymao pushed a commit to vymao/ray that referenced this pull request Oct 11, 2023
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.

None yet

3 participants