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

[jax2tf] Fix conversion for argmin/argmax; add conversion for reduce #7196

Merged
merged 1 commit into from
Jul 12, 2021

Conversation

copybara-service[bot]
Copy link

@copybara-service copybara-service bot commented Jul 6, 2021

[jax2tf] Fix conversion for argmin/argmax; add conversion for reduce

The previous conversion for argmin/argmax simply used tf.argmin and tf.argmax.
Those ops behave differently than JAX when the inputs contain NaN and Inf. Added
a few test cases in primitive_harness to expose the failures.

In order to implement an accurate conversion of argmin/argmax, we need to use the
XLA Reduce op.

Also tightened the shape checks for lax.argmin and lax.argmax, to ensure they are
not used with an empty reduced dimension. E.g., if the axis=-1, previously we got
an internal error:

RuntimeError: Invalid argument: Reducing out-of-bounds dimension -1 in shape f32[2,0,3].: 
This is a bug in JAX's shape-checking rules; please report it!

@google-cla google-cla bot added the cla: yes label Jul 6, 2021
@gnecula gnecula self-assigned this Jul 6, 2021
@copybara-service copybara-service bot force-pushed the test_382920927 branch 6 times, most recently from 4e37169 to d9a3f58 Compare July 12, 2021 07:41
The previous conversion for argmin/argmax simply used tf.argmin and tf.argmax.
Those ops behave differently than JAX when the inputs contain NaN and Inf. Added
a few test cases in primitive_harness to expose the failures.

In order to implement an accurate conversion of argmin/argmax, we need to use the
XLA Reduce op.

Also tightened the shape checks for lax.argmin and lax.argmax, to ensure they are
not used with an empty reduced dimension. E.g., if the axis=-1, previously we got
an internal error:
```
RuntimeError: Invalid argument: Reducing out-of-bounds dimension -1 in shape f32[2,0,3].:
This is a bug in JAX's shape-checking rules; please report it!
```
PiperOrigin-RevId: 384182794
@copybara-service copybara-service bot merged commit 0beef34 into main Jul 12, 2021
@copybara-service copybara-service bot deleted the test_382920927 branch July 12, 2021 08:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant