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

[Feat][Core] Implement single file module for runtime_env #47807

Merged

Conversation

MortalHappiness
Copy link
Member

Why are these changes needed?

See the description in the corresponding issue for details.

Related issue number

Closes #23151

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

@MortalHappiness MortalHappiness force-pushed the bugfix/#23151-python-modules branch 2 times, most recently from e6afa5d to 175cdf5 Compare September 24, 2024 11:54
@MortalHappiness MortalHappiness marked this pull request as ready for review September 24, 2024 11:54
@MortalHappiness MortalHappiness requested a review from a team as a code owner September 24, 2024 11:55
@anyscalesam anyscalesam added triage Needs triage (eg: priority, bug/not-bug, and owning component) core Issues that should be addressed in Ray Core labels Sep 24, 2024
Copy link
Contributor

@rynewang rynewang left a comment

Choose a reason for hiding this comment

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

Generally LGTM. Left with some wording issues. Also can you add a real Ray running test in python/ray/tests/test_runtime_env_working_dir.py ?

@MortalHappiness
Copy link
Member Author

MortalHappiness commented Sep 25, 2024

@rynewang

The following screencast shows that the zip file actually only contains single file even if its parent folder contains multiple files.

2024-09-25.16-43-02.mp4

Explanation:

  • ls _test shows that there are multiple files under _test folder
  • Also you can see the content of test.py on the right panel, which imports file_module and then inject it as runtime_env.
  • In IDE, I set a breakpoint after create_package
  • When the execution reaches the breakpoint, I copied the value of package_file
  • Also note that the value of the variable directory is a .py file. This variable naming is confusing, so I've renamed it to module_path
  • I ran a cp command to copy it to my ~/Downloads folder.
  • I opend that zip file with file manager and you can see that there is only file_module.py in it.

I've renamed some variables and add more comments in 2957106 to make it clear.

@MortalHappiness MortalHappiness force-pushed the bugfix/#23151-python-modules branch from 9acb04b to 2957106 Compare September 25, 2024 08:56
@MortalHappiness
Copy link
Member Author

Added tests for single file module in python/ray/tests/test_runtime_env_working_dir.py in commit a0d5bc2

Copy link
Contributor

@rynewang rynewang left a comment

Choose a reason for hiding this comment

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

LGTM! Other than 1 nit on naming we can merge this.

@MortalHappiness MortalHappiness force-pushed the bugfix/#23151-python-modules branch from a0d5bc2 to ea58122 Compare September 25, 2024 22:41
@rynewang rynewang enabled auto-merge (squash) September 26, 2024 00:54
@github-actions github-actions bot added the go add ONLY when ready to merge, run all tests label Sep 26, 2024
@rynewang rynewang removed the triage Needs triage (eg: priority, bug/not-bug, and owning component) label Sep 26, 2024
@rynewang
Copy link
Contributor

@angelinalg Hi this PR updates the py_modules runtime env. Previously it only support a py module as a directory, now it supports the other type of module: a single file. Please check the docs, thanks!

Copy link
Contributor

@angelinalg angelinalg left a comment

Choose a reason for hiding this comment

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

Some style nits and some clarification for confusing sentence. Please correct if I introduced inaccuracies.

) -> bytes:
"""Helper function to create hash of a single file or directory.

This function will hash the path of the file or directory,
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
This function will hash the path of the file or directory,
This function hashes the path of the file or directory,

"""Helper function to create hash of a single file or directory.

This function will hash the path of the file or directory,
and if it's a file, it'll hash its content too.
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
and if it's a file, it'll hash its content too.
and if it's a file, then it hashes its content too.

except Exception as e:
logger.debug(
f"Skipping contents of file {filepath} when calculating package hash "
f"because the file could not be opened: {e}"
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
f"because the file could not be opened: {e}"
f"because the file couldn't be opened: {e}"

) -> bytes:
"""Helper function to create hash of a single file.

It'll hash the path of the file and its content to create a hash value.
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
It'll hash the path of the file and its content to create a hash value.
It hashes the path of the file and its content to create a hash value.

def get_uri_for_file(file: str) -> str:
"""Get a content-addressable URI from a file's content.

This function will generate the name of the package by the file.
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
This function will generate the name of the package by the file.
This function generates the name of the package by the file.

"""Get a content-addressable URI from a file's content.

This function will generate the name of the package by the file.
The final package name is: _ray_pkg_<HASH_VAL>.zip of this package.
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
The final package name is: _ray_pkg_<HASH_VAL>.zip of this package.
The final package name is _ray_pkg_<HASH_VAL>.zip, where <HASH_VAL> is a hash of this package.

Copy link
Contributor

Choose a reason for hiding this comment

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

I couldn't understand what you meant to say in this sentence. This is a guess at a rewrite. Please correct if needed.


This function will generate the name of the package by the file.
The final package name is: _ray_pkg_<HASH_VAL>.zip of this package.
e.g., _ray_pkg_029f88d5ecc55e1e4d64fc6e388fd103.zip
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
e.g., _ray_pkg_029f88d5ecc55e1e4d64fc6e388fd103.zip
For example: _ray_pkg_029f88d5ecc55e1e4d64fc6e388fd103.zip

@rynewang rynewang merged commit 61a4220 into ray-project:master Oct 11, 2024
7 checks passed
@rynewang
Copy link
Contributor

Oops! Auto-merged without applying the doc reviews. @MortalHappiness would you mind updating the docs in another PR?

ujjawal-khare pushed a commit to ujjawal-khare-27/ray that referenced this pull request Oct 15, 2024
…t#47807)

Supports single file modules in `py_module` runtime_env.

Signed-off-by: Chi-Sheng Liu <[email protected]>
Signed-off-by: ujjawal-khare <[email protected]>
ujjawal-khare pushed a commit to ujjawal-khare-27/ray that referenced this pull request Oct 15, 2024
…t#47807)

Supports single file modules in `py_module` runtime_env.

Signed-off-by: Chi-Sheng Liu <[email protected]>
Signed-off-by: ujjawal-khare <[email protected]>
ujjawal-khare pushed a commit to ujjawal-khare-27/ray that referenced this pull request Oct 15, 2024
…t#47807)

Supports single file modules in `py_module` runtime_env.

Signed-off-by: Chi-Sheng Liu <[email protected]>
Signed-off-by: ujjawal-khare <[email protected]>
ujjawal-khare pushed a commit to ujjawal-khare-27/ray that referenced this pull request Oct 15, 2024
…t#47807)

Supports single file modules in `py_module` runtime_env.

Signed-off-by: Chi-Sheng Liu <[email protected]>
Signed-off-by: ujjawal-khare <[email protected]>
ujjawal-khare pushed a commit to ujjawal-khare-27/ray that referenced this pull request Oct 15, 2024
…t#47807)

Supports single file modules in `py_module` runtime_env.

Signed-off-by: Chi-Sheng Liu <[email protected]>
Signed-off-by: ujjawal-khare <[email protected]>
ujjawal-khare pushed a commit to ujjawal-khare-27/ray that referenced this pull request Oct 15, 2024
…t#47807)

Supports single file modules in `py_module` runtime_env.

Signed-off-by: Chi-Sheng Liu <[email protected]>
Signed-off-by: ujjawal-khare <[email protected]>
ujjawal-khare pushed a commit to ujjawal-khare-27/ray that referenced this pull request Oct 15, 2024
…t#47807)

Supports single file modules in `py_module` runtime_env.

Signed-off-by: Chi-Sheng Liu <[email protected]>
Signed-off-by: ujjawal-khare <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
core Issues that should be addressed in Ray Core go add ONLY when ready to merge, run all tests
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[runtime_env][Bug] Runtime envs py_modules doesn't support local Python modules
4 participants