JAX tree_* drops `None` elements
See original GitHub issueSomewhat 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:
- Created 4 years ago
- Comments:7 (5 by maintainers)
Top 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 >
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
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.
+1 of documenting this more thoroughly in the doc strings of methods in
tree_util
. I don’t see any mentions toNone
in the tree_utils docsAnd the notebook referenced earlier does not seem exist anymore.