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

[no_early_kickoff] Make sure all public APIs will auto-init ray #34730

Merged
merged 23 commits into from
May 3, 2023

Conversation

raulchen
Copy link
Contributor

@raulchen raulchen commented Apr 24, 2023

Why are these changes needed?

  • Fix the issue that get_runtime_context won't auto-init ray.
  • Make sure all public APIs will auto-init ray, by decorating all functions in __all__ of ray/__init__.py.
  • Decouple auto-init with client mode.

Related issue number

Fixes #34631

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

@raulchen raulchen requested a review from ericl April 24, 2023 22:18
Signed-off-by: Hao Chen <chenh1024@gmail.com>
@pcmoritz
Copy link
Contributor

Nice!

Copy link
Contributor

@ericl ericl left a comment

Choose a reason for hiding this comment

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

Cool. Consider adding a unit tests / automated checks for the symbols exposed in init as you mentioned earlier.

Btw, our convention is to "assign" reviewers instead of "request reviewers". This is because assignees show up persistently in github.com/pulls, but review requests sometimes appear and disappear so it's not a great way to track what PRs you're supposed to review.

@ericl ericl self-assigned this Apr 24, 2023
Signed-off-by: Hao Chen <chenh1024@gmail.com>
@raulchen raulchen changed the title Make get_runtime_context auto-init ray Make sure all public APIs will auto-init ray Apr 25, 2023
@raulchen
Copy link
Contributor Author

@pcmoritz @ericl I just reimplemented the code and make sure all APIs are wrapped. Do you want to take a look again?

@@ -25,7 +26,8 @@
_filesystem = None


@client_mode_hook(auto_init=True)
@wrap_auto_init
Copy link
Contributor Author

@raulchen raulchen Apr 25, 2023

Choose a reason for hiding this comment

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

This api (along with get_client and list_named_actors) isn't part of __init__.py:__all__.
Not sure if they should be there. I didn't move them to __all__, but just added a standalone wrapper there.

Copy link
Contributor

Choose a reason for hiding this comment

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

Sounds good. They are not public APIs yet, but the plan is to eventually get them there.

@pcmoritz
Copy link
Contributor

pcmoritz commented Apr 25, 2023

If you want to auto-wrap the APIs, would it be better to have a separate list? Something like

AUTO_INIT_RAY_APIS = [
...
]

wrap_auto_init_for_all_apis(AUTO_INIT_RAY_APIS)

__all__ += AUTO_INIT_RAY_APIS

We probably don't want things like ObjectID to auto-init (which I think your change is doing?), what do you think?

@raulchen
Copy link
Contributor Author

@pcmoritz that makes sense. Currently I avoid ObjectID by only only wrapping function objects.

@ericl ericl added the @author-action-required The PR author is responsible for the next step. Remove tag to send back to the reviewer. label Apr 25, 2023
Signed-off-by: Hao Chen <chenh1024@gmail.com>
Copy link
Contributor

@pcmoritz pcmoritz left a comment

Choose a reason for hiding this comment

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

The new scheme makes sense I think.

I do enourage you to put it into ray/__init__.py like

AUTO_INIT_APIS = [
    "cancel",
    "get",
    "get_actor",
    "get_gpu_ids",
    "get_runtime_context",
    "kill",
    "put",
    "wait",
]

wrap_auto_init_for_apis(AUTO_INIT_APIS)

since that makes it a little more discoverable for adding new APIs :)

Signed-off-by: Hao Chen <chenh1024@gmail.com>
Signed-off-by: Hao Chen <chenh1024@gmail.com>
Signed-off-by: Hao Chen <chenh1024@gmail.com>
Signed-off-by: Hao Chen <chenh1024@gmail.com>
"kill",
"put",
"wait",
]
Copy link
Contributor

Choose a reason for hiding this comment

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

Hmm, I think it's actually a bug that cluster_resources / available_resources isn't enabled in auto init. To make sure folks don't forgot one or the other, how about we make this explicit, and have:

AUTO_INIT_APIS = [...]
NO_AUTO_INIT_APIS = [...]

And raise an error if there is some API that is not in one of these lists?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

How can we collect the full list of all APIs? I checked @PublicAPI. There are too many. And most of them are not Ray core APIs.

I think it's actually a bug that cluster_resources / available_resources isn't enabled in auto init.

Which bug do you refer to? The bug reported in #34631 is because get_runtime_context doesn't auto init. "cluster_resources / available_resources" still don't auto init. Not sure whether they should.

Copy link
Contributor

Choose a reason for hiding this comment

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

To clarify, I mean the previous list of APIs in "all", the list of 20 or so things including ObjectID.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

sounds good. Refactored the "init.py" file. do you want to take a another look?

Signed-off-by: Hao Chen <chenh1024@gmail.com>
Signed-off-by: Hao Chen <chenh1024@gmail.com>
@ericl
Copy link
Contributor

ericl commented May 1, 2023

TypeError: client_mode_hook() missing 1 required keyword-only argument: 'auto_init'

