-
-
Notifications
You must be signed in to change notification settings - Fork 609
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
Flux.softmax returns wrong result with CuArray #1425
Comments
Hmm, I would run it with a few older versions of Flux/ Zygote/ NNlib. Things that come to mind are the moving of rules from zygote to chain rules core, which we should catch before it's released. |
Could you test with CUDA@2.3? Or a newer Flux with CUDA@1.3 |
yes. I think it's a bug in CUDA, not Flux.
julia> using NNlib:softmax
julia> using CUDA
julia> softmax(randn(CURAND.default_rng(), 1,2,1,3), dims = 1)
1×2×1×3 CuArray{Float64,4}:
[:, :, 1, 1] =
1.0 1.0
[:, :, 1, 2] =
1.0 1.0
[:, :, 1, 3] =
1.0 1.0
julia> softmax(randn(CURAND.default_rng(), 1,2,1,3), dims = 1)
1×2×1×3 CuArray{Float64,4}:
[:, :, 1, 1] =
0.170576 0.829424
[:, :, 1, 2] =
0.58034 0.41966
[:, :, 1, 3] =
0.613132 0.386868 Let me file a new bug in CUDA. |
@DhairyaLGandhi , |
Yes that would be best |
let's keep this open, we should also add a test here to make sure there won't be future regression |
could you also check |
logsoftmax is wrong too. import NNlib
using CUDA, Debugger
xs = CUDA.rand(1,2,1,3)
NNlib.logsoftmax(copy(xs),dims=1)
NNlib.logsoftmax(copy(xs),dims=2)
NNlib.softmax(copy(xs),dims=1)
NNlib.softmax(copy(xs),dims=2)
# copied from https://github.com/FluxML/NNlib.jl/blob/master/src/softmax.jl
function softmax(xs::AbstractArray; dims=1)
max_ = maximum(xs, dims=dims)
exp_ = exp.(xs .- max_)
exp_ ./ sum(exp_, dims=dims)
end
softmax(copy(xs),dims=1)
softmax(copy(xs),dims=2)
Debugger.@enter NNlib.softmax(copy(xs),dims=1)
The softmax function from But
|
seems like the CUDA implementation is not picking the julia> using CUDA,NNlib
julia> x = rand(Float32, 2,2)
2×2 Array{Float32,2}:
0.431404 0.794794
0.118349 0.288102
julia> Array(softmax(cu(x), dims=1)) ≈ softmax(x, dims=1)
true
julia> Array(softmax(cu(x), dims=2)) ≈ softmax(x, dims=2)
false
julia> Array(softmax(cu(x), dims=2)) ≈ softmax(x, dims=1)
true
julia> Array(logsoftmax(cu(x), dims=1)) ≈ logsoftmax(x, dims=1)
true
julia> Array(logsoftmax(cu(x), dims=2)) ≈ logsoftmax(x, dims=2)
false
julia> Array(logsoftmax(cu(x), dims=2)) ≈ logsoftmax(x, dims=1)
true |
All of the examples above pass for me on the latest NNlib(CUDA):
Can we consider this fixed? |
Maybe there should be a few more tests in https://github.com/FluxML/NNlibCUDA.jl/blob/master/test/softmax.jl, or is this tested elsewhere? |
version:
on GPU, something is wrong with
dims
:expected behavior:
The text was updated successfully, but these errors were encountered: