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

Expose ray gpu & memory options #267

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
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
14 changes: 13 additions & 1 deletion buildflow/core/app/flow.py
Original file line number Diff line number Diff line change
Expand Up @@ -309,6 +309,8 @@ def pipeline(
sink: Optional[Primitive] = None,
*,
num_cpus: float = 1.0,
num_gpus: Optional[float] = None,
memory: Optional[float] = None,
num_concurrency: int = 1,
autoscale_options: AutoscalerOptions = AutoscalerOptions.default(),
log_level: str = "INFO",
Expand All @@ -329,6 +331,8 @@ def pipeline(
sink_primitive=sink,
processor_options=ProcessorOptions(
num_cpus=num_cpus,
num_gpu=num_gpus,
memory=memory,
num_concurrency=num_concurrency,
log_level=log_level,
autoscaler_options=autoscale_options,
Expand All @@ -344,6 +348,8 @@ def collector(
sink: Optional[Primitive] = None,
*,
num_cpus: float = 1.0,
num_gpus: Optional[float] = None,
memory: Optional[float] = None,
autoscale_options: AutoscalerOptions = AutoscalerOptions.default(),
log_level: str = "INFO",
):
Expand All @@ -362,6 +368,8 @@ def collector(
sink_primitive=sink,
processor_options=ProcessorOptions(
num_cpus=num_cpus,
num_gpu=num_gpus,
memory=memory,
# Collectors always have a concurrency of 1
num_concurrency=1,
log_level=log_level,
Expand All @@ -376,6 +384,8 @@ def endpoint(
method: Method,
*,
num_cpus: float = 1.0,
num_gpus: Optional[float] = None,
memory: Optional[float] = None,
autoscale_options: AutoscalerOptions = AutoscalerOptions.default(),
log_level: str = "INFO",
):
Expand All @@ -384,7 +394,9 @@ def endpoint(
method=method,
processor_options=ProcessorOptions(
num_cpus=num_cpus,
# Collectors always have a concurrency of 1
num_gpu=num_gpus,
memory=memory,
# Endpoints always have a concurrency of 1
num_concurrency=1,
log_level=log_level,
autoscaler_options=autoscale_options,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,10 +78,19 @@
f"Method {self.processor.endpoint().method} is not supported "
"for collectors."
)

# Some ProcessorOptions fields are optional, so we need to filter out Nones
ray_actor_options = {

Check warning on line 83 in buildflow/core/app/runtime/actors/collector_pattern/receive_process_push_ack.py

View check run for this annotation

Codecov / codecov/patch

buildflow/core/app/runtime/actors/collector_pattern/receive_process_push_ack.py#L83

Added line #L83 was not covered by tests
"num_cpus": self.processor_options.num_cpus,
}
if self.processor_options.num_gpu is not None:
ray_actor_options["num_gpus"] = self.options.num_gpu
if self.processor_options.memory is not None:
ray_actor_options["memory"] = self.options.memory

Check warning on line 89 in buildflow/core/app/runtime/actors/collector_pattern/receive_process_push_ack.py

View check run for this annotation

Codecov / codecov/patch

buildflow/core/app/runtime/actors/collector_pattern/receive_process_push_ack.py#L86-L89

Added lines #L86 - L89 were not covered by tests

@serve.deployment(
route_prefix=self.endpoint.route,
ray_actor_options={"num_cpus": self.processor_options.num_cpus},
ray_actor_options=ray_actor_options,
autoscaling_config={
"min_replicas": self.processor_options.autoscaler_options.min_replicas,
"initial_replicas": self.processor_options.autoscaler_options.num_replicas, # noqa: E501
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,10 +76,19 @@
f"Method {self.processor.endpoint().method} is not supported "
"for endpoints."
)

# Some ProcessorOptions fields are optional, so we need to filter out Nones
ray_actor_options = {

Check warning on line 81 in buildflow/core/app/runtime/actors/endpoint_pattern/receive_process_respond.py

View check run for this annotation

Codecov / codecov/patch

buildflow/core/app/runtime/actors/endpoint_pattern/receive_process_respond.py#L81

Added line #L81 was not covered by tests
"num_cpus": self.processor_options.num_cpus,
}
if self.processor_options.num_gpu is not None:
ray_actor_options["num_gpus"] = self.options.num_gpu
if self.processor_options.memory is not None:
ray_actor_options["memory"] = self.options.memory

Check warning on line 87 in buildflow/core/app/runtime/actors/endpoint_pattern/receive_process_respond.py

View check run for this annotation

Codecov / codecov/patch

buildflow/core/app/runtime/actors/endpoint_pattern/receive_process_respond.py#L84-L87

Added lines #L84 - L87 were not covered by tests

@serve.deployment(
route_prefix=self.endpoint.route,
ray_actor_options={"num_cpus": self.processor_options.num_cpus},
ray_actor_options=ray_actor_options,
autoscaling_config={
"min_replicas": self.processor_options.autoscaler_options.min_replicas,
"initial_replicas": self.processor_options.autoscaler_options.num_replicas, # noqa: E501
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95,8 +95,17 @@
# contain any runtime logic that applies to all Processor types.
async def create_replica(self) -> ReplicaReference:
replica_id = utils.uuid()
# Some options are optional, so we need to filter out None values
ray_actor_options = {

Check warning on line 99 in buildflow/core/app/runtime/actors/pipeline_pattern/pipeline_pool.py

View check run for this annotation

Codecov / codecov/patch

buildflow/core/app/runtime/actors/pipeline_pattern/pipeline_pool.py#L99

Added line #L99 was not covered by tests
"num_cpus": self.options.num_cpus,
}
if self.options.num_gpu is not None:
ray_actor_options["num_gpus"] = self.options.num_gpu
if self.options.memory is not None:
ray_actor_options["memory"] = self.options.memory

Check warning on line 105 in buildflow/core/app/runtime/actors/pipeline_pattern/pipeline_pool.py

View check run for this annotation

Codecov / codecov/patch

buildflow/core/app/runtime/actors/pipeline_pattern/pipeline_pool.py#L102-L105

Added lines #L102 - L105 were not covered by tests

replica_actor_handle = PullProcessPushActor.options(
num_cpus=self.options.num_cpus,
**ray_actor_options
).remote(
self.run_id,
self.processor,
Expand Down
8 changes: 7 additions & 1 deletion buildflow/core/options/runtime_options.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import dataclasses
from typing import Dict
from typing import Dict, Optional

from buildflow.core.options._options import Options
from buildflow.core.processor.processor import ProcessorID
Expand Down Expand Up @@ -53,7 +53,11 @@ def __post_init__(self):
# TODO: Add options for other pattern types, or merge into a single options object
@dataclasses.dataclass
class ProcessorOptions(Options):
# ray actor options
num_cpus: float
num_gpu: Optional[float]
memory: Optional[float]
# Runtime API options
num_concurrency: int
log_level: str
# the configuration of the autoscaler for this processor
Expand All @@ -63,6 +67,8 @@ class ProcessorOptions(Options):
def default(cls) -> "ProcessorOptions":
return cls(
num_cpus=1.0,
num_gpu=None,
memory=None,
num_concurrency=1,
log_level="INFO",
autoscaler_options=AutoscalerOptions.default(),
Expand Down
Loading