-
Notifications
You must be signed in to change notification settings - Fork 232
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 CUDA randn work with Zygote #2581
base: master
Are you sure you want to change the base?
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks. Needs a rebase for the CI failure.
@@ -2,12 +2,15 @@ | |||
|
|||
module ChainRulesCoreExt | |||
|
|||
using CUDA: CuArray | |||
using CUDA: CuArray, CUDA |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
using CUDA: CuArray, CUDA | |
using CUDA |
@@ -0,0 +1,19 @@ | |||
using GPUArraysCore: GPUArraysCore |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
using GPUArraysCore: GPUArraysCore | |
using GPUArrays |
GPUArrays re-exports the Core functionality.
function call_rand(v::AbstractVector{T}) where {T} | ||
randn(T, 4,4) * v[1:4] | ||
end | ||
function call_rand(v::GPUArraysCore.AbstractGPUVector{T}) where {T} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
function call_rand(v::GPUArraysCore.AbstractGPUVector{T}) where {T} | |
function call_rand(v::AbstractGPUVector{T}) where {T} |
|
||
isdefined(Base, :get_extension) ? (import ChainRulesCore) : (import ..ChainRulesCore) | ||
|
||
## support ChainRulesCore inplaceability | ||
|
||
ChainRulesCore.is_inplaceable_destination(::CuArray) = true | ||
|
||
# allow usage of rand with Zygote | ||
ChainRulesCore.@non_differentiable CUDA.randn(::Any...) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
rand
too?
ChainRulesCore.@non_differentiable CUDA.randn(::Any...) | |
ChainRulesCore.@non_differentiable CUDA.rand(::Any...) | |
ChainRulesCore.@non_differentiable CUDA.randn(::Any...) |
Tab completion says there are a few more, but not marked public, so IDK:
julia> CUDA.rand
rand rand_logn
rand_logn! rand_poisson
rand_poisson! randexp_unlikely
randn randn_unlikely
5d585c4
to
c850163
Compare
Currently, I get errors when using CUDA in combination with Zygote and random numbers.
mcabbott adviced to add a
@non_differentiable CUDA.randn
rule forCUDA.randn
to CUDAs ChainRulesCoreExt, so that all users can benefit.