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

[Ray component: Core] Runtime Envs should support package installation with uv #47819

Closed
colinjc opened this issue Sep 25, 2024 · 21 comments
Closed
Assignees
Labels
core Issues that should be addressed in Ray Core core-runtime-env Issues related to Ray environment dependencies enhancement Request for new feature and/or capability P0 Issues that should be fixed in short order

Comments

@colinjc
Copy link

colinjc commented Sep 25, 2024

Description

uv is a vastly faster at installing Python packages than Conda and Pip, so Ray should enable using it when defining runtime envs.

uv has two interfaces, which would be nice to support separately -

The uv pip interface is nearly drop-in compatible with pip with the exception of some outlier packages like jax[tpu], and would be nice to have as an option.

The uv sync interface is nicer, but would only really work by passing a pyproject.toml in as the argument much like runtime env's conda argument accepts a environment yaml path.

Use case

Runtime env creation now is quite slow. Having uv support would really improve the ux of iterating changes to a runtime env.

@colinjc colinjc added enhancement Request for new feature and/or capability triage Needs triage (eg: priority, bug/not-bug, and owning component) labels Sep 25, 2024
@anyscalesam anyscalesam added the core Issues that should be addressed in Ray Core label Oct 4, 2024
@jjyao jjyao added core-runtime-env Issues related to Ray environment dependencies P2 Important issue, but not time-critical and removed triage Needs triage (eg: priority, bug/not-bug, and owning component) labels Oct 7, 2024
@jjyao
Copy link
Collaborator

jjyao commented Oct 7, 2024

We will pick it up if there is enough demand from OSS users.

@danielgafni
Copy link

Sounds like this would be really really great to have!

uv installations from are 10-100x faster in my experience (especially from cache) so should really improve UX for heavy runtime environments like torch

@dbuades
Copy link

dbuades commented Oct 24, 2024

I agree that this would be great. We have moved from poetry to uv recently and the difference is staggering.

@jjyao jjyao added P0 Issues that should be fixed in short order and removed P2 Important issue, but not time-critical labels Oct 29, 2024
@jjyao jjyao assigned rynewang and unassigned rynewang Oct 29, 2024
@jjyao
Copy link
Collaborator

jjyao commented Oct 29, 2024

cc @dentiny

@chainlink
Copy link

We've seen a huge increase in speed with uv and would love to see it as an option in Ray

@rynewang
Copy link
Contributor

Hi all, does this interface look reasonable to you?

runtime_env = {"pip": {"uv_version": "==0.1.1", "packages":["tensorflow", "requests"], "pip_check": False}}

Note the uv_version field in pip. If it's set, we use uv instead of pip. uv_version and pip_version can not both exist.

@jjyao
Copy link
Collaborator

jjyao commented Oct 30, 2024

What about we completely separate pip plugin and uv plugin:

runtime_env = {"uv": {"uv_version": "==0.1.1", "packages":["tensorflow", "requests"], "pip_check": False}}

pip_version is invalid in uv runtime env plugin.

@dentiny
Copy link
Contributor

dentiny commented Oct 30, 2024

What about we completely separate pip plugin and uv plugin:

@jjyao I think interface wise it makes sense, but implementation wise we would have quite a few duplicate code between pip vs uv.
My PR (#48457) attempts to do least code change as possible.

uv could be a subset of pip, one justification is, the command for uv to install packages is pip uv install.

@jjyao
Copy link
Collaborator

jjyao commented Oct 30, 2024

We can have an implementation that share code between these two plugins.

uv doesn't use pip, it just provides a pip like interface. I feel it's cleaner to explicitly separate them and this also gives us flexibility to support uv specific options in the future.

cc @pcmoritz for API discussion.

@danielgafni
Copy link

I think it would be best if Ray did both:

  1. Use uv instead of pip with the current {"runtime_env": {"pip": ...}} interface. This should be enabled by default. We can make a flag to disable uv in this interface just in case something goes wrong. This interface won't take any uv-specific parameters. This would immediately improve installation times for all Ray users.
  2. Add a new {"runtime_env": {"uv": ...}} interface which would mostly share the same code but also will be able to take some new uv-specific parameters.

@dentiny
Copy link
Contributor

dentiny commented Oct 31, 2024

Hi I think we have multiple available solutions, just a brief summaries:

  1. uv has higher priority than pip, with no user interface changed
    1.1 Option-1: automatically use uv when installed, detect whether uv exists in environment, prefer uv if already installed, otherwise fallback to pip; no user side change needed
    1.2 Option-2: install and use uv in all cases

If pip_version version specified, which means users do have an intention to prefer pip, we will respect and no uv checked in at certain case.

  1. Use uv as a subcommand for pip and install uv when specified.
    Within runtime env, we expect new spec like (1) uv_version, which assigns a detailed uv to use; or (2) use_uv, which means users don't have a requirement on version, so latest version would be installed.

The interface would look pretty similar to what we have for pip command, which looks like

runtime_env = {"pip": {"uv_version": "==0.1.1", "packages":["tensorflow", "requests"], "pip_check": False}}

uv is only selected when explicitly specified.

  1. Make uv a new command as a counterpart of pip, which looks similar to how we use pip/conda nowadays
runtime_env = {"uv": {"uv_version": "==0.1.1", "packages":["tensorflow", "requests"]}}

In rollout phase, one thing we could do to reduce risk is allow fallback to pip when package installation via uv fails.

@rynewang
Copy link
Contributor

I feel silently changing implementations behind pip is so risky. Rather it's good to make uv opt-in, by either a "uv" plugin, or a pip.uv_version key.

@rynewang
Copy link
Contributor

And no, we don't want the behavior to depend on "if uv exists on this machine". If we want uv and it does not exist we need to fail instead of falling back to pip.

@jjyao
Copy link
Collaborator

jjyao commented Oct 31, 2024

@colinjc @dbuades @chainlink any feedbacks on the above API proposals?

@colinjc
Copy link
Author

colinjc commented Oct 31, 2024

I agree that swapping pip to uv blindly is very risky. They're not as 1:1 compatible as you would think, a lot of code would break due to the stricter constraint checking.

In the Ray docs it's mentioned that pip installs into the existing , while conda creates an isolated one. Which approach will the uv env implement?

runtime_env = {"uv": {"uv_version": "==0.1.1", "packages":["tensorflow", "requests"]}}

I would make it more explicit that this is the uv pip interface, in case there's interest in adding uv sync support later.

Or support both in the same interface?

{"uv": 
  {"version": "==0.1.1", "pip_packages": ["tensorflow"], "pyproject": "/path/to/pyproject.toml"}
}

@dbuades
Copy link

dbuades commented Nov 5, 2024

I agree that swapping pip to uv blindly is very risky. They're not as 1:1 compatible as you would think, a lot of code would break due to the stricter constraint checking.

In the Ray docs it's mentioned that pip installs into the existing , while conda creates an isolated one. Which approach will the uv env implement?


runtime_env = {"uv": {"uv_version": "==0.1.1", "packages":["tensorflow", "requests"]}}

I would make it more explicit that this is the uv pip interface, in case there's interest in adding uv sync support later.

Or support both in the same interface?


{"uv": 

  {"version": "==0.1.1", "pip_packages": ["tensorflow"], "pyproject": "/path/to/pyproject.toml"}

}

Support for installing packages with uv sync with the uv.lock file would be great, since we wouldn't need to export a requirements.txt anymore and we would be sure that the exact project dependencies are installed.

@dentiny
Copy link
Contributor

dentiny commented Nov 5, 2024

I would make it more explicit that this is the uv pip interface, in case there's interest in adding uv sync support later.

Sounds good.

@danielgafni
Copy link

Support for installing packages with uv sync with the uv.lock file would be great, since we wouldn't need to export a requirements.txt anymore and we would be sure that the exact project dependencies are installed.

This really sounds like it should be a build step (in CI) instead. Curious to know why would you need to swap lock files at runtime?

@sfriedowitz
Copy link

This would be a HUGE improvement for us. Runtime env installation is slow for our use cases, and UV is significantly faster than standard pip installs. Would greatly appreciate if this feature is implemented soon.

@dentiny
Copy link
Contributor

dentiny commented Nov 10, 2024

Hi community, I'm working on runtime env setup with uv;
As the first milestone, I target at existing features for pip;
Let me know if you have any other feature requested specifically for uv.

@jjyao jjyao added P0 Issues that should be fixed in short order and removed P0 Issues that should be fixed in short order labels Nov 18, 2024
@jjyao jjyao closed this as completed Nov 18, 2024
@dbuades
Copy link

dbuades commented Dec 23, 2024

Support for installing packages with uv sync with the uv.lock file would be great, since we wouldn't need to export a requirements.txt anymore and we would be sure that the exact project dependencies are installed.

This really sounds like it should be a build step (in CI) instead. Curious to know why would you need to swap lock files at runtime?

Sorry for the delayed response, I was playing with Ray and uv today and came back to this thread.

We already export the lock to a requirements.txt file in the CI. However, uv export doesn't add external indexes and, although there are manual workarounds to add it afterwards, it doesn't guarantee perfect compatibility. This comment in the uv repo explains the reasoning well.

I think the support for uv pip currently implemented in Ray works perfectly fine. Adding support for uv sync would just be a nice-to-have feature for the future.

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 core-runtime-env Issues related to Ray environment dependencies enhancement Request for new feature and/or capability P0 Issues that should be fixed in short order
Projects
None yet
Development

No branches or pull requests

9 participants