Fix momo crash when loss value is a Python float - #1502
Merged
copybara-service[bot] merged 1 commit intoDec 3, 2025
Merged
Conversation
Aaryan-549
force-pushed
the
fix-momo-python-float-1500
branch
from
November 17, 2025 19:13
4a577ca to
d181d3a
Compare
Collaborator
|
Thanks! Can you adjust the type annotation to reflect the value requirement? Should probably drop Optional and use |
Aaryan-549
force-pushed
the
fix-momo-python-float-1500
branch
from
November 18, 2025 04:31
d181d3a to
cf081e8
Compare
Contributor
Author
|
@rdyro Thanks for the review! I've made the suggested changes and updated the type annotation to use jax.typing.ArrayLike. Ready for another look. |
Fixes google-deepmind#1500 The momo and momo_adam update functions declared the value parameter as Optional[jax.Array] but never enforced that type. When calling value.astype(state.barf.dtype), passing a Python float or NumPy scalar would raise AttributeError since these types don't have an astype method. This fix uses jnp.asarray(value, dtype=state.barf.dtype) instead of value.astype(state.barf.dtype) to handle Python floats, NumPy scalars, and JAX arrays uniformly.
Aaryan-549
force-pushed
the
fix-momo-python-float-1500
branch
from
November 18, 2025 12:17
cf081e8 to
3482972
Compare
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.
Fixes #1500
The momo and momo_adam update functions declared the value parameter as Optional[jax.Array] but never enforced that type. When calling value.astype(state.barf.dtype), passing a Python float or NumPy scalar would raise AttributeError since these types don't have an astype method.
This fix uses jnp.asarray(value, dtype=state.barf.dtype) instead of value.astype(state.barf.dtype) to handle Python floats, NumPy scalars, and JAX arrays uniformly.