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

Make take_along_axis an optional callback #1440

Conversation

Benjamin-Philip
Copy link
Contributor

Makes take_along_axis an optional callback, using the default
implementation for BinaryBackend and EXLA, and a custom one for
Torchx.

Closes #1366.

@Benjamin-Philip
Copy link
Contributor Author

I'm still yet to implement the default implementation. Hence the failing tests.

^axis -> Value.reshape(indices, new_axis_typespec)
axis -> Value.iota(state.builder, axis, new_axis_typespec)
end)
|> Value.concatenate(indices_rank, full_indices_typespec)
Copy link
Collaborator

Choose a reason for hiding this comment

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

FWIW, this is the main transformation you need to make in order to convert take_along_axis into a gather. :) If you do this transformation and call gather without the axes option, it should be equivalent to the work done here.

@Benjamin-Philip Benjamin-Philip force-pushed the bp-make-take-along-axis-optional branch from ba1a17c to 3da08f3 Compare May 13, 2024 09:37
@Benjamin-Philip
Copy link
Contributor Author

Benjamin-Philip commented May 13, 2024

@josevalim, I've committed that transformation. I'm having some trouble making the optional callback work in Defn, which is why the test are failing in Nx.Defn.GradTest and Nx.RandomTest.

@Benjamin-Philip Benjamin-Philip marked this pull request as ready for review May 13, 2024 09:44
nx/lib/nx.ex Outdated Show resolved Hide resolved
nx/lib/nx.ex Outdated Show resolved Hide resolved
nx/lib/nx/backend.ex Outdated Show resolved Hide resolved
@Benjamin-Philip Benjamin-Philip force-pushed the bp-make-take-along-axis-optional branch from 0863a3c to 3da08f3 Compare May 13, 2024 10:16
@josevalim
Copy link
Collaborator

@Benjamin-Philip you can also remove the implementations from expr.ex and grad.ex :)

@josevalim
Copy link
Collaborator

Fixed and pushed manually, thank you!

@Benjamin-Philip Benjamin-Philip deleted the bp-make-take-along-axis-optional branch May 13, 2024 11:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Remove take_along_axis and take
2 participants