Ray Questions( dynamic remotify + num_cpus for remote func that calls remote funcs)

Hey, all I have a couple of questions:

Question 1)
Is there a way to make a function remote on the fly?

Let’s say I have some given function foo.
I know I can do

@ray.remote
def bar(*args):
    return foo(*args)

I was curious if there is a built-in utility for doing:
from ray.util import remotify <=== something like this

remotify(foo).remote(*args)

I know I could write remotify but I want to limit the amount of custom code / I feel like I’ve seen it but I just can’t find it rn.

Question 2)
If I have a remote function that calls out to other remote functions what is the right number of CPU’s to give the first function? Should it requires sum(dependent functions) + self.

For example:

@ray.remote(num_cpus=1)
def bar(arg):
    print(“foo” + arg)
    return “bar”

@ray.remote(num_cpus=x)
def foo():
     bars = ray.get([bar(i) for i in range(100)])
     return bars

What should I set x to
101? Or 1?

For 1, you can just call ray.remote like a function:

def remotify(func):
    return ray.remote(func)

For 2, each remote calls consume independent unit of resources. The “parent” tasks should be annotated with self number of CPUs only. However, when the task is blocked on ray.get Ray will recognize that and temporarily release the resource, and let other CPU tasks to run, because that worker is blocked.

Also when you make remote functions on the fly, make sure to avoid this mistake!