-
Notifications
You must be signed in to change notification settings - Fork 6k
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
[Datasets] Add logical operator for map() #31912
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,13 +7,14 @@ | |
from ray.data._internal.execution.operators.map_operator import MapOperator | ||
from ray.data._internal.logical.interfaces import LogicalOperator | ||
from ray.data._internal.compute import ( | ||
UDF, | ||
get_compute, | ||
CallableClass, | ||
ComputeStrategy, | ||
TaskPoolStrategy, | ||
ActorPoolStrategy, | ||
) | ||
from ray.data.block import BatchUDF, Block | ||
from ray.data.block import BatchUDF, Block, RowUDF | ||
|
||
|
||
if sys.version_info >= (3, 8): | ||
|
@@ -22,44 +23,99 @@ | |
from typing_extensions import Literal | ||
|
||
|
||
class MapBatches(LogicalOperator): | ||
"""Logical operator for map_batches.""" | ||
class BaseMapLike(LogicalOperator): | ||
"""Abstract class for logical operators should be converted to physical | ||
MapOperator. | ||
""" | ||
|
||
def __init__( | ||
self, | ||
name: str, | ||
input_op: LogicalOperator, | ||
block_fn: BlockTransform, | ||
fn: BatchUDF, | ||
batch_size: Optional[Union[int, Literal["default"]]] = "default", | ||
compute: Optional[Union[str, ComputeStrategy]] = None, | ||
batch_format: Literal["default", "pandas", "pyarrow", "numpy"] = "default", | ||
zero_copy_batch: bool = False, | ||
target_block_size: Optional[int] = None, | ||
fn: Optional[UDF] = None, | ||
fn_args: Optional[Iterable[Any]] = None, | ||
fn_kwargs: Optional[Dict[str, Any]] = None, | ||
fn_constructor_args: Optional[Iterable[Any]] = None, | ||
fn_constructor_kwargs: Optional[Dict[str, Any]] = None, | ||
ray_remote_args: Optional[Dict[str, Any]] = None, | ||
): | ||
super().__init__("MapBatches", [input_op]) | ||
super().__init__(name, [input_op]) | ||
self._block_fn = block_fn | ||
self._fn = fn | ||
self._batch_size = batch_size | ||
self._compute = compute or "tasks" | ||
self._batch_format = batch_format | ||
self._zero_copy_batch = zero_copy_batch | ||
self._target_block_size = target_block_size | ||
self._fn = fn | ||
self._fn_args = fn_args | ||
self._fn_kwargs = fn_kwargs | ||
self._fn_constructor_args = fn_constructor_args | ||
self._fn_constructor_kwargs = fn_constructor_kwargs | ||
self._ray_remote_args = ray_remote_args or {} | ||
|
||
|
||
def plan_map_batches_op( | ||
op: MapBatches, input_physical_dag: PhysicalOperator | ||
) -> PhysicalOperator: | ||
"""Get the corresponding DAG of physical operators for MapBatches.""" | ||
class MapBatches(BaseMapLike): | ||
"""Logical operator for map_batches.""" | ||
|
||
def __init__( | ||
self, | ||
input_op: LogicalOperator, | ||
block_fn: BlockTransform, | ||
fn: BatchUDF, | ||
batch_size: Optional[Union[int, Literal["default"]]] = "default", | ||
compute: Optional[Union[str, ComputeStrategy]] = None, | ||
batch_format: Literal["default", "pandas", "pyarrow", "numpy"] = "default", | ||
zero_copy_batch: bool = False, | ||
target_block_size: Optional[int] = None, | ||
fn_args: Optional[Iterable[Any]] = None, | ||
fn_kwargs: Optional[Dict[str, Any]] = None, | ||
fn_constructor_args: Optional[Iterable[Any]] = None, | ||
fn_constructor_kwargs: Optional[Dict[str, Any]] = None, | ||
ray_remote_args: Optional[Dict[str, Any]] = None, | ||
): | ||
super().__init__( | ||
"MapBatches", | ||
input_op, | ||
block_fn, | ||
compute=compute, | ||
target_block_size=target_block_size, | ||
fn=fn, | ||
fn_args=fn_args, | ||
fn_kwargs=fn_kwargs, | ||
fn_constructor_args=fn_constructor_args, | ||
fn_constructor_kwargs=fn_constructor_kwargs, | ||
ray_remote_args=ray_remote_args, | ||
) | ||
self._batch_size = batch_size | ||
self._batch_format = batch_format | ||
self._zero_copy_batch = zero_copy_batch | ||
|
||
|
||
class Map(BaseMapLike): | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. s/Map/MapRow? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. hmm still want to keep There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't think need to use the same as public API though. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ok, renamed to There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. yeah, I think the iteration API names are quite intuitive: |
||
"""Logical operator for map.""" | ||
|
||
def __init__( | ||
self, | ||
input_op: LogicalOperator, | ||
block_fn: BlockTransform, | ||
fn: RowUDF, | ||
compute: Optional[Union[str, ComputeStrategy]] = None, | ||
ray_remote_args: Optional[Dict[str, Any]] = None, | ||
): | ||
super().__init__( | ||
"Map", | ||
input_op, | ||
block_fn, | ||
compute=compute, | ||
fn=fn, | ||
ray_remote_args=ray_remote_args, | ||
) | ||
|
||
|
||
def plan_map_like_op( | ||
op: BaseMapLike, input_physical_dag: PhysicalOperator | ||
) -> MapOperator: | ||
"""Get the corresponding physical operators DAG for map-like operators.""" | ||
compute = get_compute(op._compute) | ||
block_fn = op._block_fn | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This name looks strange, maybe LogicalMap or AbstractMap or MapInterface?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@jianoaix - sure, changed to
AbstractMap
.