Skip to content

Commit

Permalink
[Data] Fix args and kwargs passed to ActorPool map_batches (#38110)
Browse files Browse the repository at this point in the history
Fixes args and kwargs passed to ActorPool map_batches. Closes #38092
Signed-off-by: amogkam <amogkamsetty@yahoo.com>
  • Loading branch information
amogkam committed Aug 4, 2023
1 parent 73311c4 commit 43958f0
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 2 deletions.
4 changes: 2 additions & 2 deletions python/ray/data/_internal/planner/plan_udf_map_op.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,10 +54,10 @@ def _plan_udf_map_op(

fn_ = make_callable_class_concurrent(op._fn)

def fn(item: Any) -> Any:
def fn(item: Any, *args, **kwargs) -> Any:
assert ray.data._cached_fn is not None
assert ray.data._cached_cls == fn_
return ray.data._cached_fn(item)
return ray.data._cached_fn(item, *args, **kwargs)

def init_fn():
if ray.data._cached_fn is None:
Expand Down
20 changes: 20 additions & 0 deletions python/ray/data/tests/test_map.py
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,26 @@ def __call__(self, x):
actor_reuse = ds.filter(StatefulFn, compute=ray.data.ActorPoolStrategy()).take()
assert len(actor_reuse) == 9, actor_reuse

class StatefulFnWithArgs:
def __init__(self, arg, kwarg):
assert arg == 1
assert kwarg == 2

def __call__(self, x, arg, kwarg):
assert arg == 1
assert kwarg == 2
return x

# map_batches with args & kwargs
ds.map_batches(
StatefulFnWithArgs,
compute=ray.data.ActorPoolStrategy(),
fn_args=(1,),
fn_kwargs={"kwarg": 2},
fn_constructor_args=(1,),
fn_constructor_kwargs={"kwarg": 2},
).take() == list(range(10))


def test_concurrent_callable_classes(shutdown_only):
"""Test that concurrenct actor pool runs user UDF in a separate thread."""
Expand Down

0 comments on commit 43958f0

Please sign in to comment.