cannot serialize 'Array' object when jax_array = True
See original GitHub issueDescription
import jax.numpy as jnp
from flax import serialization
s = jnp.zeros(5)
t = serialization.msgpack_serialize(s)
print(len(t))
jax 0.3.25: works OK (prints 36) jax HEAD:
File "jaxbug.py", line 5, in <module>
t = serialization.msgpack_serialize(s)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File ".../lib/python3.11/site-packages/flax/serialization.py", line 334, in msgpack_serialize
return msgpack.packb(pytree, default=_msgpack_ext_pack, strict_types=True)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File ".../lib/python3.11/site-packages/msgpack/__init__.py", line 38, in packb
return Packer(**kwargs).pack(o)
^^^^^^^^^^^^^^^^^^^^^^^^
File "msgpack/_packer.pyx", line 294, in msgpack._cmsgpack.Packer.pack
File "msgpack/_packer.pyx", line 300, in msgpack._cmsgpack.Packer.pack
File "msgpack/_packer.pyx", line 297, in msgpack._cmsgpack.Packer.pack
File "msgpack/_packer.pyx", line 291, in msgpack._cmsgpack.Packer._pack
TypeError: can not serialize 'Array' object
I guess the new global default jax.Array
in ea930e1d8 might have caused the bug. Note that this serialization API can be called through checkpoint.save
or any other relevant codes.
What jax/jaxlib version are you using?
jax master (61398ff409bd1afc7fb96bf9f0b0c43444baca2b, any version since ea930e1d8)
Which accelerator(s) are you using?
CPU
Additional system info
macOS, Linux x86_64
NVIDIA GPU info
N/A
Issue Analytics
- State:
- Created 9 months ago
- Comments:6 (5 by maintainers)
Top Results From Across the Web
ES6 Set does not serialize to array - json - Stack Overflow
I've noticed that the Set in ES2015 does not implement a simple toJSON function, such as serializing to an array. Below is the...
Read more >var_export - Manual - PHP
I have been looking for the best method to store data in cache files. First, I've identified two limitations of var_export verus serialize....
Read more >SerializeJSON - Adobe Support
It converts structures to JSON Objects, arrays to JSON Arrays, numbers to JSON ... this.serialization.preservecaseforstructkey = true.
Read more >Serialization Guide - Json.NET
NET collections are not serialized. In situations where a type implements IEnumerable but a JSON array is not wanted, then the JsonObjectAttribute can...
Read more >Serialization - PHP Internals Book
For objects there are two serialization mechanisms: The first one simply serializes the object properties just like it is done for arrays. This...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
I don’t know yet. I’ll investigate but let’s wait for a reply in the flax bug.
Yes — my flax installation was somehow outdated and my apologies for having missed them. Flax was using a custom serializer and it has been updated, can confirm flax 0.6.1+ works with no problems. Thank you.