Skip to content

Conversation

@mcabbott
Copy link
Member

@mcabbott mcabbott commented Mar 5, 2022

This avoids using rational numbers in some activation function gradients, as that causes problems on GPU.

Closes #398, closes #400.

@terasakisatoshi
Copy link

terasakisatoshi commented Mar 6, 2022

Could you fix the definition of deriv_hardsish? It contains 1//2 which causes an error on my GPU machine.

https://github.com/mcabbott/NNlib.jl/blob/b8b328d9c0fd2ab215a2298b5cfd82191cd6e606/src/activations.jl#L406-L408

For example here is my suggestion.

deriv_hardswish(x) = ifelse(x < -3, oftf(x, 0), ifelse(x > 3, oftf(x, 1), x / 3 + oftf(x, 1 / 2)))

@mcabbott
Copy link
Member Author

mcabbott commented Mar 6, 2022

Maybe I got all of them this time...

end
@testset verbose=true "NNlib.jl" begin
if CUDA.functional()
if get(ENV, "NNLIB_TEST_CUDA", "false") == "true"
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

BTW all this mess is because I thought it was sometimes failing first on another test, and hence not showing the problem. So I added an overall testset. But it turns out this doesn't matter, because NNlibCUDA already has such a testset, and that's where both problems were.

Anyway, so it's unrelated, but perhaps a good idea. I also pulled the CUDA tests first. Since these aren't always run, it's nice to find out immediately whether they are going to be run at all.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

But easy to revert if someone thinks it ought not to be in this PR.

@mcabbott
Copy link
Member Author

mcabbott commented Mar 6, 2022

GPU test failures in softmax are probably to be looked at in FluxML/NNlibCUDA.jl#44. Which sadly is in a separate repository.

Nightly test failure is still #396

@mcabbott mcabbott requested a review from darsnack March 7, 2022 15:32
@mcabbott mcabbott changed the title Fix #398 Avoid Rational in activation function gradients Mar 7, 2022
@mcabbott mcabbott merged commit 886b34c into FluxML:master Mar 7, 2022
@mcabbott mcabbott deleted the activate8 branch March 7, 2022 16:18
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

Successfully merging this pull request may close these issues.

NNlib 0.8.3 broke NNlibCUDA Bug report: leakyrelu'.(CuArray(rand(Float32, 10))) fails [email protected] (@0.8.2 works)

3 participants