Repository navigation
Fix tree_map_cast turning non-matching leaves into None - #222
Open
rootkiller6788 wants to merge 1 commit into
Open
rootkiller6788 wants to merge 1 commit into
rootkiller6788 wants to merge 1 commit into
Conversation
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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.