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

Exposes ray init functionality #597

Merged
merged 2 commits into from
Dec 20, 2023
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 17 additions & 4 deletions hamilton/plugins/h_ray.py
Original file line number Diff line number Diff line change
Expand Up @@ -209,20 +209,33 @@ class RayTaskExecutor(executors.TaskExecutor):
This is still experimental, so the API might change.
"""

def __init__(self, num_cpus: int):
def __init__(
self,
num_cpus: int = None,
skrawcz marked this conversation as resolved.
Show resolved Hide resolved
config: typing.Dict[str, typing.Any] = None,
skrawcz marked this conversation as resolved.
Show resolved Hide resolved
skip_init: bool = False,
):
"""Creates a ray task executor. Note this will likely take in more parameters. This is
experimental, so the API will likely change, although we will do our best to make it
backwards compatible.

:param num_cpus: Number of cores to use for initialization, passed drirectly to ray.init
:param num_cpus: Number of cores to use for initialization, passed directly to ray.init. Defaults to all cores.
:param config: General configuration to pass to ray.init. Defaults to None.
:param skip_init: Skips ray init if you already have Ray initialized. Default is False.
"""
self.num_cpus = num_cpus
self.config = config if config else {}
self.skip_init = skip_init

def init(self):
ray.init(num_cpus=self.num_cpus)
if not self.skip_init:
ray.init(num_cpus=self.num_cpus, **self.config)

def finalize(self):
ray.shutdown()
if (
not self.skip_init
): # we assume that if we didn't init it, we don't need to shutdown either.
ray.shutdown()

def submit_task(self, task: TaskImplementation) -> TaskFuture:
"""Submits a task, wrapping it in a TaskFuture (after getting the corresponding python
Expand Down