How to use `@ray.remote` on a subclass

Hi, here’s a simplified version of my code:

import ray

class Foo:
    def __init__(self, x):
        self.x = x
    
    def run(self):
        pass

    @classmethod
    def main(cls, x):
        main_instance = cls(x)
        main_instance.run()

@ray.remote
class Bar(Foo):
    def run(self):
        return self.x
    

ray.init()
x = ray.get(Bar.main.remote(1))

We have a base class Foo with classmethod main, and we want to make the subclass Bar a Ray Actor. The code above returns

Traceback (most recent call last):
  File "test.py", line 22, in <module>
    x = ray.get(Bar.main.remote(1))
AttributeError: 'function' object has no attribute 'remote'

What is the correct way to implement something like this so that we could use the classmethod Bar.main.remote(1)?

Ray version: 1.12.0

Hey @fuhuifang unfortunately this isn’t supported. Ray has to do quite a lot of class inspection to generate the remote functions internally, and it looks like this case isn’t covered.

Feel free to file a feature request on GitHub (cc @suquark ).

4 Likes