mirror of
https://github.com/wassname/ray.git
synced 2026-06-29 14:39:44 +08:00
Enable actor methods to be decorated on the caller side also and get postprocessors. (#4732)
* Allow decorating ray actor methods. * Add test. * Add get postprocessors. * Improve documentation. * Make it work for remote functions. * Temporary fix.
This commit is contained in:
committed by
Philipp Moritz
parent
897b35ce36
commit
d81e71e297
@@ -2892,3 +2892,32 @@ def test_redis_lru_with_set(ray_start_object_store_memory):
|
||||
|
||||
# Now evict the object from the object store.
|
||||
ray.put(x) # This should not crash.
|
||||
|
||||
|
||||
def test_decorated_function(ray_start_regular):
|
||||
def function_invocation_decorator(f):
|
||||
def new_f(args, kwargs):
|
||||
# Reverse the arguments.
|
||||
return f(args[::-1], {"d": 5}), kwargs
|
||||
|
||||
return new_f
|
||||
|
||||
def f(a, b, c, d=None):
|
||||
return a, b, c, d
|
||||
|
||||
f.__ray_invocation_decorator__ = function_invocation_decorator
|
||||
f = ray.remote(f)
|
||||
|
||||
result_id, kwargs = f.remote(1, 2, 3, d=4)
|
||||
assert kwargs == {"d": 4}
|
||||
assert ray.get(result_id) == (3, 2, 1, 5)
|
||||
|
||||
|
||||
def test_get_postprocess(ray_start_regular):
|
||||
def get_postprocessor(object_ids, values):
|
||||
return [value for value in values if value > 0]
|
||||
|
||||
ray.worker.global_worker._post_get_hooks.append(get_postprocessor)
|
||||
|
||||
assert ray.get(
|
||||
[ray.put(i) for i in [0, 1, 3, 5, -1, -3, 4]]) == [1, 3, 5, 4]
|
||||
|
||||
Reference in New Issue
Block a user