JuliaDiff / JuliaDiff/ChainRules.jl

Scalar indexing error using prod(...)

Open
#747 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

GPU
Dominant language
Julia
Stars
475
Forks
98
PR merge metrics
No merged PRs in 30d

Description

This might not be a bug, but at the least it seems to be a mysterious error.

I'm using Flux and in the loss function (which is processed by Zygote and so uses ChainRules.jl), I'm using prod. The surprising thing was that it ran for several iterations before failing with a scalar index error.

I'm guessing the error happens when it goes into this branch because it finds a zero somewhere. That would explain why some iterations occur before hitting this error. I don't know if the code can be changed to avoid scalar indexing, or maybe a more informative error, or maybe it's just something I need to better understand.

Stacktrace:
  [1] error(s::String)
    @ Base .\error.jl:35
  [2] assertscalar(op::String)
    @ GPUArraysCore C:\Users\joel\.julia\packages\GPUArraysCore\uOYfN\src\GPUArraysCore.jl:103
  [3] getindex(::CuArray{Float32, 2, CUDA.Mem.DeviceBuffer}, ::Int64, ::Int64)
    @ GPUArrays C:\Users\joel\.julia\packages\GPUArrays\5XhED\src\host\indexing.jl:9
  [4] maybeview
    @ .\views.jl:149 [inlined]
  [5] ∇prod_dims!(dx::CuArray{Float32, 2, CUDA.Mem.DeviceBuffer}, #unused#::Val{1}, x::CuArray{Float32, 2, CUDA.Mem.DeviceBuffer}, dy::CuArray{Float32, 2, CUDA.Mem.DeviceBuffer}, y::CuArray{Float32, 2, CUDA.Mem.DeviceBuffer})
    @ ChainRules C:\Users\joel\.julia\packages\ChainRules\9sNmB\src\rulesets\Base\mapreduce.jl:287
  [6] ∇prod_dims(vald::Val{1}, x::CuArray{Float32, 2, CUDA.Mem.DeviceBuffer}, dy::CuArray{Float32, 2, CUDA.Mem.DeviceBuffer}, y::CuArray{Float32, 2, CUDA.Mem.DeviceBuffer})
    @ ChainRules C:\Users\joel\.julia\packages\ChainRules\9sNmB\src\rulesets\Base\mapreduce.jl:278
  [7] (::ChainRules.var"#1683#1686"{CuArray{Float32, 2, CUDA.Mem.DeviceBuffer}, Int64, CuArray{Float32, 2, CUDA.Mem.DeviceBuffer}, ChainRulesCore.ProjectTo{AbstractArray, NamedTuple{(:element, :axes), Tuple{ChainRulesCore.ProjectTo{Float32, NamedTuple{(), Tuple{}}}, Tuple{Base.OneTo{Int64}, Base.OneTo{Int64}}}}}, CuArray{Float32, 2, CUDA.Mem.DeviceBuffer}})()
    @ ChainRules C:\Users\joel\.julia\packages\ChainRules\9sNmB\src\rulesets\Base\mapreduce.jl:265
  [8] unthunk
    @ C:\Users\joel\.julia\packages\ChainRulesCore\0t04l\src\tangent_types\thunks.jl:204 [inlined]
  [9] unthunk
    @ C:\Users\joel\.julia\packages\ChainRulesCore\0t04l\src\tangent_types\thunks.jl:237 [inlined]
 [10] wrap_chainrules_output
    @ C:\Users\joel\.julia\packages\Zygote\4rucm\src\compiler\chainrules.jl:110 [inlined]
 [11] map
    @ .\tuple.jl:274 [inlined]
 [12] wrap_chainrules_output
    @ C:\Users\joel\.julia\packages\Zygote\4rucm\src\compiler\chainrules.jl:111 [inlined]
 [13] ZBack
    @ C:\Users\joel\.julia\packages\Zygote\4rucm\src\compiler\chainrules.jl:211 [inlined]
 [14] (::Zygote.var"#kw_zpullback#53"{ChainRules.var"#prod_pullback#1684"{Int64, CuArray{Float32, 2, CUDA.Mem.DeviceBuffer}, ChainRulesCore.ProjectTo{AbstractArray, NamedTuple{(:element, :axes), Tuple{ChainRulesCore.ProjectTo{Float32, NamedTuple{(), Tuple{}}}, Tuple{Base.OneTo{Int64}, Base.OneTo{Int64}}}}}, CuArray{Float32, 2, CUDA.Mem.DeviceBuffer}}})(dy::CuArray{Float32, 2, CUDA.Mem.DeviceBuffer})
    @ Zygote C:\Users\joel\.julia\packages\Zygote\4rucm\src\compiler\chainrules.jl:237
...

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by reproducing the prod failure with the Flux, Zygote, ChainRules, and CuArray setup shown in the stack trace. Read src/rulesets/Base/mapreduce.jl around lines 265 and 287, then determine the expected behavior for zero-containing inputs. Done means either avoiding the scalar-indexing error or documenting and reporting it more clearly.

Written by the indexing model from the issue text.

Assessment

Tech stack
julia
Domain
machine-learning
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.