Skip to content

Fix tree_map_cast turning non-matching leaves into None - #222

Open
rootkiller6788 wants to merge 1 commit into
google-deepmind:mainfrom
rootkiller6788:fix-tree-map-cast-none-leaf
Open

rootkiller6788 wants to merge 1 commit into
google-deepmind:mainfrom
rootkiller6788:fix-tree-map-cast-none-leaf

Conversation

@rootkiller6788

Copy link
Copy Markdown

tree_map_cast maps a cast function over a pytree, and Bfloat16Cast uses it to bring bfloat16 predictions back to the targets dtype. The inner cast_fn had no return for the "dtype doesn't match" branch, so jax.tree.map silently swapped those leaves for None. Any prediction tree carrying an integer or boolean variable next to the bfloat16 weather variables would come out of the wrapper with that variable turned into None.

The fix is one line: return x unchanged when the dtype doesn't match, instead of falling off the end of the function.

Repro: tree_map_cast({'winds': bf16, 'level': int32, 'mask': bool}, bf16, float32) -- before, 'level' and 'mask' came back as None; after, they're preserved and 'winds' is cast to float32.

cast_fn returned None for any leaf whose dtype isn't input_dtype, so a
tree with an int or bool variable next to the bfloat16 weather vars would
come out of the Bfloat16Cast wrapper with that variable silently replaced
by None. Keep non-matching leaves as-is.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant