question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

cannot serialize 'Array' object when jax_array = True

See original GitHub issue

Description

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:closed
  • Created 9 months ago
  • Comments:6 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
yashk2810commented, Dec 7, 2022

I don’t know yet. I’ll investigate but let’s wait for a reply in the flax bug.

0reactions
wookayincommented, Dec 7, 2022

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.

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found