Skip to content

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
Collaborator

@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
Collaborator

Choose a reason for hiding this comment

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

👍

@pcmoritz pcmoritz enabled auto-merge (squash) February 4, 2025 17:59
@github-actions github-actions bot disabled auto-merge February 4, 2025 20:50
@pcmoritz pcmoritz enabled auto-merge (squash) February 4, 2025 21:02
@github-actions github-actions bot disabled auto-merge February 4, 2025 22:04
@pcmoritz pcmoritz enabled auto-merge (squash) February 4, 2025 23:36
@github-actions github-actions bot disabled auto-merge February 4, 2025 23:45
@pcmoritz pcmoritz enabled auto-merge (squash) February 4, 2025 23:45
@github-actions github-actions bot disabled auto-merge February 5, 2025 00:54
@pcmoritz pcmoritz enabled auto-merge (squash) February 5, 2025 00:54
@pcmoritz pcmoritz disabled auto-merge February 5, 2025 05:46
@pcmoritz pcmoritz merged commit ecb9eeb into master Feb 5, 2025
5 of 6 checks passed
@pcmoritz pcmoritz deleted the wrap-runtime-env branch February 5, 2025 05:46
pcmoritz added a commit that referenced this pull request Feb 13, 2025
…#50462)

<!-- Thank you for your contribution! Please review
https://github.com/ray-project/ray/blob/master/CONTRIBUTING.rst before
opening a pull request. -->

<!-- Please add a reviewer to the assignee section when you create a PR.
If you don't have the access to it, we will shortly find a reviewer and
assign them to your PR. -->

## Why are these changes needed?

Next step after #50160 to make it
more convenient to use UV with Ray.

This is a useful runtime environment hook for mirroring the environment
of `uv run` to the workers (currently the args to uv run and the
working_dir). This is useful because it will allow people to intuitively
use `uv run` in a distributed application with the same behavior as for
a single python process.

This only modifies the environment if the driver was run with `uv run`
and could conceivably become the default for drivers run with uv run.

This is currently a developer API as implied by the fact that it is in
the `_private` namespace. It is currently for experimentation and can
needs to be opted in via

```shell
export RAY_RUNTIME_ENV_HOOK=ray._private.runtime_env.uv_runtime_env_hook.hook
```

If it works well, we might make it the default in the `uv run` case.

## Related issue number

<!-- For example: "Closes #1234" -->

