Skip to content

Commit

Permalink
Merge pull request #474 from LuxDL/ap/metal_recurrence_fix
Browse files Browse the repository at this point in the history
Patch Metal Recurrent Neural Networks
  • Loading branch information
avik-pal authored Jan 6, 2024
2 parents f11c407 + 1781b88 commit 1cb774c
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 1 deletion.
6 changes: 5 additions & 1 deletion Project.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name = "Lux"
uuid = "b2108857-7c20-44ae-9111-449ecde12c47"
authors = ["Avik Pal <avikpal@mit.edu> and contributors"]
version = "0.5.13"
version = "0.5.14"

[deps]
ADTypes = "47edcb42-4c32-4615-8424-f2b9edc5f35b"
Expand Down Expand Up @@ -33,6 +33,7 @@ FillArrays = "1a297f60-69ca-5386-bcde-b61e274b549b"
Flux = "587475ba-b771-5e3f-ad9e-33799f191a9c"
LuxAMDGPU = "83120cb1-ca15-4f04-bf3b-6967d2e6b60b"
LuxCUDA = "d0bbae9a-e099-4d5b-a835-1c6931763bda"
Metal = "dde4c033-4e86-420c-a63e-0dd931031962"
ReverseDiff = "37e2e3b7-166d-5795-8a7a-e32c996b4267"
Tracker = "9f7883ad-71c0-57eb-9f7f-b5c9e6d3789c"
Zygote = "e88e6eb3-aa80-5325-afca-941959d7151f"
Expand All @@ -44,6 +45,7 @@ LuxComponentArraysReverseDiffExt = ["ComponentArrays", "ReverseDiff"]
LuxFluxTransformExt = "Flux"
LuxLuxAMDGPUExt = "LuxAMDGPU"
LuxLuxCUDAExt = "LuxCUDA"
LuxMetalExt = "Metal"
LuxTrackerExt = "Tracker"
LuxZygoteExt = "Zygote"

Expand All @@ -66,6 +68,7 @@ LuxDeviceUtils = "0.1"
LuxLib = "0.3"
MacroTools = "0.5"
Markdown = "<0.0.1, 1"
Metal = "0.5"
Optimisers = "0.2, 0.3"
PackageExtensionCompat = "1"
Random = "<0.0.1, 1"
Expand All @@ -87,6 +90,7 @@ FillArrays = "1a297f60-69ca-5386-bcde-b61e274b549b"
Flux = "587475ba-b771-5e3f-ad9e-33799f191a9c"
LuxAMDGPU = "83120cb1-ca15-4f04-bf3b-6967d2e6b60b"
LuxCUDA = "d0bbae9a-e099-4d5b-a835-1c6931763bda"
Metal = "dde4c033-4e86-420c-a63e-0dd931031962"
ReverseDiff = "37e2e3b7-166d-5795-8a7a-e32c996b4267"
Tracker = "9f7883ad-71c0-57eb-9f7f-b5c9e6d3789c"
Zygote = "e88e6eb3-aa80-5325-afca-941959d7151f"
23 changes: 23 additions & 0 deletions ext/LuxMetalExt.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
module LuxMetalExt

using Lux, LuxLib, Metal, Random

@inline function Lux._init_hidden_state(rng::AbstractRNG, rnn, x::MtlArray)
return MtlArray(rnn.init_state(rng, rnn.out_dims, size(x, 2)))
end

@inline function Lux._conv(x::SubArray{T, N, <:MtlArray}, weight, cdims) where {T, N}
return conv(copy(x), weight, cdims)
end

@inline function Lux._conv_transpose(x::SubArray{T, N, <:MtlArray}, weight,
cdims) where {T, N}
return ∇conv_data(copy(x), weight, cdims)
end

@inline function Lux._eachslice(x::MtlArray, ::Val{dims}) where {dims}
# FIXME: This is not efficient but Metal doesn't deal with views well
return [copy(selectdim(x, dims, i)) for i in axes(x, dims)]
end

end

2 comments on commit 1cb774c

@avik-pal
Copy link
Member Author

Choose a reason for hiding this comment

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

@JuliaRegistrator
Copy link

Choose a reason for hiding this comment

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

Registration pull request created: JuliaRegistries/General/98352

Tip: Release Notes

Did you know you can add release notes too? Just add markdown formatted text underneath the comment after the text
"Release notes:" and it will be added to the registry PR, and if TagBot is installed it will also be added to the
release that TagBot creates. i.e.

@JuliaRegistrator register

Release notes:

## Breaking changes

- blah

To add them here just re-invoke and the PR will be updated.

Tagging

After the above pull request is merged, it is recommended that a tag is created on this repository for the registered package version.

This will be done automatically if the Julia TagBot GitHub Action is installed, or can be done manually through the github interface, or via:

git tag -a v0.5.14 -m "<description of version>" 1cb774c8cdaeed1b16811ecc41b15b81bb8016f9
git push origin v0.5.14

Please sign in to comment.