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

[Core] Implement py_executable support for runtime environments to enable better UV support #50160

Open
wants to merge 26 commits into
base: master
Choose a base branch
from

Conversation

pcmoritz
Copy link
Contributor

@pcmoritz pcmoritz commented Jan 31, 2025

Why are these changes needed?

This implements a very simple runtime environment plugin that allows e.g. using the uv run command for dependency handling (but could also be useful for wrapping the worker command e.g. with a profiler or debugger).

Very simple example:

uv run --with emoji test.py

with

import ray

ray.init(runtime_env={"py_executable": "uv run --with emoji"})

@ray.remote
def f():
    import emoji
    return emoji.emojize("Ray rocks :thumbs_up:")

print(ray.get(f.remote()))

Slightly more complex example with pyproject.toml in the working_dir (see https://docs.astral.sh/uv/guides/scripts):

uv run test.py

with

pyproject.toml:

[project]

name = "test"

version = "0.1"

dependencies = [
   "rich",
   "emoji",
   "ray", # had to do "ray @ file:///tmp/ray-2.41.0-cp312-cp312-macosx_11_0_arm64.whl" here since this is not released yet
]

text.py

import ray
import time
from rich.progress import track

ray.init(runtime_env={"working_dir": ".", "py_executable": "uv run --isolated"})

@ray.remote
def f():
    import emoji
    return emoji.emojize("Ray rocks :thumbs_up:")

for i in track(range(20), description="For example:"):
    print(ray.get(f.remote()))
    time.sleep(0.05)

And the dependencies can also be locked with uv lock.

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

@pcmoritz pcmoritz added the go add ONLY when ready to merge, run all tests label Feb 1, 2025
@pcmoritz pcmoritz requested a review from a team as a code owner February 1, 2025 08:36
@pcmoritz pcmoritz changed the title [Core] Implement generic runtime environment plugin to wrap worker [Core] Implement py_executable support for runtime environments to enable better UV support Feb 2, 2025
Copy link
Contributor

@edoakes edoakes left a comment

Choose a reason for hiding this comment

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

Looks good pending uv e2e test

import emoji
return emoji.emojize("Ray rocks :thumbs_up:")

assert ray.get(emojize.remote()) == "Ray rocks 👍"
Copy link
Contributor

Choose a reason for hiding this comment

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

👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
go add ONLY when ready to merge, run all tests
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants