Skip to content

[runtime env] redefine runtime env to protobuf - #19511

Merged
raulchen merged 58 commits into
ray-project:masterfrom
antgroup:dev_runtime_env_pb
Nov 20, 2021
Merged

raulchen merged 58 commits into
ray-project:masterfrom
antgroup:dev_runtime_env_pb

Conversation

@SongGuyang

@SongGuyang SongGuyang commented Oct 19, 2021 •

Copy link
Copy Markdown
Contributor

Why are these changes needed?

In current PR:

  • We redefine the runtime env to a protobuf structure.
  • Every language worker should serialize the runtime env of users to this common protobuf structure.
  • Runtime env agent will parse the protobuf and install the typed runtime env, E.g. conda, pip,contianer.
  • We also has a PluginRuntimeEnv type to support the pluggability.

After this refector, we can get some benefits:

  • Using protobuf, we can get a clear relationship between different runtime env type. For example, we can't set conda and container at the same time. So we use a oneof type in protobuf.
  • Easy to share common codes between different language workers. For example, we need to override the actor level runtime env by job level runtime env. We move this logic from python worker to core worker in current PR. So we don't need to implement this in Java and C++ worker.
  • Easy to support cross-language. If we want to create an python actor in Java, we need to align the interface of Java with Python. Now, we can unify the structure by protobuf.

Future work:

  • Do we need to give user a runtime env structure, instead of Dict or json. For example:
runtime_env = RuntimeEnv(working_dir=".", pip=["requests"])
ray.init(runtime_env=runtime_env)

Related issue number

#19447

@SongGuyang

Copy link
Copy Markdown
Contributor Author

@architkulkarni

Copy link
Copy Markdown
Contributor

The protobuf looks good to me. I guess now any custom plugin needs to have a config that's serializable to map<string, string>, but that doesn't sound too restrictive, so it should be okay.

Comment thread src/ray/protobuf/common.proto Outdated
Comment on lines +157 to +163
message PipRuntimeEnv {
/// A list of pip packages, such as ["redis >= 3.5.0", "numpy"].
repeated string config = 1;
/// The path to a pip requirements.txt file.
string config_file_path = 2;
/// The name of a local virtual env.
string virtual_env_name = 3;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Should this also be oneof? Or are we leaving these all in to allow for the future possibility of combining these options (for example, specifying a virtual env together with a list of additional packages to install)? I'm not sure what the best practice is here

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Yep, I think we can make it to be oneof. And the CondaRuntimeEnv should be oneof as well.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

The pb has been updated.

@edoakes

edoakes commented Oct 22, 2021

Copy link
Copy Markdown
Collaborator

@SongGuyang sorry for the delay, will review tmrw.

@edoakes

edoakes commented Oct 22, 2021

Copy link
Copy Markdown
Collaborator

@SongGuyang I don't think we can assume that plugins will use map<str,str> as their value, that seems restrictive to me. What if we just serialize those options as pure JSON and pass them through instead?

We will also need some way to pass URIs for those options as well.

I'm also generally a little worried that this is adding complexity without clear value, given that language frontends can just serialize things to JSON already.

@SongGuyang

Copy link
Copy Markdown
Contributor Author

@edoakes make sense. We can use a single string to represent a common plugin, instead of map.

About "We will also need some way to pass URIs for those options as well.", do you mean that the plugin could append some uris to the uris field of RuntimeEnv protobuf? Do you have a case about this? Or you can say some details.

@edoakes

edoakes commented Oct 25, 2021

Copy link
Copy Markdown
Collaborator

@SongGuyang that's right, plugins should be able to use the caching/GC setup too, so they'll need to be able to pass URIs (see https://docs.google.com/document/d/1x1JAHg7c0ewcOYwhhclbuW0B0UC7l92WFkF4Su0T-dk/edit#heading=h.rcrah72c195t)

@edoakes

edoakes commented Oct 25, 2021

Copy link
Copy Markdown
Collaborator

@SongGuyang kind of a crazy idea: what if instead of moving this to protobuf we just had the core worker call back into Python to do validation on the JSON string?

@SongGuyang

Copy link
Copy Markdown
Contributor Author

@edoakes I found a issue in my implementation. I ran the test case python/ray/tests/test_actor.py::test_remote_function_within_actor and a except about pickle was raised:
image

It seems protobuf can not be pickled. Do you know how to fix this? The actor class depends on protobuf indirectly after my refector.

@SongGuyang

Copy link
Copy Markdown
Contributor Author

@fyrestone has helped solve the pickle issue f01d09d.

@SongGuyang

Copy link
Copy Markdown
Contributor Author

@edoakes @architkulkarni Do you have any other comments? We plan to merge current PR this week. cc @raulchen

@architkulkarni architkulkarni left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

This looks good to me. I think we would prefer to have the overriding logic in Python rather than C++, but like you said in the PR description, in order for it to work for all languages it needs to be in the CoreWorker, so it has to be in C++.

Does it make sense to add unit tests for the new code in core_worker.cc?

Also, now OverrideTaskOrActorRuntimeEnv is duplicated, appearing both in C++ and in Python (override_task_or_actor_runtime_env in validation.py). Is it feasible to unify them somehow so there's a single code path?

@architkulkarni

Copy link
Copy Markdown
Contributor

The linter is failing with python/ray/_private/runtime_env/utils.py:165:27: C409 Unnecessary list passed to tuple() - rewrite as a tuple literal.

import ray.dashboard.optional_deps # noqa: F401
except ImportError:
if require_dashboard:
logger.exception("dashboard dependency error")

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

What's the context for adding this? Does the ImportError on the line below not show up in some cases?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

If I don't log this, I can't see which package import error.

@SongGuyang

Copy link
Copy Markdown
Contributor Author

@architkulkarni Yep, I can remove this function in python and add some test cases in C++.

For long term, I'm thinking that can we do this override logic in runtime env agent?But we need to do a refacter. In this way, the runtime env and hash will be generated by agent with installng. I'm not sure about that.

for plugin_class_path in runtime_env.get("plugins", {}).keys():
for plugin_class_path, config in runtime_env.plugins():
logger.debug(
f"Run setup function of plugin {plugin_class_path}")

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Setting up RuntimeEnv plugin {...}

else:
return runtime_env_agent_pb2.DeleteURIsReply(
status=agent_manager_pb2.AGENT_RPC_STATUS_OK)
if failed_uris:

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Is this change intended? Why move this if statement out of the for loop?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Yep, I think here is a bug before. We need to reply the rpc after getting all the failed uris.

Comment thread src/ray/core_worker/context.cc Outdated
// never see a new one.
serialized_runtime_env_ = task_spec.SerializedRuntimeEnv();
if (!serialized_runtime_env_.serialized_runtime_env().empty()) {
RAY_LOG(INFO) << "serialized_runtime_env_.serialized_runtime_env() "

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

this is for debugging?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Let me remove this.

@raulchen
raulchen merged commit ad56b9b into ray-project:master Nov 20, 2021
@jovany-wang
jovany-wang deleted the dev_runtime_env_pb branch November 21, 2021 01:11
wuisawesome added a commit that referenced this pull request Nov 22, 2021
wuisawesome pushed a commit that referenced this pull request Nov 22, 2021
@SongGuyang SongGuyang mentioned this pull request Nov 23, 2021
1 of 2 tasks
elliot-barn added a commit that referenced this pull request Sep 3, 2026
… outage (#65880)

## Why this change is needed

`data.pyg.org`, the PyG wheel index that every ML/data/rllib depset
declares via `--find-links`, has been a dangling CNAME since 2026-09-02:
it points at `d28mro9bmx3ky3.cloudfront.net`, and that CloudFront
distribution returns `NOERROR` with zero answers from 8.8.8.8, 1.1.1.1
and 9.9.9.9. Upstream is tracking it at pyg-team/pyg-lib#719 and has
said they are working on it with urgency; as of their last update there
is no ETA.

uv fails eagerly on an unreadable `--find-links` URL before deciding
whether it needs anything from it, so `raydepsets build --all-configs
--check` is red on every run regardless of the PR's contents:

| Pipeline | Build | Time (UTC) | Result |
|---|---|---|---|
| postmerge | #19487 | Sep 2 05:05 | passed (last good) |
| postmerge | #19498 | Sep 2 15:28 | pyg DNS |
| postmerge | #19501 | Sep 2 16:09 | pyg DNS |
| postmerge | #19507 | Sep 2 20:06 | pyg DNS |
| postmerge | #19511 | Sep 3 00:05 | pyg DNS |
| premerge | #72711, #72712 | Sep 2 | pyg DNS |

Every run since ~15:30Z Sep 2 has failed. It blocks every
`python_dependencies`-tagged PR and paints master red.

The `pip-compile dependencies` step is **not** affected and is left
alone: pip treats an unreachable find-links as a warning, PyPI's sdist
satisfies `torch-scatter==2.1.2`, and since `requirements_compiled.txt`
pins without the `+pt29cpu` local version the output is byte-identical.
It passed in all six of the builds above where raydepsets failed, so it
keeps guarding `requirements_compiled.txt`.

## What changes

`soft_fail: true` on the `raydepsets: compile all dependencies` step,
with a comment recording why and when to remove it.

`soft_fail` rather than removing the step: the job still runs and
reports, so it turns green on its own when upstream restores the record,
and reviewers can still see lock drift in its output in the meantime.
There's precedent for this pattern in `lint.rayci.yml`
(`api-param-coverage`).

## What this does not fix

- **Image builds.** 32 deplocks carry the find-links line, so any wanda
image build that misses cache fails at `pip install` inside the
Dockerfile (#72719 lost `docgpubuild-py3.10` and `mlgpubuild-py3.10`
this way). Most PRs are unaffected because unchanged inputs reuse the
cached image. Nothing CI-side fixes this without hosting the wheels
somewhere else, which is a separate change.
- **Lock regeneration.** A PR that needs a new deplock still can't
produce one until the index is back, since the recompile itself reads
the find-links.

## Cost

While this is in, a PR that edits a requirements file without
regenerating its lock can merge. The pip-compile guard still covers
`requirements_compiled.txt`, and the window should be short.

## Revert when

`raydepsets: compile all dependencies` is green on a master postmerge
build. Track pyg-team/pyg-lib#719.

Signed-off-by: elliot-barn <[email protected]>
nadongjun pushed a commit to nadongjun/ray that referenced this pull request Oct 6, 2026
… outage (ray-project#65880)

## Why this change is needed

`data.pyg.org`, the PyG wheel index that every ML/data/rllib depset
declares via `--find-links`, has been a dangling CNAME since 2026-09-02:
it points at `d28mro9bmx3ky3.cloudfront.net`, and that CloudFront
distribution returns `NOERROR` with zero answers from 8.8.8.8, 1.1.1.1
and 9.9.9.9. Upstream is tracking it at pyg-team/pyg-lib#719 and has
said they are working on it with urgency; as of their last update there
is no ETA.

uv fails eagerly on an unreadable `--find-links` URL before deciding
whether it needs anything from it, so `raydepsets build --all-configs
--check` is red on every run regardless of the PR's contents:

| Pipeline | Build | Time (UTC) | Result |
|---|---|---|---|
| postmerge | ray-project#19487 | Sep 2 05:05 | passed (last good) |
| postmerge | ray-project#19498 | Sep 2 15:28 | pyg DNS |
| postmerge | ray-project#19501 | Sep 2 16:09 | pyg DNS |
| postmerge | ray-project#19507 | Sep 2 20:06 | pyg DNS |
| postmerge | ray-project#19511 | Sep 3 00:05 | pyg DNS |
| premerge | #72711, #72712 | Sep 2 | pyg DNS |

Every run since ~15:30Z Sep 2 has failed. It blocks every
`python_dependencies`-tagged PR and paints master red.

The `pip-compile dependencies` step is **not** affected and is left
alone: pip treats an unreachable find-links as a warning, PyPI's sdist
satisfies `torch-scatter==2.1.2`, and since `requirements_compiled.txt`
pins without the `+pt29cpu` local version the output is byte-identical.
It passed in all six of the builds above where raydepsets failed, so it
keeps guarding `requirements_compiled.txt`.

## What changes

`soft_fail: true` on the `raydepsets: compile all dependencies` step,
with a comment recording why and when to remove it.

`soft_fail` rather than removing the step: the job still runs and
reports, so it turns green on its own when upstream restores the record,
and reviewers can still see lock drift in its output in the meantime.
There's precedent for this pattern in `lint.rayci.yml`
(`api-param-coverage`).

## What this does not fix

- **Image builds.** 32 deplocks carry the find-links line, so any wanda
image build that misses cache fails at `pip install` inside the
Dockerfile (#72719 lost `docgpubuild-py3.10` and `mlgpubuild-py3.10`
this way). Most PRs are unaffected because unchanged inputs reuse the
cached image. Nothing CI-side fixes this without hosting the wheels
somewhere else, which is a separate change.
- **Lock regeneration.** A PR that needs a new deplock still can't
produce one until the index is back, since the recompile itself reads
the find-links.

## Cost

While this is in, a PR that edits a requirements file without
regenerating its lock can merge. The pip-compile guard still covers
`requirements_compiled.txt`, and the window should be short.

## Revert when

`raydepsets: compile all dependencies` is green on a master postmerge
build. Track pyg-team/pyg-lib#719.

Signed-off-by: elliot-barn <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants