-
Notifications
You must be signed in to change notification settings - Fork 5.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Actors do not work properly with subclasses that call super. #449
Comments
I think it is urgent to solve the problem of handling the kwarg of super class. |
As a workaround, you can do the following. Avoid referring to the class name within the class definition. For example, suppose the base class is class A(object):
pass Instead of defining the actor as @ray.actor
class B(A):
def __init__(self):
super(B, self).__init__()
# This fails.
B() You can define it as follows. @ray.actor
class B(A):
def __init__(self):
A.__init__(self)
# This works.
B() |
@mehrdadn, you've looked a lot at serialization in Python. Is it correct that the problem has to do with referring to the name of |
It indeed seems to be that they don't support a class referring to itself by name at all:
It also seems to be strictly a The workaround for I would file this as a bug with |
Thanks @mehrdadn. In this case, class A:
def __init__(self):
A as AttributeError: Can't get attribute 'A' on <module '__main__'> |
Oof, I forgot to delete |
Closing this for now since it seems to be a bug in cloudpickle, and we have a viable workaround which is to call |
The cloudpickle issue is now fixed with cloudpipe/cloudpickle#102, this should be part of the next cloudpickle release. It still doesn't work with Ray and the cloudpickle master, but there is new hope that we can fix it! |
We haven't resolved this yet, but the following workaround seems to work. import ray
ray.init()
class Foo(object):
def __init__(self):
self.x = 1
class Bar(Foo):
def __init__(self):
super(Bar, self).__init__()
def get_x(self):
return self.x
Bar2 = ray.remote(Bar)
b = Bar2.remote()
ray.get(b.get_x.remote()) |
Any idea how I can do this if I am using actors that require a GPU? If I add a gpu argument to the example above, i.e.
I get the following error:
|
If you are using Python 3 there seems to be a simple workaround to the entire problem. Just leave out the super arguments: import ray
ray.init()
class Foo(object):
def __init__(self):
self.x = 1
@ray.remote
class Bar(Foo):
def __init__(self):
super().__init__()
def get_x(self):
return self.x
b = Bar.remote()
print(ray.get(b.get_x.remote())) This did not cause an error for me and also worked with |
@amiranas Thanks! I'll try that |
The original issue no longer seems completely accurate, but there is still a problem here. If I run import ray
ray.init()
import cloudpickle
class A(object):
pass
@ray.remote
class B(A):
def __init__(self):
super(B, self).__init__()
B.remote() There is no issue with cloudpickle now, but the actor constructor fails with
|
Have this problem been fixed yet? I get the same bug in Ray 1.12.1 class A(object):
def __init__(self):
print("I'm A")
@ray.remote
class B(A):
def __init__(self):
super(B, self).__init__()
#super().__init__() #this can work
print("I'm B")
def test(self):
pass
b=B.remote()
objref = b.test.remote()
ray.get(objref) |
Continuing a discussion from #439, and as pointed out by @raopku, the following does not work.
At the root of the problem is the fact that
cloudpickle
doesn't seem to be able to serialize subclasses that callsuper
. For example, consider the following.The last line fails with the following exception.
The text was updated successfully, but these errors were encountered: