Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update nn.py to use jnp.add rather than + operand. #19323

Merged
merged 1 commit into from
Apr 15, 2024

Conversation

chococigar
Copy link
Contributor

Ref: https://jax.readthedocs.io/en/latest/notebooks/thinking_in_jax.html#numpy-lax-xla-jax-api-layering

jax.numpy implicitly promotes arguments to allow operations of mixed data types, while jax.lax does not. If using jax.lax directly, it is advised to do explicit type promotion. Because the core functions in nn.py are the backbone for various model edge cases, it is better to use a safer operand.

@@ -546,7 +546,7 @@ def batch_normalization(
offset = jnp.reshape(offset, shape)
res = res + offset

return x * inv + res
return jnp.add(x + inv, res)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That should be *

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for catching, updated accordingly.

@fchollet
Copy link
Member

Was this change motivated by a specific error you encountered?

@google-ml-butler google-ml-butler bot added kokoro:force-run ready to pull Ready to be merged into the codebase labels Apr 15, 2024
@fchollet fchollet merged commit 3b92b67 into keras-team:master Apr 15, 2024
6 checks passed
@google-ml-butler google-ml-butler bot removed ready to pull Ready to be merged into the codebase kokoro:force-run labels Apr 15, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
Status: Merged
Development

Successfully merging this pull request may close these issues.

3 participants