Flux CNN error: Scalar indexing is disallowed

Hi!

I have 1D data which I can successfully train and test with all to all connected 3 layer model as below:

function build_model_ffn(; nclasses=2)
    return Chain(
            Dense(99, 48, relu),
            Dense(48, 24, relu),
            Dense(24, 12, relu),
            Dense(12, nclasses))
end

I am currently trying to adapt the 1D data to CNN by converting it into a (33, 3, 1) with 1 channel (reshaping the input data), using the following model for training:

function build_model_dnn(; nclasses=2)
    return Chain(
            Conv((3,3), 1=>1, relu, pad=(1,1)),
            MaxPool((3,3)),
            flatten,
            Dense(11, 5, relu),
            Dense(5, nclasses)
          )
end

The core functionality of training and testing is adapted from the model zoo feed forward example and remains the same for both the above models. While the first one, build_model_ffn runs successfully, the latter fails with a scalar indexing error. I also tried adapting the convolution layer to be 1D which results in the same error. It would be helpful to know any insights on the error resulting in a successful run of the second model.

The following includes more details of the error:

 [11] conv(x::CuArray{Int64, 4, CUDA.Mem.DeviceBuffer}, w::CuArray{Float32, 4, CUDA.Mem.DeviceBuffer}, cdims::DenseConvDims{2, 2, 2, 4, 2}; kwargs::Base.Iterators.Pairs{Union{}, Union{}, Tuple{}, NamedTuple{(), Tuple{}}})
    @ NNlib /user/jlib/packages/NNlib/0QnJJ/src/conv.jl:88

Something is producing an array of integers x here, maybe your input data? The GPU conv wants all Float32, so instead you get some slow fallback, which works by indexing.

1 Like

Many thanks! It was indeed that the input data is of the type int and converting it to float makes it work!

Hello there, I got a similar error but on Apple Silicon using the MtlArrays. When I run a forward pass on the GPU with a model that has linear layers with relus it runs fine.
However when I use Conv Layers I run into the error of scalar indexing.

I wonder what is going on under the hood, so that this error occurs.
It is a bit frustrating, because It makes training models on larger datasets impossible in my use case.

gpu convolution is not yet supported on apple sylicon

1 Like