Skip to content
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

Can't cloudpickle gin-configured class #42

Closed
piojanu opened this issue Dec 20, 2019 · 3 comments
Closed

Can't cloudpickle gin-configured class #42

piojanu opened this issue Dec 20, 2019 · 3 comments

Comments

@piojanu
Copy link

piojanu commented Dec 20, 2019

Running this code...

import cloudpickle
import gin
import pickle


@gin.configurable
def msg_fn(msg):
    return msg


@gin.configurable
class Foo:
    def __init__(self, msg_fn):
        self.msg = msg_fn()


config = """
msg_fn.msg = "Hello World"
Foo.msg_fn = @msg_fn
"""
gin.parse_config(config)

try:
    pkl = pickle.dumps(Foo)
    foo = pickle.loads(pkl)()
    print("Can pickle: {}!".format(foo.msg))
except:
    print("Can't pickle!")

try:
    cpkl = cloudpickle.dumps(Foo)
    foo = cloudpickle.loads(cpkl)()
    print("Can cloudpickle: {}!".format(foo.msg))
except:
    print("Can't cloudpickle!")

...prints:

Can pickle: Hello World!!
Can't cloudpickle!

Cloudpickle rises Error on cloudpickle.dumps(): TypeError: can't pickle _thread.lock objects.

This is a problem, because Ray uses cloudpickle to serialize objects. We can't send gin configurable classes to Ray actors or Ray object store (with ray.put). Is it a bug or should it be done differently? I didn't know where to open this issue (in cloudpickle, ray or here). Can you help us with this?

@piojanu
Copy link
Author

piojanu commented Dec 20, 2019

Note that this will rise error too:

@gin.configurable
class Bar:
    pass
cloudpickle.dumps(Bar)

@piojanu
Copy link
Author

piojanu commented Dec 28, 2019

Reverting this commit: ea92e34 fixes the problem. Having gin configured classes being clouldpicklable is a must for us. Do you have some advice how to make gin picklable without reverting this commit?

@piojanu
Copy link
Author

piojanu commented Jan 6, 2020

Solution: #8 (comment)

@piojanu piojanu closed this as completed Jan 6, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant