[Pallas] Lower aten gather using one_hot + sum for TPU compatibility, unblocking cross_entropy#2060
Open
AmesingFlank wants to merge 1 commit into
Open
[Pallas] Lower aten gather using one_hot + sum for TPU compatibility, unblocking cross_entropy#2060AmesingFlank wants to merge 1 commit into
AmesingFlank wants to merge 1 commit into
Conversation
1a3b7f5 to
696b52e
Compare
This was referenced Apr 20, 2026
AmesingFlank
added a commit
that referenced
this pull request
Apr 20, 2026
TPU Mosaic has very limited lax.gather support, so jnp.take_along_axis fails during lowering. Instead, implement gather(input, dim, index) as: mask = one_hot(index.squeeze(dim), input.shape[dim], dtype=input.dtype) result = sum(input * mask, axis=dim, keepdims=True) Also removes the xfailIfPallas mark from test_cross_entropy since the gather lowering now works. Co-Authored-By: Claude Sonnet 4 <noreply@anthropic.com> stack-info: PR: #2060, branch: AmesingFlank/stack/26
AmesingFlank
added a commit
that referenced
this pull request
Apr 20, 2026
TPU Mosaic has very limited lax.gather support, so jnp.take_along_axis fails during lowering. Instead, implement gather(input, dim, index) as: mask = one_hot(index.squeeze(dim), input.shape[dim], dtype=input.dtype) result = sum(input * mask, axis=dim, keepdims=True) Also removes the xfailIfPallas mark from test_cross_entropy since the gather lowering now works. Co-Authored-By: Claude Sonnet 4 <noreply@anthropic.com> stack-info: PR: #2060, branch: AmesingFlank/stack/26
… unblocking cross_entropy TPU Mosaic has very limited lax.gather support, so jnp.take_along_axis fails during lowering. Instead, implement gather(input, dim, index) as: mask = one_hot(index.squeeze(dim), input.shape[dim], dtype=input.dtype) result = sum(input * mask, axis=dim, keepdims=True) Also removes the xfailIfPallas mark from test_cross_entropy since the gather lowering now works. Co-Authored-By: Claude Sonnet 4 <noreply@anthropic.com> stack-info: PR: #2060, branch: AmesingFlank/stack/26
696b52e to
c0cabf4
Compare
Contributor
|
Is this somewhat related to #2054 ? |
Collaborator
My 2 cents: they are orthogonal.
I think both can land independently. They share the same one-hot-matmul trick, so we can extract a shared helper as a follow-up if it's worth the churn. |
jansel
approved these changes
Apr 23, 2026
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.
Stacked PRs:
[Pallas] Lower aten gather using one_hot + sum for TPU compatibility
TPU Mosaic has very limited lax.gather support, so jnp.take_along_axis
fails during lowering. Instead, implement
gather(input, dim, index)as:Also removes the
xfailIfPallasmark from test_cross_entropy since thegather lowering now works.
Co-Authored-By: Claude Sonnet 4 noreply@anthropic.com