Skip to content
This repository has been archived by the owner on Apr 26, 2024. It is now read-only.

Fix ray remote options #56

Merged
merged 6 commits into from
Nov 1, 2022
Merged

Conversation

pcmoritz
Copy link
Contributor

@pcmoritz pcmoritz commented Nov 1, 2022

This PR fixes the prefect_ray.remote_options feature. Without this fix, it is possible to get an error of the form

AssertionError: The @ray.remote decorator must be applied either with no arguments and no parentheses, for example '@ray.remote', or it must be applied using some of the arguments in the list ['max_calls', 'max_retries', 'num_cpus', 'num_returns', 'object_store_memory', 'retry_exceptions', 'concurrency_groups', 'lifetime', 'max_concurrency', 'max_restarts', 'max_task_retries', 'max_pending_calls', 'namespace', 'get_if_exists', 'accelerator_type', 'memory', 'name', 'num_gpus', 'placement_group', 'placement_group_bundle_index', 'placement_group_capture_child_tasks', 'resources', 'runtime_env', 'scheduling_strategy', '_metadata'], for example '@ray.remote(num_returns=2, resources={"CustomResource": 1})'.

Closes #

Example

Checklist

  • This pull request references any related issue by including "Closes #<ISSUE_NUMBER>"
    • If no issue exists and your change is not a small fix, please create an issue first.
  • This pull request includes tests or only affects documentation.
  • Summarized PR's changes in CHANGELOG.md

@ahuang11
Copy link
Contributor

ahuang11 commented Nov 1, 2022

Curious when does the error happen? Would it be possible to replicate it in a test?

Also, to fix static analysis: pre-commit install && pre-commit run --all

@pcmoritz
Copy link
Contributor Author

pcmoritz commented Nov 1, 2022

This actually happens if you just run the example in the README:

In [1]: from prefect import flow, task
   ...: from prefect_ray.task_runners import RayTaskRunner
   ...: from prefect_ray.context import remote_options
   ...: 
   ...: @task
   ...: def process(x):
   ...:     return x + 1
   ...: 
   ...: 
   ...: @flow(task_runner=RayTaskRunner())
   ...: def my_flow():
   ...:     # equivalent to setting @ray.remote(num_cpus=4, num_gpus=2)
   ...:     with remote_options(num_cpus=4, num_gpus=2):
   ...:         process.submit(42)
   ...: 

In [2]: my_flow()

Happy to add a test if you point me to where it should be added.

@pcmoritz
Copy link
Contributor Author

pcmoritz commented Nov 1, 2022

I guess adding it in https://github.com/PrefectHQ/prefect-ray/blob/main/tests/test_task_runners.py should be fine? I'll give that a shot :)

@ahuang11
Copy link
Contributor

ahuang11 commented Nov 1, 2022

Thanks! Can you add it under test_task_runners:
https://github.com/PrefectHQ/prefect-ray/blob/main/tests/test_task_runners.py#L232

It can literally be that example.

@ahuang11
Copy link
Contributor

ahuang11 commented Nov 1, 2022

On second thought, maybe we should lower the number of CPUs and remove the number of GPUs requested in the test.

@pcmoritz
Copy link
Contributor Author

pcmoritz commented Nov 1, 2022

Yes, happy to do that :)

I can also use the config that made me run into this -- max_calls, it won't require changes to the CPUs or GPUs :)

@pcmoritz
Copy link
Contributor Author

pcmoritz commented Nov 1, 2022

Btw, is it possible to do a new release that includes this fix? Or if that's too disruptive, cut a release candidate with it so it can be installed with --pre? I'd like to get this to somebody ASAP :)

@ahuang11
Copy link
Contributor

ahuang11 commented Nov 1, 2022

Yes I think we might be able to release tomorrow to fix this.

Copy link
Member

@desertaxle desertaxle left a comment

Choose a reason for hiding this comment

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

LGTM!

@ahuang11 ahuang11 merged commit 5e6521e into PrefectHQ:main Nov 1, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants