Serialize wrapped global functions by value #4406
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Signed-off-by: Kamil Tokarski ktokarski@nvidia.com
Category:
Bug fix (non-breaking change which fixes an issue)
New feature (non-breaking change which adds functionality)
Description:
Extends the idea of serialization by value from local functions to global ones that were manually overwritten.
Fixes an issue with a new ipython notebook env, where
open
(which should be justio.open
) is replaced with a custom wrapper (ipython/ipython@93992a7). This makes serailization by value of any callback that useopen
call fail with the pickle check that theopen is io.open
.Additional information:
Plain python pickler serializes functions by name, just remembering "a path" to the function. However, if the function is not statically available (because it is dynamically created closure or it is global function but in a notebook), this approach fails.
DALI uses sligtly cutomized pickler to handle serialization of local functions and global functions in a notebook mode. The pickler serializes local functions by value (marshalling their bytecode) and serializing recursivelly the dependencies. The same procudure can be applied to a global function if it is marked with
dali.pickling.pikcle_by_value
.Now, ipython recently added a wrapper around global
open
, which makes it non-serializable with pickle. As a result, serialization by value fails on callbacks that useopen
, because it needs to be serialzied as a dependency. The change in this PR just tries to catch any such cases in advance and apply "by value" mode to them too.Affected modules and functionalities:
Key points relevant for the review:
Tests:
Checklist
Documentation
DALI team only
Requirements
REQ IDs: N/A
JIRA TASK: N/A