Hi Team,
Well, I have a usual organization level model serving codebase. I need to explore Ray core and Ray serve feasibility within this.
While going through most of Ray’s docs, blogs, videos and even external youtube videos, I couldn’t see any example showcasing Ray remote/serve implementation/usage with modularized code[Help me with any, if I have missed].
One specific example that I could locate is here at https://docs.ray.io/en/latest/actors.html#actor-methods, I changed it little to demonstrate use-case.
## Counter.py
import ray
ray.init(address='ray://127.0.0.1:10001')
@ray.remote
class Counter(object):
def __init__(self):
self.value = 0
def increment(self):
self.value += 1
return self.value
def get_counter(self):
return self.value
Then I am consuming this Counter.py
in another python script CounterUser.py
as shown below.
#CounterUser.py
import Counter
import ray
@ray.remote
class Foo(object):
# Any method of the actor can return multiple object refs.
@ray.method(num_returns=2)
def bar(self):
return 1, 2
f = Foo.remote()
obj_ref1, obj_ref2 = f.bar.remote()
assert ray.get(obj_ref1) == 1
assert ray.get(obj_ref2) == 2
# Calling Counter module
counter_actor = Counter.remote()
assert ray.get(counter_actor.increment.remote()) == 1
I started ray with ray start --head
and when I called CounterUser.py
, it threw following errors.
❯ python CounterUser.py
Traceback (most recent call last):
File "/Users/macpro/ray_demo/CounterUser.py", line 20, in <module>
counter_actor = Counter.remote()
AttributeError: module 'Counter' has no attribute 'remote'
I do not know if this is correct consumption style but module level consumption is much needed. I can not restructure a big modularized code to a single file with all the models, remote functions, actors.
If anyone has already solved this one, please guide me.