## 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: Philipp Moritz <pcmoritz@gmail.com>
Co-authored-by: Edward Oakes <ed.nmi.oakes@gmail.com>
Co-authored-by: angelinalg <122562471+angelinalg@users.noreply.github.com>
xsuler pushed a commit to antgroup/ant-ray that referenced this pull request Mar 4, 2025
…able better UV support (ray-project#50160)

<!-- Thank you for your contribution! Please review
https://github.com/ray-project/ray/blob/master/CONTRIBUTING.rst before
opening a pull request. -->

<!-- Please add a reviewer to the assignee section when you create a PR.
If you don't have the access to it, we will shortly find a reviewer and
assign them to your PR. -->

## 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

```Python
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:
```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
```Python
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

<!-- For example: "Closes ray-project#1234" -->

## 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: Philipp Moritz <pcmoritz@gmail.com>
Co-authored-by: pcmoritz <pcmoritz@anyscale.com>
Co-authored-by: angelinalg <122562471+angelinalg@users.noreply.github.com>
xsuler pushed a commit to antgroup/ant-ray that referenced this pull request Mar 4, 2025
…ray-project#50462)

<!-- Thank you for your contribution! Please review
https://github.com/ray-project/ray/blob/master/CONTRIBUTING.rst before
opening a pull request. -->

<!-- Please add a reviewer to the assignee section when you create a PR.
If you don't have the access to it, we will shortly find a reviewer and
assign them to your PR. -->

## Why are these changes needed?

Next step after ray-project#50160 to make it
more convenient to use UV with Ray.

This is a useful runtime environment hook for mirroring the environment
of `uv run` to the workers (currently the args to uv run and the
working_dir). This is useful because it will allow people to intuitively
use `uv run` in a distributed application with the same behavior as for
a single python process.

This only modifies the environment if the driver was run with `uv run`
and could conceivably become the default for drivers run with uv run.

This is currently a developer API as implied by the fact that it is in
the `_private` namespace. It is currently for experimentation and can
needs to be opted in via

```shell
export RAY_RUNTIME_ENV_HOOK=ray._private.runtime_env.uv_runtime_env_hook.hook
```

If it works well, we might make it the default in the `uv run` case.

## Related issue number

<!-- For example: "Closes ray-project#1234" -->

## 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: Philipp Moritz <pcmoritz@gmail.com>
Co-authored-by: Edward Oakes <ed.nmi.oakes@gmail.com>
Co-authored-by: angelinalg <122562471+angelinalg@users.noreply.github.com>
xsuler pushed a commit to antgroup/ant-ray that referenced this pull request Mar 4, 2025
…able better UV support (ray-project#50160)

<!-- Thank you for your contribution! Please review
https://github.com/ray-project/ray/blob/master/CONTRIBUTING.rst before
opening a pull request. -->

<!-- Please add a reviewer to the assignee section when you create a PR.
If you don't have the access to it, we will shortly find a reviewer and
assign them to your PR. -->

## 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

```Python
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:
```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
```Python
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

<!-- For example: "Closes ray-project#1234" -->

## 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: Philipp Moritz <pcmoritz@gmail.com>
Co-authored-by: pcmoritz <pcmoritz@anyscale.com>
Co-authored-by: angelinalg <122562471+angelinalg@users.noreply.github.com>
xsuler pushed a commit to antgroup/ant-ray that referenced this pull request Mar 4, 2025
…ray-project#50462)

<!-- Thank you for your contribution! Please review
https://github.com/ray-project/ray/blob/master/CONTRIBUTING.rst before
opening a pull request. -->

<!-- Please add a reviewer to the assignee section when you create a PR.
If you don't have the access to it, we will shortly find a reviewer and
assign them to your PR. -->

## Why are these changes needed?

Next step after ray-project#50160 to make it
more convenient to use UV with Ray.

This is a useful runtime environment hook for mirroring the environment
of `uv run` to the workers (currently the args to uv run and the
working_dir). This is useful because it will allow people to intuitively
use `uv run` in a distributed application with the same behavior as for
a single python process.

This only modifies the environment if the driver was run with `uv run`
and could conceivably become the default for drivers run with uv run.

This is currently a developer API as implied by the fact that it is in
the `_private` namespace. It is currently for experimentation and can
needs to be opted in via

```shell
export RAY_RUNTIME_ENV_HOOK=ray._private.runtime_env.uv_runtime_env_hook.hook
```

If it works well, we might make it the default in the `uv run` case.

## Related issue number

<!-- For example: "Closes ray-project#1234" -->

## 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: Philipp Moritz <pcmoritz@gmail.com>
Co-authored-by: Edward Oakes <ed.nmi.oakes@gmail.com>
Co-authored-by: angelinalg <122562471+angelinalg@users.noreply.github.com>
park12sj pushed a commit to park12sj/ray that referenced this pull request Mar 18, 2025
…able better UV support (ray-project#50160)

<!-- Thank you for your contribution! Please review
https://github.com/ray-project/ray/blob/master/CONTRIBUTING.rst before
opening a pull request. -->

<!-- Please add a reviewer to the assignee section when you create a PR.
If you don't have the access to it, we will shortly find a reviewer and
assign them to your PR. -->

## 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

```Python
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:
```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
```Python
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

<!-- For example: "Closes ray-project#1234" -->

## 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: Philipp Moritz <pcmoritz@gmail.com>
Co-authored-by: pcmoritz <pcmoritz@anyscale.com>
Co-authored-by: angelinalg <122562471+angelinalg@users.noreply.github.com>
park12sj pushed a commit to park12sj/ray that referenced this pull request Mar 18, 2025
…ray-project#50462)

<!-- Thank you for your contribution! Please review
https://github.com/ray-project/ray/blob/master/CONTRIBUTING.rst before
opening a pull request. -->

<!-- Please add a reviewer to the assignee section when you create a PR.
If you don't have the access to it, we will shortly find a reviewer and
assign them to your PR. -->

## Why are these changes needed?

Next step after ray-project#50160 to make it
more convenient to use UV with Ray.

This is a useful runtime environment hook for mirroring the environment
of `uv run` to the workers (currently the args to uv run and the
working_dir). This is useful because it will allow people to intuitively
use `uv run` in a distributed application with the same behavior as for
a single python process.

This only modifies the environment if the driver was run with `uv run`
and could conceivably become the default for drivers run with uv run.

This is currently a developer API as implied by the fact that it is in
the `_private` namespace. It is currently for experimentation and can
needs to be opted in via

```shell
export RAY_RUNTIME_ENV_HOOK=ray._private.runtime_env.uv_runtime_env_hook.hook
```

If it works well, we might make it the default in the `uv run` case.

## Related issue number

<!-- For example: "Closes ray-project#1234" -->

## 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: Philipp Moritz <pcmoritz@gmail.com>
Co-authored-by: Edward Oakes <ed.nmi.oakes@gmail.com>
Co-authored-by: angelinalg <122562471+angelinalg@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
community-backlog go add ONLY when ready to merge, run all tests
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants