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

support arbitrary number of batch dimensions in batched_mul #451

Closed
CarloLucibello opened this issue Jan 2, 2023 · 1 comment · Fixed by #455
Closed

support arbitrary number of batch dimensions in batched_mul #451

CarloLucibello opened this issue Jan 2, 2023 · 1 comment · Fixed by #455

Comments

@CarloLucibello
Copy link
Member

Motivation and description

use case is the multihead attention layer in FluxML/Flux.jl#2146

Possible Implementation

function NNlib.batched_mul(x::AbstractArray{T1,N}, y::AbstractArray{T2,N}) where {T1,T2,N}
  sz = size(x)[3:end]
  @assert sz == size(y)[3:end]
  x2 = reshape(x, size(x, 1), size(x, 2), :)
  y2 = reshape(y, size(y, 1), size(y, 2), :)
  z = NNlib.batched_mul(x2, y2)
  return reshape(z, size(z, 1), size(z, 2), sz...)
end
@mcabbott
Copy link
Member

mcabbott commented Jan 3, 2023

This is #391

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants