-
Notifications
You must be signed in to change notification settings - Fork 184
Restore CloudPickler-scoped globals namespace isolation for pickled functions #240
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
Restore CloudPickler-scoped globals namespace isolation for pickled functions #240
Conversation
|
A bit of background: this PR restores the behavior of cloudpickle from before 0.6.0. In 0.6.0 and 0.6.1 we changed the dynamic module globals handling behavior as we thought it was a bug (lack of consistency with how globals are handled in non-dynamic modules) but user feedback including #214 revealed that the new behavior is surprising/annoying for most users. In #216 we explored the possibility of introducing of a switch on the So to keep things simple, this PR hardcodes the |
I agree, please feel free to push an empty commit with the |
|
The failure comes from Edit: the next build passed, so indeed it looks like a random failure. |
Codecov Report
@@ Coverage Diff @@
## master #240 +/- ##
==========================================
- Coverage 85.39% 84.91% -0.49%
==========================================
Files 1 1
Lines 589 570 -19
Branches 118 112 -6
==========================================
- Hits 503 484 -19
Misses 63 63
Partials 23 23
Continue to review full report at Codecov.
|
ogrisel
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM. Just a few comments:
|
@suquark, can you check this? |
|
This doesn't seem to fix the issue fully for us. Not sure what is going on, do you have an idea @suquark? |
|
@pcmoritz sorry, I still had a couple fixes to do that I thought I already pushed. This PR now reverts |
|
@pierreglaser Great, I re-ran the Ray test suite on top of your latest commits and it seems to be working now. Thanks a lot for the fix :) |
ogrisel
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
First pass at reviewing the new version of this PR.
Co-Authored-By: pierreglaser <[email protected]>
Co-Authored-By: pierreglaser <[email protected]>
13afdd2 to
f4f15e3
Compare
|
Here is a gist that loads "old" (e.g created using PS: sorry about the ugly force push, i forgot I resolved some conflicts in the browser... |
|
@pierreglaser please launch downstream CI on this PR to check that we have not broken anything. |
CHANGES.md
Outdated
| variables when loaded in their new environment. This restores the (previously | ||
| untested) behavior of cloudpickle prior to changes done in 0.5.4 for | ||
| functions defined in the `__main__` module, and 0.6.0/1 for other dynamic | ||
| functions. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There is no "override" anymore because we create a new empty namespace each time. May I suggest the following:
- Global variables referenced by functions pickled by cloudpickle are now
unpickled in a new and isolated namespace scoped by the CloudPickler instance.
This restores the (previously untested) behavior of cloudpickle prior to changes
done in 0.5.4 for functions defined in the `__main__` module, and 0.6.0/1 for
other dynamic functions.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes you are right, this was stale. I'll let the downstream integration test finish before pushing a new commit.
|
You can trigger downstream CI again, I merged your PR to fix the broken loky test. |
ogrisel
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
+1 for merge once the downstream CI has completed and the changelog is updated.
|
Merged. Thanks for your work @pierreglaser! Thanks for your feedback @pcmoritz! |
## What changes were proposed in this pull request? After upgrading cloudpickle to 0.6.1 at #20691, one regression was found. Cloudpickle had a critical cloudpipe/cloudpickle#240 for that. Basically, it currently looks existing globals would override globals shipped in a function's, meaning: **Before:** ```python >>> def hey(): ... return "Hi" ... >>> spark.range(1).rdd.map(lambda _: hey()).collect() ['Hi'] >>> def hey(): ... return "Yeah" ... >>> spark.range(1).rdd.map(lambda _: hey()).collect() ['Hi'] ``` **After:** ```python >>> def hey(): ... return "Hi" ... >>> spark.range(1).rdd.map(lambda _: hey()).collect() ['Hi'] >>> >>> def hey(): ... return "Yeah" ... >>> spark.range(1).rdd.map(lambda _: hey()).collect() ['Yeah'] ``` Therefore, this PR upgrades cloudpickle to 0.8.0. Note that cloudpickle's release cycle is quite short. Between 0.6.1 and 0.7.0, it contains minor bug fixes. I don't see notable changes to double check and/or avoid. There is virtually only this fix between 0.7.0 and 0.8.1 - other fixes are about testing. ## How was this patch tested? Manually tested, tests were added. Verified unit tests were added in cloudpickle. Closes #23904 from HyukjinKwon/SPARK-27000. Authored-by: Hyukjin Kwon <[email protected]> Signed-off-by: Hyukjin Kwon <[email protected]>
This PR changes the way globals collisions are handled:
The tests are accordingly updated. Note that #216 did not add any new tests, but simply parametrized existing ones.
EDIT: For the record, the previous behavior (silently override globals shipped with the functions) introduced regressions reported by users of downstream projects. Here is the list of issues related to it:
@ogrisel it is a good PR to trigger the new downstream integration builds!