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.

JAX tree_* drops `None` elements

See original GitHub issue

Somewhat confusingly (imho) flatten drops leaves that are None:

>>> jax.tree_leaves([1, None, 1])
[1, 1]

However flatten/unflatten on such a structure is symmetrical (leading me to believe JAX treats a None leaf as part of the structure):

>>> leaves, treedef = jax.tree_flatten([1, None, 1])
>>> jax.tree_unflatten(treedef, leaves)
[1, None, 1]

However multimap does not complain that the structures are different, and also skips the map fn if the left hand leaf is None:

>>> a = [None, 1]
>>> b = [2, None]
>>> jax.tree_multimap(lambda x, y: (x, y), a, b)
[None, (1, None)]

Is this desired behaviour? It doesn’t align with the other tree libraries (e.g. tf.nest and dm-tree) which treat None as a leaf, so it feels broken to me as a user of those libraries.

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:7 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
skyecommented, Mar 4, 2020

Just my $.02, I would prefer if this were behavior were switchable, as I also find the current behavior surprising and hard to remember (I screwed up using pytrees with Nones not five minutes ago!) and I don’t like the vmap dance. But agreed this isn’t top priority.

0reactions
alvarosgcommented, Jun 8, 2020

+1 of documenting this more thoroughly in the doc strings of methods in tree_util. I don’t see any mentions to None in the tree_utils docs

And the notebook referenced earlier does not seem exist anymore.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Working with Pytrees - JAX documentation - Read the Docs
a pytree is a container of leaf elements and/or more pytrees. Containers include lists, tuples, and dicts. A leaf element is anything that's...
Read more >
Writing Mathematics for MathJax
None of the combined components currently include it, so you would need to specify it explicitly in your MathJax configuration in order to...
Read more >
Trimming Trees on a Property Line: What Are Your Rights ...
Disputes over trees on or near the property line can divide neighbors and involve large sums of money. Who can cut it? What...
Read more >
Environmental Services | Clay County, FL
NON -ACCEPTABLE ITEMS. Sharps (needles) - for proper disposal, please get in touch with the Clay County Health Department at (904) 284-6340.
Read more >
Why Is There Water Coming Out of My Tree?
If your tree has missing bark, any wounds, broken parts, this is where the ... We know how to care for Jacksonville and...
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