-
Notifications
You must be signed in to change notification settings - Fork 2.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Initial pickle and deepcopy singleton support
- Loading branch information
1 parent
20e5838
commit 6e40270
Showing
3 changed files
with
65 additions
and
2 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
from functools import partial | ||
from cloudpickle import cloudpickle | ||
from copy import deepcopy | ||
|
||
import jax | ||
from jax._src.core import jaxpr_as_fun | ||
|
||
def test_jaxpr_cloudpickle(): | ||
def f(a, b): | ||
return a + b, b * a | ||
|
||
jxpr = jax.make_jaxpr(f)(1, 2) | ||
encoded = cloudpickle.dumps(jxpr) | ||
loaded_jxpr = cloudpickle.loads(encoded) | ||
|
||
assert jaxpr_as_fun(loaded_jxpr)(5, 3) == [8, 15] | ||
|
||
def test_jaxpr_deepcopy(): | ||
def f(a, b): | ||
return b * a, a + b, | ||
|
||
jxpr = jax.make_jaxpr(f)(1, 2) | ||
copied_jaxpr = deepcopy(jxpr) | ||
|
||
assert jaxpr_as_fun(copied_jaxpr)(5, 3) == [15, 8] |