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

The cumprod rule with CUDA hits scalar indexing error #1447

Closed
Red-Portal opened this issue Aug 15, 2023 · 2 comments
Closed

The cumprod rule with CUDA hits scalar indexing error #1447

Red-Portal opened this issue Aug 15, 2023 · 2 comments
Labels
ChainRules adjoint -> rrule, and further integration

Comments

@Red-Portal
Copy link

Hi, it seems like the rule is not properly kicking in for CUDA.

using Zygote, CUDA
gradient(x -> x |> cumprod |> sum , CUDA.randn(3) )
ERROR: Scalar indexing is disallowed.
Invocation of getindex resulted in scalar indexing of a GPU array.
This is typically caused by calling an iterating implementation of a method.
Such implementations *do not* execute on the GPU, but very slowly on the CPU,
and therefore are only permitted from the REPL for prototyping purposes.
If you did intend to index this array, annotate the caller with @allowscalar.
Stacktrace:
  [1] error(s::String)
    @ Base ./error.jl:35
  [2] assertscalar(op::String)
    @ GPUArraysCore ~/.julia/packages/GPUArraysCore/uOYfN/src/GPUArraysCore.jl:103
  [3] getindex
    @ ~/.julia/packages/GPUArrays/5XhED/src/host/indexing.jl:9 [inlined]
  [4] ∇cumprod!
    @ ~/.julia/packages/ChainRules/9sNmB/src/rulesets/Base/mapreduce.jl:405 [inlined]
  [5] ∇cumprod(x::CuArray{Float32, 1, CUDA.Mem.DeviceBuffer}, dy::CuArray{Float32, 1, CUDA.Mem.DeviceBuffer}, y::CuArray{Float32, 1, CUDA.Mem.DeviceBuffer})
    @ ChainRules ~/.julia/packages/ChainRules/9sNmB/src/rulesets/Base/mapreduce.jl:395
  [6] #1693
    @ ~/.julia/packages/ChainRules/9sNmB/src/rulesets/Base/mapreduce.jl:341 [inlined]
  [7] unthunk
    @ ~/.julia/packages/ChainRulesCore/0t04l/src/tangent_types/thunks.jl:204 [inlined]
  [8] unthunk
    @ ~/.julia/packages/ChainRulesCore/0t04l/src/tangent_types/thunks.jl:237 [inlined]
  [9] wrap_chainrules_output
    @ ~/.julia/packages/Zygote/4rucm/src/compiler/chainrules.jl:110 [inlined]
 [10] map
    @ ./tuple.jl:274 [inlined]
 [11] wrap_chainrules_output
    @ ~/.julia/packages/Zygote/4rucm/src/compiler/chainrules.jl:111 [inlined]
 [12] ZBack
    @ ~/.julia/packages/Zygote/4rucm/src/compiler/chainrules.jl:211 [inlined]
 [13] Pullback
    @ ./operators.jl:907 [inlined]
 [14] Pullback
    @ ./REPL[7]:1 [inlined]
 [15] (::Zygote.var"#75#76"{Zygote.Pullback{Tuple{var"#31#32", CuArray{Float32, 1, CUDA.Mem.DeviceBuffer}}, Tuple{Zygote.Pullback{Tuple{typeof(|>), CuArray{Float32, 1, CUDA.Mem.DeviceBuffer}, typeof(cumprod)}, Tuple{Zygote.ZBack{ChainRules.var"#cumprod_pullback_1#1694"{Int64, CuArray{Float32, 1, CUDA.Mem.DeviceBuffer}, ProjectTo{AbstractArray, NamedTuple{(:element, :axes), Tuple{ProjectTo{Float32, NamedTuple{(), Tuple{}}}, Tuple{Base.OneTo{Int64}}}}}, CuArray{Float32, 1, CUDA.Mem.DeviceBuffer}}}}}, Zygote.Pullback{Tuple{typeof(|>), CuArray{Float32, 1, CUDA.Mem.DeviceBuffer}, typeof(sum)}, Tuple{Zygote.var"#4229#back#1457"{Zygote.var"#1453#1456"{CuArray{Float32, 1, CUDA.Mem.DeviceBuffer}}}}}}}})(Δ::Float32)
    @ Zygote ~/.julia/packages/Zygote/4rucm/src/compiler/interface.jl:45
 [16] gradient(f::Function, args::CuArray{Float32, 1, CUDA.Mem.DeviceBuffer})
    @ Zygote ~/.julia/packages/Zygote/4rucm/src/compiler/interface.jl:97
 [17] top-level scope
    @ REPL[7]:1
 [18] top-level scope
    @ ~/.julia/packages/CUDA/tVtYo/src/initialization.jl:185
@ToucheSir ToucheSir added the ChainRules adjoint -> rrule, and further integration label Aug 15, 2023
@ToucheSir
Copy link
Member

Ref. #282 (comment). Closing since the rule lives in ChainRules (Zygote never had one, I think).

@ToucheSir ToucheSir closed this as not planned Won't fix, can't repro, duplicate, stale Aug 15, 2023
@Red-Portal
Copy link
Author

Red-Portal commented Aug 15, 2023

Oops sorry. I should have taken this to chainrules

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
ChainRules adjoint -> rrule, and further integration
Projects
None yet
Development

No branches or pull requests

2 participants