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

Disable CUDNN_SOFTMAX_FAST or use a separate math mode variable for softmax #506

Open
chengchingwen opened this issue Feb 9, 2023 · 1 comment
Labels

Comments

@chengchingwen
Copy link
Member

Since #455 is merged, I want to point out that CUDNN_SOFTMAX_FAST would easily cause problem for attention operation. In the masking scenario, we would usually set the masked value to -Inf or some really small value, like -1e9. But if we want to use CUDA.math_mode!(CUDA.FAST_MATH) to accelerate the gemm, softmax would actually introduce many NaNs.

MWE:

julia> using CUDA, Flux
                                                                                                                       
julia> x = CUDA.randn(Float32, 512, 10); fill!(x, -1f3);

julia> CUDA.math_mode!(CUDA.FAST_MATH)

julia> softmax(x)
512×10 CuArray{Float32, 2, CUDA.Mem.DeviceBuffer}:                                                                     
 NaN  NaN  NaN  NaN  NaN  NaN  NaN  NaN  NaN  NaN
 NaN  NaN  NaN  NaN  NaN  NaN  NaN  NaN  NaN  NaN
 NaN  NaN  NaN  NaN  NaN  NaN  NaN  NaN  NaN  NaN
   ⋮                        ⋮
 NaN  NaN  NaN  NaN  NaN  NaN  NaN  NaN  NaN  NaN
 NaN  NaN  NaN  NaN  NaN  NaN  NaN  NaN  NaN  NaN
 NaN  NaN  NaN  NaN  NaN  NaN  NaN  NaN  NaN  NaN
 NaN  NaN  NaN  NaN  NaN  NaN  NaN  NaN  NaN  NaN
@ToucheSir
Copy link
Member

This relates to the discussion about customizing conv algorithms too, JuliaGPU/CUDA.jl#938. I guess the question remains how we can group and expose these toggles without overwhelming users and/or developers. Any ideas for a good API design would be appreciated.

@CarloLucibello CarloLucibello transferred this issue from FluxML/NNlibCUDA.jl Jun 24, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants