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

Serialize wrapped global functions by value #4406

Merged
merged 1 commit into from
Nov 2, 2022

Conversation

stiepan
Copy link
Member

@stiepan stiepan commented Oct 31, 2022

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 just io.open) is replaced with a custom wrapper (ipython/ipython@93992a7). This makes serailization by value of any callback that use open call fail with the pickle check that the open 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 use open, 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:

  • Existing tests apply
  • New tests added
    • Python tests
    • GTests
    • Benchmark
    • Other
  • N/A

Checklist

Documentation

  • Existing documentation applies
  • Documentation updated
    • Docstring
    • Doxygen
    • RST
    • Jupyter
    • Other
  • N/A

DALI team only

Requirements

  • Implements new requirements
  • Affects existing requirements
  • N/A

REQ IDs: N/A

JIRA TASK: N/A

Signed-off-by: Kamil Tokarski <ktokarski@nvidia.com>
@stiepan
Copy link
Member Author

stiepan commented Oct 31, 2022

!build

@dali-automaton
Copy link
Collaborator

CI MESSAGE: [6343003]: BUILD STARTED

@stiepan stiepan changed the title Serialize failing global functions by value Serialize wrapped global functions by value Oct 31, 2022
@dali-automaton
Copy link
Collaborator

CI MESSAGE: [6343003]: BUILD FAILED

@jantonguirao jantonguirao self-assigned this Nov 2, 2022
@dali-automaton
Copy link
Collaborator

CI MESSAGE: [6343003]: BUILD PASSED

@stiepan stiepan merged commit 4430603 into NVIDIA:main Nov 2, 2022
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

Successfully merging this pull request may close these issues.

5 participants