Skip to content

Fix cloudpickle serialization of wrapped Module methods.#1475

Merged
copybara-service[bot] merged 1 commit into
google:mainfrom
jheek:fix-cloudpickle
Aug 6, 2021
Merged

Fix cloudpickle serialization of wrapped Module methods.#1475
copybara-service[bot] merged 1 commit into
google:mainfrom
jheek:fix-cloudpickle

Conversation

@jheek

@jheek jheek commented Aug 4, 2021

Copy link
Copy Markdown
Contributor

Calling _context inside a closure will make cloudpickle attempt to serialize.
It will fail because it cannot serialize ThreadLocals.

Factoring out the body of method_wrapper into a
separate method hides the _context for cloudpickle
because it can store library methods by name.

This PR does not come with a test because it requires us to depend on cloudpickle.
More importantly some tests indirectly uses dill which causes a clash in the pickle registry between dill & cloudpickle.
If we decide to make (cloud)pickle a first class citizen in the future we will need some clever test setup and elaborate to check for leaks of library internals through closures.

Fixes #1467

@jheek jheek requested review from avital and levskaya August 4, 2021 12:51
@google-cla google-cla Bot added the cla: yes label Aug 4, 2021
Calling _context inside a closure will make cloudpickle attempt to serialize.
It will fail because it cannot serialize ThreadLocals.

Factoring out the body of method_wrapper into a
seperate method hides the _context for cloudpickle
because it can store library methods by name.
@jheek jheek force-pushed the fix-cloudpickle branch from af2fe9d to b7571e4 Compare August 4, 2021 12:54
@avital

avital commented Aug 5, 2021

Copy link
Copy Markdown
Contributor

The change LGTM. Can you please file a new issue to keep track of the challenge of testing this? So that we could in the future find a solution?

@avital avital left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks!

@levskaya

levskaya commented Aug 6, 2021

Copy link
Copy Markdown
Collaborator

LGTM - thanks for figuring out what cloudpickle was doing here!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Cannot pickle linen Modules

3 participants