NNlib.jl icon indicating copy to clipboard operation
NNlib.jl copied to clipboard

maxpool NNPACK breaks nonzero padding with stride 1

Open dsweber2 opened this issue 4 years ago • 3 comments

As the title says, using maxpool on the cpu with nonzero padding and a stride of 1 results in an error. On a previous version, maxpool with these parameters worked fine (not sure which, sometime within the past 3 weeks certainly). Strangely, the 1D version actually works. Examples and the actual error follows

using CUDA, NNlib
maxpool(cu(randn(25,2,1,3)),(2,1), pad=(1,0),stride=(1,1)) # works fine
maxpool(randn(25,2,1,3),(2,1), pad=(1,1),stride=(1,1)) # breaks
maxpool(randn(25,2,1,3),(2,1), pad=(1,1),stride=(2,2)) # fine
maxpool(randn(25,1,3),(2,), pad=2,stride=(1,)) # fine
ERROR: NNPACKError(code 12, NNPACK STATUS INVALID INPUT PADDING)
Stacktrace:
 [1] macro expansion at /home/dsweber/.julia/packages/NNlib/XKZ39/src/nnpack/error.jl:79 [inlined]
 [2] nnp_max_pooling_output at /home/dsweber/.julia/packages/NNlib/XKZ39/src/nnpack/libnnpack.jl:81 [inlined]
 [3] nnp_max_pooling_output(::Array{Float32,4}, ::Array{Float32,4}, ::Tuple{Int64,Int64}; padding::NTuple{4,Int64}, stride::Tuple{Int64,Int64}, threadpool::Ptr{Nothing}) at /home/dsweber/.julia/packages/NNlib/XKZ39/src/nnpack/libnnpack.jl:89
 [4] maxpool_nnpack!(::Array{Float32,4}, ::Array{Float32,4}, ::PoolDims{2,(2, 1),(1, 1),(1, 1, 1, 1),(1, 1)}) at /home/dsweber/.julia/packages/NNlib/XKZ39/src/nnpack/impl.jl:4
 [5] maxpool_nnpack!(::Array{Float64,4}, ::Array{Float64,4}, ::PoolDims{2,(2, 1),(1, 1),(1, 1, 1, 1),(1, 1)}; kwargs::Base.Iterators.Pairs{Union{},Union{},Tuple{},NamedTuple{(),Tuple{}}}) at /home/dsweber/.julia/packages/NNlib/XKZ39/src/nnpack/interface.jl:44
 [6] maxpool_nnpack! at /home/dsweber/.julia/packages/NNlib/XKZ39/src/nnpack/interface.jl:42 [inlined]
 [7] maxpool_nnpack(::Array{Float64,4}, ::PoolDims{2,(2, 1),(1, 1),(1, 1, 1, 1),(1, 1)}; kwargs::Base.Iterators.Pairs{Union{},Union{},Tuple{},NamedTuple{(),Tuple{}}}) at /home/dsweber/.julia/packages/NNlib/XKZ39/src/nnpack/interface.jl:50
 [8] maxpool_nnpack(::Array{Float64,4}, ::PoolDims{2,(2, 1),(1, 1),(1, 1, 1, 1),(1, 1)}) at /home/dsweber/.julia/packages/NNlib/XKZ39/src/nnpack/interface.jl:49
 [9] maxpool(::Array{Float64,4}, ::PoolDims{2,(2, 1),(1, 1),(1, 1, 1, 1),(1, 1)}; kwargs::Base.Iterators.Pairs{Union{},Union{},Tuple{},NamedTuple{(),Tuple{}}}) at /home/dsweber/.julia/packages/NNlib/XKZ39/src/pooling.jl:136
 [10] maxpool(::Array{Float64,4}, ::PoolDims{2,(2, 1),(1, 1),(1, 1, 1, 1),(1, 1)}) at /home/dsweber/.julia/packages/NNlib/XKZ39/src/pooling.jl:135
 [11] maxpool(::Array{Float64,4}, ::Tuple{Int64,Int64}; pad::Tuple{Int64,Int64}, stride::Tuple{Int64,Int64}) at /home/dsweber/.julia/packages/NNlib/XKZ39/src/pooling.jl:153
 [12] top-level scope at REPL[11]:1

dsweber2 avatar Jun 10 '20 22:06 dsweber2

update: having messed around with MaxPool from Flux for a bit, it appears that res = maxpool(randn(25,2,1,3), (2,1), pad=(1,0,0,0), stride=1) works even if res = maxpool(randn(25,2,1,3), (2,1), pad=1, stride=1) breaks.

dsweber2 avatar Jun 11 '20 19:06 dsweber2

Not clear why the error, but this will be worked around in #212

CarloLucibello avatar Jun 17 '20 08:06 CarloLucibello

Strangely, the 1D version actually works

NNlib only uses NNPACK for the 2D versions so it is not unexpected.

avik-pal avatar Jun 17 '20 09:06 avik-pal