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

BoundsError if the batch size is smaller than the dimension of the output #264

Open
b0noI opened this issue Aug 1, 2017 · 1 comment
Open

Comments

@b0noI
Copy link

b0noI commented Aug 1, 2017

Originally filed here: https://stackoverflow.com/questions/45406537/boundserror-in-julia-mxnet-when-using-small-batch-size (reported by: Robert Crandall)

quote:
'm trying to reproduce some Python MXNet code in Julia 0.6.0, and I'm getting a BoundsError if I try to use a batch size that is smaller than the dimension of the output. If I use a larger batch size in a toy example, things work properly and the network converges to the correct solution, but in my application the output dimension is large so this isn't practical.
Here's a linear regression example that gives this error:

using MXNet
net = mx.Variable(:data) 
net = mx.FullyConnected(net, name=:fc0, num_hidden=5) 
net = mx.LinearRegressionOutput(net, name=:output) 
mod = mx.FeedForward(net, context=mx.cpu(0))  

batch_size = 4 # works for batch_size > 4  
A = randn(5,100) 
train_in = randn(100,1000) 
train_out = A*train_in + .1*randn(5,1000) 

train_provider = mx.ArrayDataProvider(:data=>train_in,                                       
                                      :output_label=>train_out,
                                      shuffle=true,
                                      batch_size=batch_size) 

optimizer = mx.SGD(lr=0.001, momentum=0.9, weight_decay=0.00001) 
mx.fit(mod, optimizer, train_provider) 

This produces

INFO: Start training on MXNet.mx.Context[CPU0]
INFO: Initializing parameters...
INFO: Creating KVStore...
INFO: TempSpace: Total 0 MB allocated on CPU0
INFO: Start training...
ERROR: LoadError: BoundsError: attempt to access 5×4 Array{Float32,2} at index [Base.Slice(Base.OneTo(5)), 5]

Update from Viacheslav Kovalevskyi:
When I try to reproduce the bug on the master I got:

julia> mx.fit(mod, optimizer, train_provider)
INFO: Start training on MXNet.mx.Context[CPU0]
INFO: Initializing parameters...
INFO: Creating KVStore...
INFO: TempSpace: Total 0 MB allocated on CPU0
INFO: Start training...
ERROR: BoundsError: attempt to access 5_4 Array{Float32,2} at index [Base.Slice(Base.OneTo(5)), 5]
Stacktrace:
[1] throw_boundserror(::Array{Float32,2}, ::Tuple{Base.Slice{Base.OneTo{Int64}},Int64}) at ./abstractarray.jl:433
[2] checkbounds at ./abstractarray.jl:362 [inlined]
[3] view at ./subarray.jl:113 [inlined]
[4] _update_single_output(::MXNet.mx.Accuracy, ::Array{Float32,2}, ::Array{Float32,2}) at /home/ubuntu/.julia/v0.6/MXNet/src/metric.jl:211
[5] macro expansion at /home/ubuntu/.julia/v0.6/MXNet/src/metric.jl:58 [inlined]
[6] macro expansion at /home/ubuntu/.julia/v0.6/MXNet/src/ndarray.jl:783 [inlined]
[7] _update!(::MXNet.mx.Accuracy, ::Array{MXNet.mx.NDArray,1}, ::Array{MXNet.mx.NDArray,1}, ::Val{false}) at /home/ubuntu/.julia/v0.6/MXNet/src/metric.jl:55
[8] update!(::MXNet.mx.Accuracy, ::Array{MXNet.mx.NDArray,1}, ::Array{MXNet.mx.NDArray,1}) at /home/ubuntu/.julia/v0.6/MXNet/src/metric.jl:34
[9] #fit#8303(::Array{Any,1}, ::Function, ::MXNet.mx.FeedForward, ::MXNet.mx.SGD, ::MXNet.mx.ArrayDataProvider) at /home/ubuntu/.julia/v0.6/MXNet/src/model.jl:524
[10] fit(::MXNet.mx.FeedForward, ::MXNet.mx.SGD, ::MXNet.mx.ArrayDataProvider) at /home/ubuntu/.julia/v0.6/MXNet/src/model.jl:351

@ThomasDelteil
Copy link

I confirm this is still happening

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants