Add pickle/cloudpickle round-trip tests for Linen modules (#1481)#5524
Open
kapellirohith wants to merge 1 commit into
Open
Add pickle/cloudpickle round-trip tests for Linen modules (#1481)#5524kapellirohith wants to merge 1 commit into
kapellirohith wants to merge 1 commit into
Conversation
|
Thanks for your pull request! It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA). View this failed invocation of the CLA check for more information. For the most up to date status, view the checks section at the bottom of the pull request. |
9588ad1 to
bf19407
Compare
bf19407 to
bd826ed
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Fixes #1481
Description
This PR introduces unit tests ensuring that Flax Linen Modules can be safely
serialized and deserialized via
pickleandcloudpicklewithout leakinginternal binding state. All new assertions are isolated within
tests/pickle_test.py; no library code is modified.Changes Introduced
ModulePickleTestwith a shared helperassert_roundtrip_identicalthat initializes the module before dumping (so it has been bound at least
once), verifies the restored module comes back unbound (
scope is None),and asserts
applyoutputs and freshly-init-ed parameters arebit-identical before and after round-tripping.
nn.Densewith explicitly picklable initializers via stdlibpickle(with full object equality), and default
nn.Denseviacloudpickle.via both picklers.
Fix cloudpickle serialization of wrapped Module methods. #1475), via
cloudpickle.Technical Findings
nn.Densefails stdlibpickling because the default kernel initializer (
lecun_normal) is aclosure created inside
jax.nn.initializers.variance_scaling, which picklecannot serialize by reference. Rather than modifying core code, this is
documented via an expected-failure canary test
(
test_pickle_default_initializer_limitation) — if it ever starts failing,the limitation was lifted and the tests should be updated.
by value, so restored function fields are equivalent copies rather than
identical objects. The default-Dense cloudpickle test therefore validates
behavioral equality (outputs and re-initialized parameters) instead of
dataclass equality.
chain pulls in dill, so the dill/cloudpickle test-setup conflict described
in Test pickle support #1481 does not affect these tests.
cloudpickle>=3.0.0is already in thetestingextras, so CI needs no dependency changes.Checklist