SteveS
SteveS

Reputation: 4040

How to run a function both in a ray-parallel & without using ray modes?

After sudo pip3 install ray

I have created a function foo(), defined within a ray decorator :

import ray
ray.init()

@ray.remote
def foo(x):
    print(x)

I want to be able to use the foo both in a parallel and in a regular mode (ignoring the decorator).

If I want to use foo without a .remote( blabla_variable ) it will return me an error.

Please advise how to "ignore" the decorator when I don't need it.

Upvotes: 2

Views: 2168

Answers (1)

Robert Nishihara
Robert Nishihara

Reputation: 3362

One workaround is to do the following

import ray
ray.init()

def local_foo(x):
    print(x)

remote_foo = ray.remote(local_foo)

# Call foo locally.
local_foo('arg')

# Call foo remotely.
remote_foo.remote('arg')

Upvotes: 8

Related Questions