There are a number of tests failing with this currently.

Signed-off-by: Hao Chen <chenh1024@gmail.com>
@raulchen raulchen changed the title Make sure all public APIs will auto-init ray [no_early_kickoff] Make sure all public APIs will auto-init ray May 1, 2023
raulchen added 9 commits May 1, 2023 12:01
Signed-off-by: Hao Chen <chenh1024@gmail.com>
Signed-off-by: Hao Chen <chenh1024@gmail.com>
Signed-off-by: Hao Chen <chenh1024@gmail.com>
Signed-off-by: Hao Chen <chenh1024@gmail.com>
Signed-off-by: Hao Chen <chenh1024@gmail.com>
Signed-off-by: Hao Chen <chenh1024@gmail.com>
Signed-off-by: Hao Chen <chenh1024@gmail.com>
@raulchen
Copy link
Contributor Author

raulchen commented May 3, 2023

It turns out that we cannot simply auto init get_runtime_context. Because it may be called on the dashboard. I wrapped the data read api with auto init instead to fix the issue.

@raulchen raulchen merged commit 3a6d2a0 into ray-project:master May 3, 2023
@raulchen raulchen deleted the auto-init branch May 3, 2023 17:03
architkulkarni pushed a commit to architkulkarni/ray that referenced this pull request May 16, 2023
- Fix the issue that `get_runtime_context` won't auto-init ray.
- Make sure all public APIs will auto-init ray, by decorating all functions in `__all__` of `ray/__init__.py`.
- Decouple auto-init with client mode.
@messense messense mentioned this pull request Jun 9, 2023
raulchen added a commit that referenced this pull request Jun 12, 2023
…mote" (#36334)

#34730 changed `__all__` in `__init__.py` to a computed list. mypy doesn't support this. Reverting it back to a literal list to fix this issue.

Repro:
`mypy --strict --follow-imports=skip --ignore-missing-imports 1.py`

```python
# 1.py
import ray

@ray.remote
def foo() -> None:
    pass
```

Note, the reason why CI didn't catch this issue is because we don't enable strict mode, see [here](https://github.com/ray-project/ray/blob/407062499038344b0f3edb54b2c7985c3320d1ec/ci/lint/format.sh#L135). Currently we have too many issues if enabling strict mode. 

Signed-off-by: Hao Chen <chenh1024@gmail.com>
raulchen added a commit to raulchen/ray that referenced this pull request Jun 12, 2023
…mote" (ray-project#36334)

ray-project#34730 changed `__all__` in `__init__.py` to a computed list. mypy doesn't support this. Reverting it back to a literal list to fix this issue.

Repro:
`mypy --strict --follow-imports=skip --ignore-missing-imports 1.py`

```python
# 1.py
import ray

@ray.remote
def foo() -> None:
    pass
```

Note, the reason why CI didn't catch this issue is because we don't enable strict mode, see [here](https://github.com/ray-project/ray/blob/407062499038344b0f3edb54b2c7985c3320d1ec/ci/lint/format.sh#L135). Currently we have too many issues if enabling strict mode. 

Signed-off-by: Hao Chen <chenh1024@gmail.com>
can-anyscale pushed a commit that referenced this pull request Jun 13, 2023
…mote" (#36334) (#36356)

#34730 changed `__all__` in `__init__.py` to a computed list. mypy doesn't support this. Reverting it back to a literal list to fix this issue.

Repro:
`mypy --strict --follow-imports=skip --ignore-missing-imports 1.py`

```python
# 1.py
import ray

@ray.remote
def foo() -> None:
    pass
```

Note, the reason why CI didn't catch this issue is because we don't enable strict mode, see [here](https://github.com/ray-project/ray/blob/407062499038344b0f3edb54b2c7985c3320d1ec/ci/lint/format.sh#L135). Currently we have too many issues if enabling strict mode.

Signed-off-by: Hao Chen <chenh1024@gmail.com>
arvind-chandra pushed a commit to lmco/ray that referenced this pull request Aug 31, 2023
…mote" (ray-project#36334)

ray-project#34730 changed `__all__` in `__init__.py` to a computed list. mypy doesn't support this. Reverting it back to a literal list to fix this issue.

Repro:
`mypy --strict --follow-imports=skip --ignore-missing-imports 1.py`

```python
# 1.py
import ray

@ray.remote
def foo() -> None:
    pass
```

Note, the reason why CI didn't catch this issue is because we don't enable strict mode, see [here](https://github.com/ray-project/ray/blob/407062499038344b0f3edb54b2c7985c3320d1ec/ci/lint/format.sh#L135). Currently we have too many issues if enabling strict mode.

Signed-off-by: Hao Chen <chenh1024@gmail.com>
Signed-off-by: e428265 <arvind.chandramouli@lmco.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
@author-action-required The PR author is responsible for the next step. Remove tag to send back to the reviewer.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Data] Local read throws exception if Ray cluster is not initialized
3 participants